Completed
Pull Request — master (#564)
by
unknown
02:28
created

DeviceNameList.run()   B

Complexity

Conditions 5

Size

Total Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
dl 0
loc 61
rs 8.3372
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
from st2actions.runners.pythonrunner import Action
2
import requests
3
4
5
class DeviceNameList(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
        response = requests.get("http://%s%s" % (d42_server, "/api/1.0/devices/"), params={
28
            "type": type,
29
            "service_level": service_level,
30
            "in_service": in_service,
31
            "customer": customer,
32
            "tags": tags,
33
            "blade_host_name": blade_host_name,
34
            "virtual_host_name": virtual_host_name,
35
            "building_id": building_id,
36
            "building": building,
37
            "room_id": room_id,
38
            "room": room,
39
            "rack_id": rack_id,
40
            "rack": rack,
41
            "serial_no": serial_no,
42
            "serial_no_contains": serial_no_contains,
43
            "asset_no": asset_no,
44
            "name": name,
45
            "tags_and": tags_and,
46
            "uuid": uuid,
47
            "is_it_switch": is_it_switch,
48
            "is_it_virtual_host": is_it_virtual_host,
49
            "is_it_blade_host": is_it_blade_host,
50
            "hardware": hardware,
51
            "hardware_ids": hardware_ids,
52
            "os": os,
53
            "virtual_subtype": virtual_subtype,
54
            "last_updated_lt": last_updated_lt,
55
            "last_updated_gt": last_updated_gt,
56
            "first_added_lt": first_added_lt,
57
            "first_added_gt": first_added_gt,
58
            "custom_fields_and": custom_fields_and,
59
            "custom_fields_or": custom_fields_or,
60
        }, auth=(d42_username, d42_password))
61
62
        names = []
63
        for device in response.json()["Devices"]:
64
            names.append(device["name"])
65
66
        return names
67