Conditions | 8 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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_ids, server_data, connection_details=None): |
||
22 | self.set_connection(connection_details) |
||
23 | self.get_sessionid() |
||
24 | |||
25 | # Prepare Endpoint within ICSP API |
||
26 | endpoint = "/rest/os-deployment-jobs" |
||
27 | |||
28 | # Prepare Pesonality Data data collection |
||
29 | pload = {} |
||
30 | pload['osbpUris'] = [] |
||
31 | pload['failMode'] = None |
||
32 | pload['serverData'] = [] |
||
33 | |||
34 | for plan in buildplan_ids: |
||
35 | # Confirm input are integers |
||
36 | try: |
||
37 | isinstance(plan, int) |
||
38 | except: |
||
39 | raise ValueError("Build plans must be \ |
||
40 | Integers (comma seperated)") |
||
41 | |||
42 | pload["osbpUris"].append("/rest/os-deployment-build-plans/%s" |
||
43 | % (plan)) |
||
44 | |||
45 | for server in server_data: |
||
46 | data = {} |
||
47 | pdata = {} |
||
48 | data['serverUri'] = "/rest/os-deployment-servers/%s" % (server) |
||
49 | |||
50 | # Prepare server personality Data |
||
51 | # Initially not including network data Although |
||
52 | # this can be included later |
||
53 | # TODO extend variable values to include IP configuration |
||
54 | |||
55 | if "hostname" in server_data[server]: |
||
56 | pdata['hostName'] = server_data[server]['hostname'] |
||
57 | if "domain" in server_data[server]: |
||
58 | pdata['domain'] = server_data[server]['domain'] |
||
59 | if "workgroup" in server_data[server]: |
||
60 | pdata['workgroup'] = server_data[server]['workgroup'] |
||
61 | data['personalityData'] = pdata |
||
62 | |||
63 | pload['serverData'].append(data) |
||
64 | |||
65 | payload = json.dumps(pload) |
||
66 | try: |
||
67 | results = self.icsp_post(endpoint, payload) |
||
68 | except Exception as e: |
||
69 | raise Exception("Error: %s" % e) |
||
70 | |||
71 | return {"jobid": self.extract_id(results['uri'])} |
||
72 |