Completed
Pull Request — master (#336)
by James
03:24
created

CreateVMAction.run()   F

Complexity

Conditions 18

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 37
rs 2.7088
cc 18

How to fix   Complexity   

Complexity

Complex classes like CreateVMAction.run() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
from lib.actions import BaseAction
2
3
__all__ = [
4
    'ImportPublicSSHKeyAction'
5
]
6
7
8
class ImportPublicSSHKeyAction(BaseAction):
9
    api_type = 'compute'
10
11
    def run(self, credentials, name, key_material):
12
        driver = self._get_driver_for_credentials(credentials=credentials)
13
        return driver.import_key_pair_from_string(name=name,
14
                                                  key_material=key_material)
15