Conditions | 9 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # Licensed to the StackStorm, Inc ('StackStorm') under one or more |
||
21 | def run(self, buildplan_uris, server_data, connection_details): |
||
22 | if connection_details: |
||
23 | self.setConnection(connection_details) |
||
24 | self.getSessionID() |
||
25 | |||
26 | # Prepare Endpoint within ICSP API |
||
27 | endpoint = "/rest/os-deployment-jobs" |
||
28 | |||
29 | # Prepare Pesonality Data data collection |
||
30 | pload = {} |
||
31 | pload['osbpUris'] = [] |
||
32 | pload['failMode'] = None |
||
33 | pload['serverData'] = [] |
||
34 | |||
35 | for plan in buildplan_uris: |
||
36 | # Confirm input are integers |
||
37 | try: |
||
38 | isinstance(plan, int) |
||
39 | except: |
||
40 | raise ValueError("Build plans must be \ |
||
41 | Integers (comma seperated)") |
||
42 | |||
43 | pload["osbpUris"].append("/rest/os-deployment-build-plans/%s" |
||
44 | % plan) |
||
45 | |||
46 | for server in server_data: |
||
47 | data = {} |
||
48 | pdata = {} |
||
49 | data['serverUri'] = "/rest/os-deployment-servers/%s" % server |
||
50 | |||
51 | # Prepare server personality Data |
||
52 | # Initially not including network data Although |
||
53 | # this can be included later |
||
54 | # TODO extend variable values to include IP configuration |
||
55 | |||
56 | if "hostname" in server_data[server]: |
||
57 | pdata['hostName'] = server_data[server]['hostname'] |
||
58 | if "domain" in server_data[server]: |
||
59 | pdata['domain'] = server_data[server]['domain'] |
||
60 | if "workgroup" in server_data[server]: |
||
61 | pdata['workgroup'] = server_data[server]['workgroup'] |
||
62 | data['personalityData'] = pdata |
||
63 | |||
64 | pload['serverData'].append(data) |
||
65 | |||
66 | payload = json.dumps(pload) |
||
67 | try: |
||
68 | results = self.icspPOST(endpoint, payload) |
||
69 | except Exception as e: |
||
70 | raise Exception("Error: %s" % e) |
||
71 | |||
72 | return {"jobid": int(results['uri'].rsplit("/")[-1])} |
||
73 |