|
3 | 3 | from .OperatingSystem import OperatingSystem |
4 | 4 |
|
5 | 5 |
|
6 | | -class Device(): |
7 | | - |
| 6 | +class Device: |
8 | 7 | def __init__(self, data, manager): |
9 | 8 | self.manager = manager |
10 | 9 |
|
11 | | - self.billing_cycle = data['billing_cycle'] |
12 | | - self.created_at = data['created_at'] |
13 | | - self.facility = data['facility'] |
14 | | - self.hostname = data['hostname'] |
15 | | - self.href = data['href'] |
16 | | - self.id = data['id'] |
17 | | - self.ip_addresses = data['ip_addresses'] |
18 | | - self.locked = data['locked'] |
19 | | - self.operating_system = OperatingSystem(data['operating_system']) |
20 | | - self.plan = data['plan'] |
21 | | - self.spot_instance = data.get('spot_instance') |
22 | | - self.spot_price_max = data.get('spot_price_max') |
23 | | - self.ssh_keys = data.get('ssh_keys', []) |
24 | | - self.state = data['state'] |
25 | | - self.tags = data['tags'] |
26 | | - self.termination_time = data.get('termination_time') |
27 | | - self.updated_at = data['updated_at'] |
28 | | - self.user = data['user'] |
| 10 | + self.billing_cycle = data["billing_cycle"] |
| 11 | + self.created_at = data["created_at"] |
| 12 | + self.facility = data["facility"] |
| 13 | + self.hostname = data["hostname"] |
| 14 | + self.href = data["href"] |
| 15 | + self.id = data["id"] |
| 16 | + self.ip_addresses = data["ip_addresses"] |
| 17 | + self.locked = data["locked"] |
| 18 | + self.operating_system = OperatingSystem(data["operating_system"]) |
| 19 | + self.plan = data["plan"] |
| 20 | + self.spot_instance = data.get("spot_instance") |
| 21 | + self.spot_price_max = data.get("spot_price_max") |
| 22 | + self.ssh_keys = data.get("ssh_keys", []) |
| 23 | + self.state = data["state"] |
| 24 | + self.tags = data["tags"] |
| 25 | + self.termination_time = data.get("termination_time") |
| 26 | + self.updated_at = data["updated_at"] |
| 27 | + self.user = data["user"] |
29 | 28 |
|
30 | 29 | def update(self): |
31 | | - params = { |
32 | | - "hostname": self.hostname, |
33 | | - "locked": self.locked, |
34 | | - "tags": self.tags, |
35 | | - } |
| 30 | + params = {"hostname": self.hostname, "locked": self.locked, "tags": self.tags} |
36 | 31 |
|
37 | | - return self.manager.call_api("devices/%s" % self.id, type='PATCH', params=params) |
| 32 | + return self.manager.call_api( |
| 33 | + "devices/%s" % self.id, type="PATCH", params=params |
| 34 | + ) |
38 | 35 |
|
39 | 36 | def delete(self): |
40 | | - return self.manager.call_api("devices/%s" % self.id, type='DELETE') |
| 37 | + return self.manager.call_api("devices/%s" % self.id, type="DELETE") |
41 | 38 |
|
42 | 39 | def power_off(self): |
43 | | - params = {'type': 'power_off'} |
44 | | - return self.manager.call_api("devices/%s/actions" % self.id, type='POST', params=params) |
| 40 | + params = {"type": "power_off"} |
| 41 | + return self.manager.call_api( |
| 42 | + "devices/%s/actions" % self.id, type="POST", params=params |
| 43 | + ) |
45 | 44 |
|
46 | 45 | def power_on(self): |
47 | | - params = {'type': 'power_on'} |
48 | | - return self.manager.call_api("devices/%s/actions" % self.id, type='POST', params=params) |
| 46 | + params = {"type": "power_on"} |
| 47 | + return self.manager.call_api( |
| 48 | + "devices/%s/actions" % self.id, type="POST", params=params |
| 49 | + ) |
49 | 50 |
|
50 | 51 | def reboot(self): |
51 | | - params = {'type': 'reboot'} |
52 | | - return self.manager.call_api("devices/%s/actions" % self.id, type='POST', params=params) |
| 52 | + params = {"type": "reboot"} |
| 53 | + return self.manager.call_api( |
| 54 | + "devices/%s/actions" % self.id, type="POST", params=params |
| 55 | + ) |
53 | 56 |
|
54 | 57 | def __str__(self): |
55 | 58 | return "%s" % self.hostname |
56 | 59 |
|
57 | 60 | def __repr__(self): |
58 | | - return '{}: {}'.format(self.__class__.__name__, self.id) |
| 61 | + return "{}: {}".format(self.__class__.__name__, self.id) |
0 commit comments