Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit e8d9ae2

Browse files
committed
yapf
1 parent eb7df49 commit e8d9ae2

11 files changed

Lines changed: 53 additions & 45 deletions

File tree

.style.yapf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[style]
2+
based_on_style = chromium
3+
column_limit = 120
4+
indent_width = 4

packet/Facility.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
class Facility():
5+
56
def __init__(self, data):
67
self.id = data['id']
78
self.code = data['code']

packet/Manager.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
class Manager(BaseAPI):
14+
1415
def __init__(self, auth_token, consumer_token=None):
1516
super(Manager, self).__init__(auth_token, consumer_token)
1617

@@ -70,10 +71,20 @@ def list_devices(self, project_id, params={}):
7071
devices.append(device)
7172
return devices
7273

73-
def create_device(self, project_id, hostname, plan, facility,
74-
operating_system, billing_cycle='hourly', userdata='',
75-
locked=False, tags={}, features={}, ipxe_script_url='',
76-
always_pxe=False, public_ipv4_subnet_size=31):
74+
def create_device(self,
75+
project_id,
76+
hostname,
77+
plan,
78+
facility,
79+
operating_system,
80+
billing_cycle='hourly',
81+
userdata='',
82+
locked=False,
83+
tags={},
84+
features={},
85+
ipxe_script_url='',
86+
always_pxe=False,
87+
public_ipv4_subnet_size=31):
7788

7889
params = {
7990
'hostname': hostname,
@@ -152,13 +163,7 @@ def get_capacity(self):
152163
def validate_capacity(self, servers):
153164
params = {'servers': []}
154165
for server in servers:
155-
params['servers'].append(
156-
{
157-
'facility': server[0],
158-
'plan': server[1],
159-
'quantity': server[2]
160-
}
161-
)
166+
params['servers'].append({'facility': server[0], 'plan': server[1], 'quantity': server[2]})
162167

163168
try:
164169
self.call_api('/capacity', 'POST', params)

packet/OperatingSystem.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
class OperatingSystem(object):
5+
56
def __init__(self, data):
67
self.slug = data['slug']
78
self.name = data['name']

packet/Plan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
class Plan():
5+
56
def __init__(self, data):
67
self.id = data['id']
78
self.name = data['name']

packet/Project.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def __init__(self, data, manager):
1919
self.ssh_keys = data['ssh_keys']
2020

2121
def update(self):
22-
params = {
23-
"name": self.name
24-
}
22+
params = {"name": self.name}
2523

2624
return self.manager.call_api("projects/%s" % self.id, type='PATCH', params=params)
2725

packet/Volume.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ def __init__(self, data, manager):
2828
self.attached_to = None
2929

3030
def update(self):
31-
params = {
32-
"description": self.description,
33-
"size": self.size,
34-
"plan": self.plan,
35-
"locked": self.locked
36-
}
31+
params = {"description": self.description, "size": self.size, "plan": self.plan, "locked": self.locked}
3732

3833
return self.manager.call_api("storage/%s" % self.id, type='PATCH', params=params)
3934

packet/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
__license__ = "LGPL v3"
88
__copyright__ = "Copyright (c) 2015, Aaron Welch and Packet"
99

10-
1110
from .Device import Device # noqa
1211
from .Facility import Facility # noqa
1312
from .OperatingSystem import OperatingSystem # noqa

packet/baseapi.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class Error(Exception): # pragma: no cover
88
"""Base exception class for this module"""
9+
910
def __init__(self, msg, cause=None):
1011
super(Error, self).__init__(msg)
1112
self._cause = cause
@@ -37,41 +38,37 @@ def call_api(self, method, type='GET', params=None): # pragma: no cover
3738

3839
url = 'https://' + self.end_point + '/' + method
3940

40-
headers = {'X-Auth-Token': self.auth_token,
41-
'X-Consumer-Token': self.consumer_token,
42-
'Content-Type': 'application/json'}
41+
headers = {
42+
'X-Auth-Token': self.auth_token,
43+
'X-Consumer-Token': self.consumer_token,
44+
'Content-Type': 'application/json'
45+
}
4346

4447
# remove token from log
4548
headers_str = str(headers).replace(self.auth_token.strip(), 'TOKEN')
46-
self._log.debug('%s %s %s %s' %
47-
(type, url, params, headers_str))
49+
self._log.debug('%s %s %s %s' % (type, url, params, headers_str))
4850
try:
4951
if type == 'GET':
5052
url = url + '%s' % self._parse_params(params)
5153
resp = requests.get(url, headers=headers)
5254
elif type == 'POST':
53-
resp = requests.post(url, headers=headers,
54-
data=json.dumps(params))
55+
resp = requests.post(url, headers=headers, data=json.dumps(params))
5556
elif type == 'DELETE':
5657
resp = requests.delete(url, headers=headers)
5758
elif type == 'PATCH':
58-
resp = requests.patch(url, headers=headers,
59-
data=json.dumps(params))
59+
resp = requests.patch(url, headers=headers, data=json.dumps(params))
6060
else:
61-
raise Error(
62-
'method type not recognized as one of GET, POST, DELETE or PATCH: %s' % type
63-
)
61+
raise Error('method type not recognized as one of GET, POST, DELETE or PATCH: %s' % type)
6462
except requests.exceptions.RequestException as e:
6563
raise Error('Communcations error: %s' % str(e), e)
64+
6665
if not resp.content:
6766
data = None
6867
elif resp.headers.get("content-type", "").startswith("application/json"):
6968
try:
7069
data = resp.json()
7170
except ValueError as e:
72-
raise JSONReadError(
73-
'Read failed: %s' % e.message, e
74-
)
71+
raise JSONReadError('Read failed: %s' % e.message, e)
7572
else:
7673
data = resp.content
7774

@@ -81,20 +78,20 @@ def call_api(self, method, type='GET', params=None): # pragma: no cover
8178
msg = "(empty response)"
8279
elif 'errors' in data:
8380
msg = ', '.join(data['errors'])
84-
raise Error(
85-
'Error {0}: {1}'.format(resp.status_code, msg)
86-
)
81+
raise Error('Error {0}: {1}'.format(resp.status_code, msg))
82+
8783
try:
8884
resp.raise_for_status()
8985
except requests.HTTPError as e:
90-
raise Error('Error {0}: {1}'.format(resp.status_code,
91-
resp.reason), e)
86+
raise Error('Error {0}: {1}'.format(resp.status_code, resp.reason), e)
87+
9288
self.meta = None
9389
try:
9490
if data and data['meta']:
9591
self.meta = data['meta']
9692
except (KeyError, IndexError):
9793
pass
94+
9895
return data
9996

10097
def _parse_params(self, params): # pragma: no cover

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@
2424
install_requires=['requests'],
2525
license='LGPL v3',
2626
keywords='packet api client',
27-
long_description=long_description
28-
)
27+
long_description=long_description)

0 commit comments

Comments
 (0)