Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed a few PEP8 compliance issues, and removed unused variables.

git-svn-id: https://svn.apache.org/repos/asf/libcloud/trunk@1212975 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 3cda3bed2f3be776575e506dc735357204618a47 1 parent cca04c7
Hutson Betts authored

Showing 40 changed files with 286 additions and 278 deletions. Show diff stats Hide diff stats

  1. +5 3 demos/compute_demo.py
  2. +3 3 example_compute.py
  3. +1 0  example_loadbalancer.py
  4. +2 1  libcloud/common/aws.py
  5. +15 11 libcloud/common/base.py
  6. +5 1 libcloud/common/cloudstack.py
  7. +0 4 libcloud/common/gandi.py
  8. +6 7 libcloud/common/gogrid.py
  9. +10 10 libcloud/common/linode.py
  10. +3 3 libcloud/compute/base.py
  11. +1 1  libcloud/compute/deployment.py
  12. +9 10 libcloud/compute/drivers/bluebox.py
  13. +29 29 libcloud/compute/drivers/brightbox.py
  14. +47 38 libcloud/compute/drivers/cloudsigma.py
  15. +2 4 libcloud/compute/drivers/cloudstack.py
  16. +3 3 libcloud/compute/drivers/dreamhost.py
  17. +31 31 libcloud/compute/drivers/dummy.py
  18. +5 8 libcloud/compute/drivers/ecp.py
  19. +1 2  libcloud/compute/drivers/gandi.py
  20. +10 11 libcloud/compute/drivers/gogrid.py
  21. +19 17 libcloud/compute/drivers/ibm_sbc.py
  22. +17 9 libcloud/compute/drivers/linode.py
  23. +6 6 libcloud/compute/drivers/rimuhosting.py
  24. +2 2 libcloud/compute/drivers/slicehost.py
  25. +29 29 libcloud/compute/drivers/softlayer.py
  26. +0 1  libcloud/compute/drivers/voxel.py
  27. +1 1  libcloud/compute/ssh.py
  28. +2 1  libcloud/compute/types.py
  29. +3 4 libcloud/dns/drivers/linode.py
  30. +6 5 libcloud/httplib_ssl.py
  31. +0 1  libcloud/loadbalancer/__init__.py
  32. +2 3 libcloud/loadbalancer/drivers/cloudstack.py
  33. +3 1 libcloud/pricing.py
  34. +1 1  libcloud/storage/base.py
  35. +1 2  libcloud/storage/drivers/atmos.py
  36. +2 3 libcloud/storage/drivers/google_storage.py
  37. +0 3  libcloud/utils/__init__.py
  38. +3 7 setup.py
  39. +1 1  test/loadbalancer/test_gogrid.py
  40. +0 1  test/test_pricing.py
8 demos/compute_demo.py
@@ -31,7 +31,8 @@
31 31 import sys
32 32
33 33 # Add parent dir of this file's dir to sys.path (OS-agnostically)
34   -sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
  34 +sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__),
  35 + os.path.pardir)))
35 36
36 37 from libcloud.common.types import InvalidCredsError
37 38 from libcloud.compute.types import Provider
@@ -39,6 +40,7 @@
39 40
40 41 from pprint import pprint
41 42
  43 +
42 44 def get_demo_driver(provider_name='RACKSPACE', *args, **kwargs):
43 45 """An easy way to play with a driver interactively.
44 46
@@ -77,8 +79,8 @@ def get_demo_driver(provider_name='RACKSPACE', *args, **kwargs):
77 79 return DriverClass(*args, **kwargs)
78 80 except InvalidCredsError:
79 81 raise InvalidCredsError(
80   - 'valid values should be put in secrets.py'
81   - )
  82 + 'valid values should be put in secrets.py')
  83 +
82 84
83 85 def main(argv):
84 86 """Main Compute Demo
6 example_compute.py
@@ -20,11 +20,11 @@
20 20 Slicehost = get_driver(Provider.SLICEHOST)
21 21 Rackspace = get_driver(Provider.RACKSPACE)
22 22
23   -drivers = [ EC2('access key id', 'secret key'),
  23 +drivers = [EC2('access key id', 'secret key'),
24 24 Slicehost('api key'),
25   - Rackspace('username', 'api key') ]
  25 + Rackspace('username', 'api key')]
26 26
27   -nodes = [ driver.list_nodes() for driver in drivers ]
  27 +nodes = [driver.list_nodes() for driver in drivers]
28 28
29 29 print(nodes)
30 30 # [ <Node: provider=Amazon, status=RUNNING, name=bob, ip=1.2.3.4.5>,
1  example_loadbalancer.py
@@ -22,6 +22,7 @@
22 22 from libcloud.loadbalancer.types import Provider, State
23 23 from libcloud.loadbalancer.providers import get_driver
24 24
  25 +
25 26 def main():
26 27 Rackspace = get_driver(Provider.RACKSPACE_US)
27 28
3  libcloud/common/aws.py
@@ -15,4 +15,5 @@
15 15
16 16 from libcloud.common.base import XmlResponse
17 17
18   -class AWSBaseResponse(XmlResponse): pass
  18 +class AWSBaseResponse(XmlResponse):
  19 + pass
26 libcloud/common/base.py
@@ -136,9 +136,9 @@ def parse_body(self):
136 136 return self.body
137 137
138 138 try:
139   - body = ET.XML(self.body)
  139 + body = ET.XML(self.body)
