Conditions | 7 |
Total Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 | from st2actions.runners.pythonrunner import Action |
||
6 | def run(self, type=None, service_level=None, in_service=None, customer=None, tags=None, |
||
7 | blade_host_name=None, virtual_host_name=None, building_id=None, building=None, |
||
8 | room_id=None, room=None, rack_id=None, rack=None, serial_no=None, |
||
9 | serial_no_contains=None, asset_no=None, name=None, tags_and=None, uuid=None, |
||
10 | is_it_switch=None, is_it_virtual_host=None, is_it_blade_host=None, hardware=None, |
||
11 | hardware_ids=None, os=None, virtual_subtype=None, last_updated_lt=None, |
||
12 | last_updated_gt=None, first_added_lt=None, first_added_gt=None, |
||
13 | custom_fields_and=None, custom_fields_or=None): |
||
14 | |||
15 | d42_server = self.config.get('d42_server', None) |
||
16 | if not d42_server: |
||
17 | raise ValueError('"d42_server" config value is required') |
||
18 | |||
19 | d42_username = self.config.get('d42_username', None) |
||
20 | if not d42_username: |
||
21 | raise ValueError('"d42_username" config value is required') |
||
22 | |||
23 | d42_password = self.config.get('d42_password', None) |
||
24 | if not d42_password: |
||
25 | raise ValueError('"d42_password" config value is required') |
||
26 | |||
27 | protocol = self.config.get('protocol', 'http') |
||
28 | |||
29 | verify = False |
||
30 | if self.confing.get('verify_certificate', None) == 'true' and protocol == 'https': |
||
31 | verify = True |
||
32 | |||
33 | response = requests.get("%s://%s%s" % (protocol, d42_server, "/api/1.0/devices/"), params={ |
||
34 | "type": type, |
||
35 | "service_level": service_level, |
||
36 | "in_service": in_service, |
||
37 | "customer": customer, |
||
38 | "tags": tags, |
||
39 | "blade_host_name": blade_host_name, |
||
40 | "virtual_host_name": virtual_host_name, |
||
41 | "building_id": building_id, |
||
42 | "building": building, |
||
43 | "room_id": room_id, |
||
44 | "room": room, |
||
45 | "rack_id": rack_id, |
||
46 | "rack": rack, |
||
47 | "serial_no": serial_no, |
||
48 | "serial_no_contains": serial_no_contains, |
||
49 | "asset_no": asset_no, |
||
50 | "name": name, |
||
51 | "tags_and": tags_and, |
||
52 | "uuid": uuid, |
||
53 | "is_it_switch": is_it_switch, |
||
54 | "is_it_virtual_host": is_it_virtual_host, |
||
55 | "is_it_blade_host": is_it_blade_host, |
||
56 | "hardware": hardware, |
||
57 | "hardware_ids": hardware_ids, |
||
58 | "os": os, |
||
59 | "virtual_subtype": virtual_subtype, |
||
60 | "last_updated_lt": last_updated_lt, |
||
61 | "last_updated_gt": last_updated_gt, |
||
62 | "first_added_lt": first_added_lt, |
||
63 | "first_added_gt": first_added_gt, |
||
64 | "custom_fields_and": custom_fields_and, |
||
65 | "custom_fields_or": custom_fields_or, |
||
66 | }, auth=(d42_username, d42_password), verify=verify) |
||
67 | |||
68 | names = [] |
||
69 | for device in response.json()["Devices"]: |
||
70 | names.append(device["name"]) |
||
71 | |||
72 | return names |
||
73 |