140 140 except:
141   - raise MalformedResponseError("Failed to parse XML",
  141 + raise MalformedResponseError("Failed to parse XML",
142 142 body=self.body,
143 143 driver=self.connection.driver)
144 144 return body
@@ -156,7 +156,6 @@ def __init__(self, connection):
156 156 self._reason = None
157 157 self.connection = connection
158 158
159   -
160 159 @property
161 160 def response(self):
162 161 if not self._response:
@@ -208,10 +207,12 @@ def _log_response(self, r):
208 207 for h in r.getheaders():
209 208 ht += "%s: %s\r\n" % (h[0].title(), h[1])
210 209 ht += "\r\n"
  210 +
211 211 # this is evil. laugh with me. ha arharhrhahahaha
212 212 class fakesock:
213 213 def __init__(self, s):
214 214 self.s = s
  215 +
215 216 def makefile(self, mode, foo):
216 217 return StringIO(self.s)
217 218 rr = r
@@ -261,11 +262,12 @@ def getresponse(self):
261 262 def request(self, method, url, body=None, headers=None):
262 263 headers.update({'X-LC-Request-ID': str(id(self))})
263 264 if self.log is not None:
264   - pre = "# -------- begin %d request ----------\n" % id(self)
  265 + pre = "# -------- begin %d request ----------\n" % id(self)
265 266 self.log.write(pre +
266 267 self._log_curl(method, url, body, headers) + "\n")
267 268 self.log.flush()
268   - return LibcloudHTTPSConnection.request(self, method, url, body, headers)
  269 + return LibcloudHTTPSConnection.request(self, method, url, body,
  270 + headers)
269 271
270 272 class LoggingHTTPConnection(LoggingConnection, LibcloudHTTPConnection):
271 273 """
@@ -283,7 +285,7 @@ def getresponse(self):
283 285 def request(self, method, url, body=None, headers=None):
284 286 headers.update({'X-LC-Request-ID': str(id(self))})
285 287 if self.log is not None:
286   - pre = "# -------- begin %d request ----------\n" % id(self)
  288 + pre = "# -------- begin %d request ----------\n" % id(self)
287 289 self.log.write(pre +
288 290 self._log_curl(method, url, body, headers) + "\n")
289 291 self.log.flush()
@@ -326,7 +328,8 @@ def __init__(self, secure=True, host=None, port=None, url=None):
326 328 self.port = 80
327 329
328 330 if url:
329   - (self.host, self.port, self.secure, self.request_path) = self._tuple_from_url(url)
  331 + (self.host, self.port, self.secure,
  332 + self.request_path) = self._tuple_from_url(url)
330 333
331 334 def set_context(self, context):
332 335 self.context = context
@@ -334,7 +337,8 @@ def set_context(self, context):
334 337 def _tuple_from_url(self, url):
335 338 secure = 1
336 339 port = None
337   - scheme, netloc, request_path, param, query, fragment = urlparse.urlparse(url)
  340 + (scheme, netloc, request_path, param,
  341 + query, fragment) = urlparse.urlparse(url)
338 342
339 343 if scheme not in ['http', 'https']:
340 344 raise LibcloudError('Invalid scheme: %s in url %s' % (scheme, url))
@@ -356,7 +360,7 @@ def _tuple_from_url(self, url):
356 360
357 361 return (host, port, secure, request_path)
358 362
359   - def connect(self, host=None, port=None, base_url = None):
  363 + def connect(self, host=None, port=None, base_url=None):
360 364 """
361 365 Establish a connection with the API server.
362 366
@@ -511,7 +515,7 @@ def request(self,
511 515 return response
512 516
513 517 def morph_action_hook(self, action):
514   - return self.request_path + action
  518 + return self.request_path + action
515 519
516 520 def add_default_params(self, params):
517 521 """
@@ -570,7 +574,7 @@ def async_request(self, action, params=None, data='', headers=None,
570 574 """
571 575 Perform an 'async' request to the specified path. Keep in mind that
572 576 this function is *blocking* and 'async' in this case means that the
573   - hit URL only returns a job ID which is the periodically polled until
  577 + hit URL only returns a job ID which is the periodically polled until
574 578 the job has completed.
575 579
576 580 This function works like this:
6 libcloud/common/cloudstack.py
@@ -24,7 +24,10 @@
24 24 from libcloud.common.base import JsonResponse
25 25 from libcloud.common.types import MalformedResponseError
26 26
27   -class CloudStackResponse(JsonResponse): pass
  27 +
  28 +class CloudStackResponse(JsonResponse):
  29 + pass
  30 +
28 31
29 32 class CloudStackConnection(ConnectionUserAndKey, PollingConnection):
30 33 responseCls = CloudStackResponse
@@ -98,6 +101,7 @@ def _sync_request(self, command, **kwargs):
98 101 result = result.object[command]
99 102 return result
100 103
  104 +
101 105 class CloudStackDriverMixIn(object):
102 106 host = None
103 107 path = None
4 libcloud/common/gandi.py
@@ -22,11 +22,7 @@
22 22 from libcloud.utils.py3 import xmlrpclib
23 23 from libcloud.utils.py3 import b
24 24
25   -import libcloud
26 25 from libcloud.common.base import ConnectionKey
27   -from libcloud.compute.types import Provider, NodeState
28   -from libcloud.compute.base import NodeDriver, Node, \
29   - NodeLocation, NodeSize, NodeImage
30 26
31 27 # Global constants
32 28 API_VERSION = '2.0'
13 libcloud/common/gogrid.py
@@ -24,7 +24,7 @@
24 24 from libcloud.compute.base import NodeLocation
25 25
26 26 HOST = 'api.gogrid.com'
27   -PORTS_BY_SECURITY = { True: 443, False: 80 }
  27 +PORTS_BY_SECURITY = {True: 443, False: 80}
28 28 API_VERSION = '1.8'
29 29
30 30 __all__ = ["GoGridResponse",
@@ -36,8 +36,8 @@
36 36 class GoGridResponse(JsonResponse):
37 37
38 38 def __init__(self, *args, **kwargs):
39   - self.driver = BaseGoGridDriver
40   - super(GoGridResponse, self).__init__(*args, **kwargs)
  39 + self.driver = BaseGoGridDriver
  40 + super(GoGridResponse, self).__init__(*args, **kwargs)
41 41
42 42 def success(self):
43 43 if self.status == 403:
@@ -76,7 +76,7 @@ def add_default_params(self, params):
76 76
77 77 def get_signature(self, key, secret):
78 78 """ create sig from md5 of key + secret + time """
79   - m = hashlib.md5(b(key+secret+str(int(time.time()))))
  79 + m = hashlib.md5(b(key + secret + str(int(time.time()))))
80 80 return m.hexdigest()
81 81
82 82 class GoGridIpAddress(object):
@@ -111,8 +111,8 @@ def _to_ip(self, element):
111 111 return ip
112 112
113 113 def _to_ips(self, object):
114   - return [ self._to_ip(el)
115   - for el in object['list'] ]
  114 + return [self._to_ip(el)
  115 + for el in object['list']]
116 116
117 117 def _to_location(self, element):
118 118 location = NodeLocation(id=element['id'],
@@ -125,7 +125,6 @@ def _to_locations(self, object):
125 125 return [self._to_location(el)
126 126 for el in object['list']]
127 127
128   -
129 128 def ex_list_ips(self, **kwargs):
130 129 """Return list of IP addresses assigned to
131 130 the account.
20 libcloud/common/linode.py
@@ -29,16 +29,16 @@
29 29 API_ROOT = '/'
30 30
31 31 # Constants that map a RAM figure to a PlanID (updated 6/28/10)
32   -LINODE_PLAN_IDS = {512:'1',
33   - 768:'2',
34   - 1024:'3',
35   - 1536:'4',
36   - 2048:'5',
37   - 4096:'6',
38   - 8192:'7',
39   - 12288:'8',
40   - 16384:'9',
41   - 20480:'10'}
  32 +LINODE_PLAN_IDS = {512: '1',
  33 + 768: '2',
  34 + 1024: '3',
  35 + 1536: '4',
  36 + 2048: '5',
  37 + 4096: '6',
  38 + 8192: '7',
  39 + 12288: '8',
  40 + 16384: '9',
  41 + 20480: '10'}
42 42
43 43
44 44 class LinodeException(Exception):
6 libcloud/compute/base.py
@@ -375,9 +375,9 @@ class NodeDriver(BaseDriver):
375 375
376 376 def __init__(self, key, secret=None, secure=True, host=None, port=None,
377 377 api_version=None):
378   - super(NodeDriver, self).__init__(key=key, secret=secret, secure=secure,
379   - host=host, port=port,
380   - api_version=api_version)
  378 + super(NodeDriver, self).__init__(key=key, secret=secret, secure=secure,
  379 + host=host, port=port,
  380 + api_version=api_version)
381 381
382 382 def create_node(self, **kwargs):
383 383 """Create a new node instance.
2  libcloud/compute/deployment.py
@@ -120,7 +120,7 @@ class MultiStepDeployment(Deployment):
120 120 """
121 121 Runs a chain of Deployment steps.
122 122 """
123   - def __init__(self, add = None):
  123 + def __init__(self, add=None):
124 124 """
125 125 @type add: C{list}
126 126 @keyword add: Deployment steps to add.
19 libcloud/compute/drivers/bluebox.py
@@ -32,7 +32,6 @@
32 32 from libcloud.common.base import JsonResponse, ConnectionUserAndKey
33 33 from libcloud.compute.providers import Provider
34 34 from libcloud.compute.types import NodeState, InvalidCredsError
35   -from libcloud.common.types import MalformedResponseError
36 35 from libcloud.compute.base import Node, NodeDriver
37 36 from libcloud.compute.base import NodeSize, NodeImage, NodeLocation
38 37 from libcloud.compute.base import NodeAuthPassword, NodeAuthSSHKey
@@ -76,11 +75,11 @@
76 75
77 76 RAM_PER_CPU = 2048
78 77
79   -NODE_STATE_MAP = { 'queued': NodeState.PENDING,
80   - 'building': NodeState.PENDING,
81   - 'running': NodeState.RUNNING,
82   - 'error': NodeState.TERMINATED,
83   - 'unknown': NodeState.UNKNOWN }
  78 +NODE_STATE_MAP = {'queued': NodeState.PENDING,
  79 + 'building': NodeState.PENDING,
  80 + 'running': NodeState.RUNNING,
  81 + 'error': NodeState.TERMINATED,
  82 + 'unknown': NodeState.UNKNOWN}
84 83
85 84 class BlueboxResponse(JsonResponse):
86 85 def parse_error(self):
@@ -137,7 +136,7 @@ def list_sizes(self, location=None):
137 136 sizes = []
138 137 for key, values in list(BLUEBOX_INSTANCE_TYPES.items()):
139 138 attributes = copy.deepcopy(values)
140   - attributes.update({ 'price': self._get_size_price(size_id=key) })
  139 + attributes.update({'price': self._get_size_price(size_id=key)})
141 140 sizes.append(BlueboxNodeSize(driver=self.connection.driver,
142 141 **attributes))
143 142
@@ -147,12 +146,12 @@ def list_images(self, location=None):
147 146 result = self.connection.request('/api/block_templates.json')
148 147 images = []
149 148 for image in result.object:
150   - images.extend([self._to_image(image)])
  149 + images.extend([self._to_image(image)])
151 150
152 151 return images
153 152
154 153 def create_node(self, **kwargs):
155   - headers = { 'Content-Type': 'application/x-www-form-urlencoded' }
  154 + headers = {'Content-Type': 'application/x-www-form-urlencoded'}
156 155 size = kwargs["size"]
157 156
158 157 name = kwargs['name']
@@ -213,7 +212,7 @@ def _to_node(self, vm):
213 212 n = Node(id=vm['id'],
214 213 name=vm['hostname'],
215 214 state=state,
216   - public_ips=[ ip['address'] for ip in vm['ips'] ],
  215 + public_ips=[ip['address'] for ip in vm['ips']],
217 216 private_ips=[],
218 217 extra={'storage':vm['storage'], 'cpu':vm['cpu']},
219 218 driver=self.connection.driver)
58 libcloud/compute/drivers/brightbox.py
@@ -104,25 +104,25 @@ class BrightboxNodeDriver(NodeDriver):
104 104 type = Provider.BRIGHTBOX
105 105 name = 'Brightbox'
106 106
107   - NODE_STATE_MAP = { 'creating': NodeState.PENDING,
108   - 'active': NodeState.RUNNING,
109   - 'inactive': NodeState.UNKNOWN,
110   - 'deleting': NodeState.UNKNOWN,
111   - 'deleted': NodeState.TERMINATED,
112   - 'failed': NodeState.UNKNOWN,
113   - 'unavailable': NodeState.UNKNOWN }
  107 + NODE_STATE_MAP = {'creating': NodeState.PENDING,
  108 + 'active': NodeState.RUNNING,
  109 + 'inactive': NodeState.UNKNOWN,
  110 + 'deleting': NodeState.UNKNOWN,
  111 + 'deleted': NodeState.TERMINATED,
  112 + 'failed': NodeState.UNKNOWN,
  113 + 'unavailable': NodeState.UNKNOWN}
114 114
115 115 def _to_node(self, data):
116 116 return Node(
117   - id = data['id'],
118   - name = data['name'],
119   - state = self.NODE_STATE_MAP[data['status']],
120   - public_ips = list(map(lambda cloud_ip: cloud_ip['public_ip'],
  117 + id=data['id'],
  118 + name=data['name'],
  119 + state=self.NODE_STATE_MAP[data['status']],
  120 + public_ips=list(map(lambda cloud_ip: cloud_ip['public_ip'],
121 121 data['cloud_ips'])),
122   - private_ips = list(map(lambda interface: interface['ipv4_address'],
  122 + private_ips=list(map(lambda interface: interface['ipv4_address'],
123 123 data['interfaces'])),
124   - driver = self.connection.driver,
125   - extra = {
  124 + driver=self.connection.driver,
  125 + extra={
126 126 'status': data['status'],
127 127 'interfaces': data['interfaces']
128 128 }
@@ -130,10 +130,10 @@ def _to_node(self, data):
130 130
131 131 def _to_image(self, data):
132 132 return NodeImage(
133   - id = data['id'],
134   - name = data['name'],
135   - driver = self,
136   - extra = {
  133 + id=data['id'],
  134 + name=data['name'],
  135 + driver=self,
  136 + extra={
137 137 'description': data['description'],
138 138 'arch': data['arch']
139 139 }
@@ -141,21 +141,21 @@ def _to_image(self, data):
141 141
142 142 def _to_size(self, data):
143 143 return NodeSize(
144   - id = data['id'],
145   - name = data['name'],
146   - ram = data['ram'],
147   - disk = data['disk_size'],
148   - bandwidth = 0,
149   - price = 0,
150   - driver = self
  144 + id=data['id'],
  145 + name=data['name'],
  146 + ram=data['ram'],
  147 + disk=data['disk_size'],
  148 + bandwidth=0,
  149 + price=0,
  150 + driver=self
151 151 )
152 152
153 153 def _to_location(self, data):
154 154 return NodeLocation(
155   - id = data['id'],
156   - name = data['handle'],
157   - country = 'GB',
158   - driver = self
  155 + id=data['id'],
  156 + name=data['handle'],
  157 + country='GB',
  158 + driver=self
159 159 )
160 160
161 161 def _post(self, path, data={}):
85 libcloud/compute/drivers/cloudsigma.py
@@ -137,6 +137,7 @@
137 137 # Default timeout (in seconds) for the drive imaging process
138 138 IMAGING_TIMEOUT = 20 * 60
139 139
  140 +
140 141 class CloudSigmaException(Exception):
141 142 def __str__(self):
142 143 return self.args[0]
@@ -144,10 +145,12 @@ def __str__(self):
144 145 def __repr__(self):
145 146 return "<CloudSigmaException '%s'>" % (self.args[0])
146 147
  148 +
147 149 class CloudSigmaInsufficientFundsException(Exception):
148 150 def __repr__(self):
149 151 return "<CloudSigmaInsufficientFundsException '%s'>" % (self.args[0])
150 152
  153 +
151 154 class CloudSigmaResponse(Response):
152 155 def success(self):
153 156 if self.status == 401:
@@ -164,6 +167,7 @@ def parse_body(self):
164 167 def parse_error(self):
165 168 return 'Error: %s' % (self.body.replace('errors:', '').strip())
166 169
  170 +
167 171 class CloudSigmaNodeSize(NodeSize):
168 172 def __init__(self, id, name, cpu, ram, disk, bandwidth, price, driver):
169 173 self.id = id
@@ -181,6 +185,7 @@ def __repr__(self):
181 185 % (self.id, self.name, self.cpu, self.ram, self.disk, self.bandwidth,
182 186 self.price, self.driver.name))
183 187
  188 +
184 189 class CloudSigmaBaseConnection(ConnectionUserAndKey):
185 190 host = API_ENDPOINTS[DEFAULT_ENDPOINT]['host']
186 191 responseCls = CloudSigmaResponse
@@ -194,6 +199,7 @@ def add_default_headers(self, headers):
194 199
195 200 return headers
196 201
  202 +
197 203 class CloudSigmaBaseNodeDriver(NodeDriver):
198 204 type = Provider.CLOUDSIGMA
199 205 name = 'CloudSigma'
@@ -238,37 +244,37 @@ def destroy_node(self, node):
238 244 if not stopped:
239 245 raise CloudSigmaException('Could not stop node with id %s' % (node.id))
240 246
241   - response = self.connection.request(action = '/servers/%s/destroy' % (node.id),
242   - method = 'POST')
  247 + response = self.connection.request(action='/servers/%s/destroy' % (node.id),
  248 + method='POST')
243 249 return response.status == 204
244 250
245 251 def list_images(self, location=None):
246 252 """
247 253 Return a list of available standard images (this call might take up to 15 seconds to return).
248 254 """
249   - response = self.connection.request(action = '/drives/standard/info').object
  255 + response = self.connection.request(action='/drives/standard/info').object
250 256
251 257 images = []
252 258 for value in response:
253 259 if value.get('type'):
254 260 if value['type'] == 'disk':
255   - image = NodeImage(id = value['drive'], name = value['name'], driver = self.connection.driver,
256   - extra = {'size': value['size']})
  261 + image = NodeImage(id=value['drive'], name=value['name'], driver=self.connection.driver,
  262 + extra={'size': value['size']})
257 263 images.append(image)
258 264
259 265 return images
260 266
261   - def list_sizes(self, location = None):
  267 + def list_sizes(self, location=None):
262 268 """
263 269 Return a list of available node sizes.
264 270 """
265 271 sizes = []
266 272 for key, value in INSTANCE_TYPES.items():
267   - size = CloudSigmaNodeSize(id = value['id'], name = value['name'],
268   - cpu = value['cpu'], ram = value['memory'],
269   - disk = value['disk'], bandwidth = value['bandwidth'],
270   - price = self._get_size_price(size_id=key),
271   - driver = self.connection.driver)
  273 + size = CloudSigmaNodeSize(id=value['id'], name=value['name'],
  274 + cpu=value['cpu'], ram=value['memory'],
  275 + disk=value['disk'], bandwidth=value['bandwidth'],
  276 + price=self._get_size_price(size_id=key),
  277 + driver=self.connection.driver)
272 278 sizes.append(size)
273 279
274 280 return sizes
@@ -277,7 +283,7 @@ def list_nodes(self):
277 283 """
278 284 Return a list of nodes.
279 285 """
280   - response = self.connection.request(action = '/servers/info').object
  286 + response = self.connection.request(action='/servers/info').object
281 287
282 288 nodes = []
283 289 for data in response:
@@ -326,18 +332,18 @@ def create_node(self, **kwargs):
326 332 'size': '%sG' % (kwargs['size'].disk),
327 333 'driveType': drive_type})
328 334
329   - response = self.connection.request(action = '/drives/%s/clone' % image.id, data = dict2str(drive_data),
330   - method = 'POST').object
  335 + response = self.connection.request(action='/drives/%s/clone' % image.id, data=dict2str(drive_data),
  336 + method='POST').object
331 337
332 338 if not response:
333 339 raise CloudSigmaException('Drive creation failed')
334 340
335 341 drive_uuid = response[0]['drive']
336 342
337   - response = self.connection.request(action = '/drives/%s/info' % (drive_uuid)).object
  343 + response = self.connection.request(action='/drives/%s/info' % (drive_uuid)).object
338 344 imaging_start = time.time()
339 345 while 'imaging' in response[0]:
340   - response = self.connection.request(action = '/drives/%s/info' % (drive_uuid)).object
  346 + response = self.connection.request(action='/drives/%s/info' % (drive_uuid)).object
341 347 elapsed_time = time.time() - imaging_start
342 348 if 'imaging' in response[0] and elapsed_time >= IMAGING_TIMEOUT:
343 349 raise CloudSigmaException('Drive imaging timed out')
@@ -351,11 +357,11 @@ def create_node(self, **kwargs):
351 357 if vnc_password:
352 358 node_data.update({'vnc:ip': 'auto', 'vnc:password': vnc_password})
353 359
354   - response = self.connection.request(action = '/servers/create', data = dict2str(node_data),
355   - method = 'POST').object
  360 + response = self.connection.request(action='/servers/create', data=dict2str(node_data),
  361 + method='POST').object
356 362
357 363 if not isinstance(response, list):
358   - response = [ response ]
  364 + response = [response]
359 365
360 366 node = self._to_node(response[0])
361 367 if node is None:
@@ -397,7 +403,7 @@ def ex_static_ip_list(self):
397 403 """
398 404 Return a list of available static IP addresses.
399 405 """
400   - response = self.connection.request(action = '/resources/ip/list', method = 'GET')
  406 + response = self.connection.request(action='/resources/ip/list', method='GET')
401 407
402 408 if response.status != 200:
403 409 raise CloudSigmaException('Could not retrieve IP list')
@@ -409,7 +415,7 @@ def ex_drives_list(self):
409 415 """
410 416 Return a list of all the available drives.
411 417 """
412   - response = self.connection.request(action = '/drives/info', method = 'GET')
  418 + response = self.connection.request(action='/drives/info', method='GET')
413 419
414 420 result = str2dicts(response.body)
415 421 return result
@@ -418,7 +424,7 @@ def ex_static_ip_create(self):
418 424 """
419 425 Create a new static IP address.
420 426 """
421   - response = self.connection.request(action = '/resources/ip/create', method = 'GET')
  427 + response = self.connection.request(action='/resources/ip/create', method='GET')
422 428
423 429 result = str2dicts(response.body)
424 430 return result
@@ -427,7 +433,7 @@ def ex_static_ip_destroy(self, ip_address):
427 433 """
428 434 Destroy a static IP address.
429 435 """
430   - response = self.connection.request(action = '/resources/ip/%s/destroy' % (ip_address), method = 'GET')
  436 + response = self.connection.request(action='/resources/ip/%s/destroy' % (ip_address), method='GET')
431 437
432 438 return response.status == 204
433 439
@@ -436,11 +442,10 @@ def ex_drive_destroy(self, drive_uuid):
436 442 Destroy a drive with a specified uuid.
437 443 If the drive is currently mounted an exception is thrown.
438 444 """
439   - response = self.connection.request(action = '/drives/%s/destroy' % (drive_uuid), method = 'POST')
  445 + response = self.connection.request(action='/drives/%s/destroy' % (drive_uuid), method='POST')
440 446
441 447 return response.status == 204
442 448
443   -
444 449 def ex_set_node_configuration(self, node, **kwargs):
445 450 """
446 451 Update a node configuration.
@@ -464,8 +469,8 @@ def ex_set_node_configuration(self, node, **kwargs):
464 469 if invalid_keys:
465 470 raise CloudSigmaException('Invalid configuration key specified: %s' % (',' .join(invalid_keys)))
466 471
467   - response = self.connection.request(action = '/servers/%s/set' % (node.id), data = dict2str(kwargs),
468   - method = 'POST')
  472 + response = self.connection.request(action='/servers/%s/set' % (node.id), data=dict2str(kwargs),
  473 + method='POST')
469 474
470 475 return (response.status == 200 and response.body != '')
471 476
@@ -473,8 +478,8 @@ def ex_start_node(self, node):
473 478 """
474 479 Start a node.
475 480 """
476   - response = self.connection.request(action = '/servers/%s/start' % (node.id),
477   - method = 'POST')
  481 + response = self.connection.request(action='/servers/%s/start' % (node.id),
  482 + method='POST')
478 483
479 484 return response.status == 200
480 485
@@ -482,8 +487,8 @@ def ex_stop_node(self, node):
482 487 """
483 488 Stop (shutdown) a node.
484 489 """
485   - response = self.connection.request(action = '/servers/%s/stop' % (node.id),
486   - method = 'POST')
  490 + response = self.connection.request(action='/servers/%s/stop' % (node.id),
  491 + method='POST')
487 492 return response.status == 204
488 493
489 494 def ex_shutdown_node(self, node):
@@ -496,8 +501,8 @@ def ex_destroy_drive(self, drive_uuid):
496 501 """
497 502 Destroy a drive.
498 503 """
499   - response = self.connection.request(action = '/drives/%s/destroy' % (drive_uuid),
500   - method = 'POST')
  504 + response = self.connection.request(action='/drives/%s/destroy' % (drive_uuid),
  505 + method='POST')
501 506 return response.status == 204
502 507
503 508 def _to_node(self, data):
@@ -520,7 +525,7 @@ def _to_node(self, data):
520 525 public_ips = [data['nic:0:dhcp']]
521 526
522 527 extra = {}
523   - extra_keys = [ ('cpu', 'int'), ('smp', 'auto'), ('mem', 'int'), ('status', 'str') ]
  528 + extra_keys = [('cpu', 'int'), ('smp', 'auto'), ('mem', 'int'), ('status', 'str')]
524 529 for key, value_type in extra_keys:
525 530 if key in data:
526 531 value = data[key]
@@ -538,9 +543,9 @@ def _to_node(self, data):
538 543 if 'vnc:ip' in data and 'vnc:password' in data:
539 544 extra.update({'vnc_ip': data['vnc:ip'], 'vnc_password': data['vnc:password']})
540 545
541   - node = Node(id = data['server'], name = data['name'], state = state,
542   - public_ips = public_ips, private_ips = None, driver = self.connection.driver,
543   - extra = extra)
  546 + node = Node(id=data['server'], name=data['name'], state=state,
  547 + public_ips=public_ips, private_ips=None, driver=self.connection.driver,
  548 + extra=extra)
544 549
545 550 return node
546 551 return None
@@ -555,17 +560,19 @@ def _get_node(self, node_id):
555 560 return node[0]
556 561
557 562 def _get_node_info(self, node):
558   - response = self.connection.request(action = '/servers/%s/info' % (node.id))
  563 + response = self.connection.request(action='/servers/%s/info' % (node.id))
559 564
560 565 result = str2dicts(response.body)
561 566 return result[0]
562 567
  568 +
563 569 class CloudSigmaZrhConnection(CloudSigmaBaseConnection):
564 570 """
565 571 Connection class for the CloudSigma driver for the Zurich end-point
566 572 """
567 573 host = API_ENDPOINTS[DEFAULT_ENDPOINT]['host']
568 574
  575 +
569 576 class CloudSigmaZrhNodeDriver(CloudSigmaBaseNodeDriver):
570 577 """
571 578 CloudSigma node driver for the Zurich end-point
@@ -573,12 +580,14 @@ class CloudSigmaZrhNodeDriver(CloudSigmaBaseNodeDriver):
573 580 connectionCls = CloudSigmaZrhConnection
574 581 api_name = 'cloudsigma_zrh'
575 582
  583 +
576 584 class CloudSigmaLvsConnection(CloudSigmaBaseConnection):
577 585 """
578 586 Connection class for the CloudSigma driver for the Las Vegas end-point
579 587 """
580 588 host = API_ENDPOINTS['lvs']['host']
581 589
  590 +
582 591 class CloudSigmaLvsNodeDriver(CloudSigmaBaseNodeDriver):
583 592 """
584 593 CloudSigma node driver for the Las Vegas end-point
6 libcloud/compute/drivers/cloudstack.py
@@ -14,11 +14,10 @@
14 14 # limitations under the License.
15 15
16 16 from libcloud.compute.providers import Provider
17   -from libcloud.common.cloudstack import CloudStackConnection, \
18   - CloudStackDriverMixIn
  17 +from libcloud.common.cloudstack import CloudStackDriverMixIn
19 18 from libcloud.compute.base import Node, NodeDriver, NodeImage, NodeLocation, \
20 19 NodeSize
21   -from libcloud.compute.types import DeploymentError, NodeState
  20 +from libcloud.compute.types import NodeState
22 21
23 22 class CloudStackNode(Node):
24 23 "Subclass of Node so we can expose our extension methods."
@@ -202,7 +201,6 @@ def create_node(self, name, size, image, location=None, **kwargs):
202 201 if location is None:
203 202 location = self.list_locations()[0]
204 203
205   -
206 204 network_id = kwargs.pop('network_id', None)
207 205 if network_id is None:
208 206 networks = self._sync_request('listNetworks')
6 libcloud/compute/drivers/dreamhost.py
@@ -239,6 +239,6 @@ def _to_node(self, data):
239 239 private_ips = [],
240 240 driver = self.connection.driver,
241 241 extra = {
242   - 'current_size' : data['memory_mb'],
243   - 'account_id' : data['account_id'],
244   - 'type' : data['type']})
  242 + 'current_size': data['memory_mb'],
  243 + 'account_id': data['account_id'],
  244 + 'type': data['type']})
62 libcloud/compute/drivers/dummy.py
@@ -67,40 +67,40 @@ class DummyNodeDriver(NodeDriver):
67 67 def __init__(self, creds):
68 68 self.creds = creds
69 69 try:
70   - num = int(creds)
  70 + num = int(creds)
71 71 except ValueError:
72   - num = None
  72 + num = None
73 73 if num:
74   - self.nl = []
75   - startip = _ip_to_int('127.0.0.1')
76   - for i in range(num):
77   - ip = _int_to_ip(startip + i)
78   - self.nl.append(
79   - Node(id=i,
80   - name='dummy-%d' % (i),
81   - state=NodeState.RUNNING,
82   - public_ips=[ip],
83   - private_ips=[],
84   - driver=self,
85   - extra={'foo': 'bar'})
86   - )
  74 + self.nl = []
  75 + startip = _ip_to_int('127.0.0.1')
  76 + for i in range(num):
  77 + ip = _int_to_ip(startip + i)
  78 + self.nl.append(
  79 + Node(id=i,
  80 + name='dummy-%d' % (i),
  81 + state=NodeState.RUNNING,
  82 + public_ips=[ip],
  83 + private_ips=[],
  84 + driver=self,
  85 + extra={'foo': 'bar'})
  86 + )
87 87 else:
88   - self.nl = [
89   - Node(id=1,
90   - name='dummy-1',
91   - state=NodeState.RUNNING,
92   - public_ips=['127.0.0.1'],
93   - private_ips=[],
94   - driver=self,
95   - extra={'foo': 'bar'}),
96   - Node(id=2,
97   - name='dummy-2',
98   - state=NodeState.RUNNING,
99   - public_ips=['127.0.0.1'],
100   - private_ips=[],
101   - driver=self,
102   - extra={'foo': 'bar'}),
103   - ]
  88 + self.nl = [
  89 + Node(id=1,
  90 + name='dummy-1',
  91 + state=NodeState.RUNNING,
  92 + public_ips=['127.0.0.1'],
  93 + private_ips=[],
  94 + driver=self,
  95 + extra={'foo': 'bar'}),
  96 + Node(id=2,
  97 + name='dummy-2',
  98 + state=NodeState.RUNNING,
  99 + public_ips=['127.0.0.1'],
  100 + private_ips=[],
  101 + driver=self,
  102 + extra={'foo': 'bar'}),
  103 + ]
104 104 self.connection = DummyConnection(self.creds)
105 105
106 106 def get_uuid(self, unique_field=None):
13 libcloud/compute/drivers/ecp.py
@@ -86,9 +86,9 @@ def add_default_headers(self, headers):
86 86 #Authentication
87 87 username = self.user_id
88 88 password = self.key
89   - base64string = base64.encodestring(
  89 + base64string = base64.encodestring(
90 90 b('%s:%s' % (username, password)))[:-1]
91   - authheader = "Basic %s" % base64string
  91 + authheader = "Basic %s" % base64string
92 92 headers['Authorization']= authheader
93 93
94 94 return headers
@@ -143,7 +143,6 @@ def list_nodes(self):
143 143 #And return it
144 144 return nodes
145 145
146   -
147 146 def _to_node(self, vm):
148 147 """
149 148 Turns a (json) dictionary into a Node object.
@@ -209,7 +208,6 @@ def reboot_node(self, node):
209 208 else:
210 209 time.sleep(5)
211 210
212   -
213 211 #Turn the VM back on.
214 212 #Black magic to make the POST requests work
215 213 d = self.connection._encode_multipart_formdata({'action':'start'})
@@ -283,7 +281,6 @@ def list_images(self, location=None):
283 281
284 282 return images
285 283
286   -
287 284 def list_sizes(self, location=None):
288 285 """
289 286 Returns a list of all hardware templates
@@ -300,9 +297,9 @@ def list_sizes(self, location=None):
300 297 id = htemplate['uuid'],
301 298 name = htemplate['name'],
302 299 ram = htemplate['memory'],
303   - disk = 0, #Disk is independent of hardware template
304   - bandwidth = 0, #There is no way to keep track of bandwidth
305   - price = 0, #The billing system is external
  300 + disk = 0, # Disk is independent of hardware template.
  301 + bandwidth = 0, # There is no way to keep track of bandwidth.
  302 + price = 0, # The billing system is external.
306 303 driver = self,
307 304 ))
308 305
3  libcloud/compute/drivers/gandi.py
@@ -94,7 +94,7 @@ def list_nodes(self):
94 94
95 95 def reboot_node(self, node):
96 96 op = self.connection.request('vm.reboot', int(node.id))
97   - op_res = self._wait_operation(op['id'])
  97 + self._wait_operation(op['id'])
98 98 vm = self.connection.request('vm.info', int(node.id))
99 99 if vm['state'] == 'running':
100 100 return True
@@ -330,7 +330,6 @@ def _to_disks(self, elements):
330 330 def ex_list_disks(self):
331 331 """Specific method to list all disk"""
332 332 res = self.connection.request('disk.list', {})
333   - disks = []
334 333 return self._to_disks(res)
335 334
336 335 def ex_node_attach_disk(self, node, disk):
21 libcloud/compute/drivers/gogrid.py
@@ -165,18 +165,17 @@ def list_nodes(self):
165 165
166 166 res = self._server_list()
167 167 try:
168   - for password in self._password_list()['list']:
169   - try:
170   - passwords_map[password['server']['id']] = password['password']
171   - except KeyError:
172   - pass
  168 + for password in self._password_list()['list']:
  169 + try:
  170 + passwords_map[password['server']['id']] = password['password']
  171 + except KeyError:
  172 + pass
173 173 except InvalidCredsError:
174   - # some gogrid API keys don't have permission to access the password list.
175   - pass
  174 + # some gogrid API keys don't have permission to access the password list.
  175 + pass
176 176
177   - return [ self._to_node(el, passwords_map.get(el.get('id')))
178   - for el
179   - in res['list'] ]
  177 + return [self._to_node(el, passwords_map.get(el.get('id')))
  178 + for el in res['list']]
180 179
181 180 def reboot_node(self, node):
182 181 id = node.id
@@ -213,7 +212,7 @@ def _server_delete(self, id):
213 212 def _get_first_ip(self, location=None):
214 213 ips = self.ex_list_ips(public=True, assigned=False, location=location)
215 214 try:
216   - return ips[0].ip
  215 + return ips[0].ip
217 216 except IndexError:
218 217 raise LibcloudError('No public unassigned IPs left',
219 218 GoGridNodeDriver)
36 libcloud/compute/drivers/ibm_sbc.py
@@ -12,10 +12,12 @@
12 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 13 # See the License for the specific language governing permissions and
14 14 # limitations under the License.
  15 +
15 16 """
16 17 Driver for the IBM Developer Cloud.
17 18 """
18   -import base64, urllib
  19 +
  20 +import base64
19 21
20 22 from libcloud.utils.py3 import urlencode
21 23 from libcloud.utils.py3 import b
@@ -67,22 +69,22 @@ class IBMNodeDriver(NodeDriver):
67 69 type = Provider.IBM
68 70 name = "IBM Developer Cloud"
69 71
70   - NODE_STATE_MAP = { 0: NodeState.PENDING, # New
71   - 1: NodeState.PENDING, # Provisioning
72   - 2: NodeState.TERMINATED, # Failed
73   - 3: NodeState.TERMINATED, # Removed
74   - 4: NodeState.TERMINATED, # Rejected
75   - 5: NodeState.RUNNING, # Active
76   - 6: NodeState.UNKNOWN, # Unknown
77   - 7: NodeState.PENDING, # Deprovisioning
78   - 8: NodeState.REBOOTING, # Restarting
79   - 9: NodeState.PENDING, # Starting
80   - 10: NodeState.PENDING, # Stopping
81   - 11: NodeState.TERMINATED,# Stopped
82   - 12: NodeState.PENDING, # Deprovision Pending
83   - 13: NodeState.PENDING, # Restart Pending
84   - 14: NodeState.PENDING, # Attaching
85   - 15: NodeState.PENDING } # Detaching
  72 + NODE_STATE_MAP = { 0: NodeState.PENDING, # New
  73 + 1: NodeState.PENDING, # Provisioning
  74 + 2: NodeState.TERMINATED, # Failed
  75 + 3: NodeState.TERMINATED, # Removed
  76 + 4: NodeState.TERMINATED, # Rejected
  77 + 5: NodeState.RUNNING, # Active
  78 + 6: NodeState.UNKNOWN, # Unknown
  79 + 7: NodeState.PENDING, # Deprovisioning
  80 + 8: NodeState.REBOOTING, # Restarting
  81 + 9: NodeState.PENDING, # Starting
  82 + 10: NodeState.PENDING, # Stopping
  83 + 11: NodeState.TERMINATED, # Stopped
  84 + 12: NodeState.PENDING, # Deprovision Pending
  85 + 13: NodeState.PENDING, # Restart Pending
  86 + 14: NodeState.PENDING, # Attaching
  87 + 15: NodeState.PENDING } # Detaching
86 88
87 89 def create_node(self, **kwargs):
88 90 """
26 libcloud/compute/drivers/linode.py
@@ -33,7 +33,6 @@
33 33 import json
34 34
35 35 import itertools
36   -import os
37 36 import binascii
38 37
39 38 from copy import copy
@@ -229,8 +228,10 @@ def create_node(self, **kwargs):
229 228 raise LinodeException(0xFB, "Root password is too short")
230 229
231 230 # Swap size
232   - try: swap = 128 if "ex_swap" not in kwargs else int(kwargs["ex_swap"])
233   - except: raise LinodeException(0xFB, "Need an integer swap size")
  231 + try:
  232 + swap = 128 if "ex_swap" not in kwargs else int(kwargs["ex_swap"])
  233 + except:
  234 + raise LinodeException(0xFB, "Need an integer swap size")
234 235
235 236 # Root partition size
236 237 imagesize = (size.disk - swap) if "ex_rsize" not in kwargs else \
@@ -308,7 +309,8 @@ def create_node(self, **kwargs):
308 309 "Size": imagesize,
309 310 "rootPass": root,
310 311 }
311   - if ssh: params["rootSSHKey"] = ssh
  312 + if ssh:
  313 + params["rootSSHKey"] = ssh
312 314 data = self.connection.request(API_ROOT, params=params).objects[0]
313 315 linode["rootimage"] = data["DiskID"]
314 316
@@ -399,10 +401,14 @@ def list_locations(self):
399 401 nl = []
400 402 for dc in data:
401 403 country = None
402   - if "USA" in dc["LOCATION"]: country = "US"
403   - elif "UK" in dc["LOCATION"]: country = "GB"
404   - elif "JP" in dc["LOCATION"]: country = "JP"
405   - else: country = "??"
  404 + if "USA" in dc["LOCATION"]:
  405 + country = "US"
  406 + elif "UK" in dc["LOCATION"]:
  407 + country = "GB"
  408 + elif "JP" in dc["LOCATION"]:
  409 + country = "JP"
  410 + else:
  411 + country = "??"
406 412 nl.append(NodeLocation(dc["DATACENTERID"],
407 413 dc["LOCATION"],
408 414 country,
@@ -483,9 +489,11 @@ def _izip_longest(*args, **kwds):
483 489
484 490 http://docs.python.org/library/itertools.html#itertools.izip
485 491 """
  492 +
486 493 fillvalue = kwds.get('fillvalue')
  494 +
487 495 def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
488   - yield counter() # yields the fillvalue, or raises IndexError
  496 + yield counter() # yields the fillvalue, or raises IndexError
489 497 fillers = itertools.repeat(fillvalue)
490 498 iters = [itertools.chain(it, sentinel(), fillers) for it in args]
491 499 try:
12 libcloud/compute/drivers/rimuhosting.py
@@ -91,7 +91,7 @@ def add_default_headers(self, headers):
91 91 headers['Content-Type'] = 'application/json'
92 92
93 93 headers['Authorization'] = 'rimuhosting apikey=%s' % (self.key)
94   - return headers;
  94 + return headers
95 95
96 96 def request(self, action, params=None, data='', headers=None, method='GET'):
97 97 if not headers:
@@ -116,7 +116,7 @@ def __init__(self, key, host=API_HOST, port=443,
116 116 # Pass in some extra vars so that
117 117 self.key = key
118 118 self.secure = secure
119   - self.connection = self.connectionCls(key ,secure)
  119 + self.connection = self.connectionCls(key, secure)
120 120 self.connection.host = host
121 121 self.connection.api_context = api_context
122 122 self.connection.port = port
@@ -163,25 +163,25 @@ def list_sizes(self, location=None):
163 163 # Get plans. Note this is really just for libcloud.
164 164 # We are happy with any size.
165 165 if location == None:
166   - location = '';</