Permalink
Browse files

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...
1 parent cca04c7 commit 3cda3bed2f3be776575e506dc735357204618a47 Hutson Betts committed Dec 11, 2011
Showing with 286 additions and 278 deletions.
  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
View
@@ -31,14 +31,16 @@
import sys
# Add parent dir of this file's dir to sys.path (OS-agnostically)
-sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
+sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__),
+ os.path.pardir)))
from libcloud.common.types import InvalidCredsError
from libcloud.compute.types import Provider
from libcloud.providers import get_driver
from pprint import pprint
+
def get_demo_driver(provider_name='RACKSPACE', *args, **kwargs):
"""An easy way to play with a driver interactively.
@@ -77,8 +79,8 @@ def get_demo_driver(provider_name='RACKSPACE', *args, **kwargs):
return DriverClass(*args, **kwargs)
except InvalidCredsError:
raise InvalidCredsError(
- 'valid values should be put in secrets.py'
- )
+ 'valid values should be put in secrets.py')
+
def main(argv):
"""Main Compute Demo
View
@@ -20,11 +20,11 @@
Slicehost = get_driver(Provider.SLICEHOST)
Rackspace = get_driver(Provider.RACKSPACE)
-drivers = [ EC2('access key id', 'secret key'),
+drivers = [EC2('access key id', 'secret key'),
Slicehost('api key'),
- Rackspace('username', 'api key') ]
+ Rackspace('username', 'api key')]
-nodes = [ driver.list_nodes() for driver in drivers ]
+nodes = [driver.list_nodes() for driver in drivers]
print(nodes)
# [ <Node: provider=Amazon, status=RUNNING, name=bob, ip=1.2.3.4.5>,
View
@@ -22,6 +22,7 @@
from libcloud.loadbalancer.types import Provider, State
from libcloud.loadbalancer.providers import get_driver
+
def main():
Rackspace = get_driver(Provider.RACKSPACE_US)
View
@@ -15,4 +15,5 @@
from libcloud.common.base import XmlResponse
-class AWSBaseResponse(XmlResponse): pass
+class AWSBaseResponse(XmlResponse):
+ pass
View
@@ -136,9 +136,9 @@ def parse_body(self):
return self.body
try:
- body = ET.XML(self.body)
+ body = ET.XML(self.body)
except:
- raise MalformedResponseError("Failed to parse XML",
+ raise MalformedResponseError("Failed to parse XML",
body=self.body,
driver=self.connection.driver)
return body
@@ -156,7 +156,6 @@ def __init__(self, connection):
self._reason = None
self.connection = connection
-
@property
def response(self):
if not self._response:
@@ -208,10 +207,12 @@ def _log_response(self, r):
for h in r.getheaders():
ht += "%s: %s\r\n" % (h[0].title(), h[1])
ht += "\r\n"
+
# this is evil. laugh with me. ha arharhrhahahaha
class fakesock:
def __init__(self, s):
self.s = s
+
def makefile(self, mode, foo):
return StringIO(self.s)
rr = r
@@ -261,11 +262,12 @@ def getresponse(self):
def request(self, method, url, body=None, headers=None):
headers.update({'X-LC-Request-ID': str(id(self))})
if self.log is not None:
- pre = "# -------- begin %d request ----------\n" % id(self)
+ pre = "# -------- begin %d request ----------\n" % id(self)
self.log.write(pre +
self._log_curl(method, url, body, headers) + "\n")
self.log.flush()
- return LibcloudHTTPSConnection.request(self, method, url, body, headers)
+ return LibcloudHTTPSConnection.request(self, method, url, body,
+ headers)
class LoggingHTTPConnection(LoggingConnection, LibcloudHTTPConnection):
"""
@@ -283,7 +285,7 @@ def getresponse(self):
def request(self, method, url, body=None, headers=None):
headers.update({'X-LC-Request-ID': str(id(self))})
if self.log is not None:
- pre = "# -------- begin %d request ----------\n" % id(self)
+ pre = "# -------- begin %d request ----------\n" % id(self)
self.log.write(pre +
self._log_curl(method, url, body, headers) + "\n")
self.log.flush()
@@ -326,15 +328,17 @@ def __init__(self, secure=True, host=None, port=None, url=None):
self.port = 80
if url:
- (self.host, self.port, self.secure, self.request_path) = self._tuple_from_url(url)
+ (self.host, self.port, self.secure,
+ self.request_path) = self._tuple_from_url(url)
def set_context(self, context):
self.context = context
def _tuple_from_url(self, url):
secure = 1
port = None
- scheme, netloc, request_path, param, query, fragment = urlparse.urlparse(url)
+ (scheme, netloc, request_path, param,
+ query, fragment) = urlparse.urlparse(url)
if scheme not in ['http', 'https']:
raise LibcloudError('Invalid scheme: %s in url %s' % (scheme, url))
@@ -356,7 +360,7 @@ def _tuple_from_url(self, url):
return (host, port, secure, request_path)
- def connect(self, host=None, port=None, base_url = None):
+ def connect(self, host=None, port=None, base_url=None):
"""
Establish a connection with the API server.
@@ -511,7 +515,7 @@ def request(self,
return response
def morph_action_hook(self, action):
- return self.request_path + action
+ return self.request_path + action
def add_default_params(self, params):
"""
@@ -570,7 +574,7 @@ def async_request(self, action, params=None, data='', headers=None,
"""
Perform an 'async' request to the specified path. Keep in mind that
this function is *blocking* and 'async' in this case means that the
- hit URL only returns a job ID which is the periodically polled until
+ hit URL only returns a job ID which is the periodically polled until
the job has completed.
This function works like this:
@@ -24,7 +24,10 @@
from libcloud.common.base import JsonResponse
from libcloud.common.types import MalformedResponseError
-class CloudStackResponse(JsonResponse): pass
+
+class CloudStackResponse(JsonResponse):
+ pass
+
class CloudStackConnection(ConnectionUserAndKey, PollingConnection):
responseCls = CloudStackResponse
@@ -98,6 +101,7 @@ def _sync_request(self, command, **kwargs):
result = result.object[command]
return result
+
class CloudStackDriverMixIn(object):
host = None
path = None
View
@@ -22,11 +22,7 @@
from libcloud.utils.py3 import xmlrpclib
from libcloud.utils.py3 import b
-import libcloud
from libcloud.common.base import ConnectionKey
-from libcloud.compute.types import Provider, NodeState
-from libcloud.compute.base import NodeDriver, Node, \
- NodeLocation, NodeSize, NodeImage
# Global constants
API_VERSION = '2.0'
View
@@ -24,7 +24,7 @@
from libcloud.compute.base import NodeLocation
HOST = 'api.gogrid.com'
-PORTS_BY_SECURITY = { True: 443, False: 80 }
+PORTS_BY_SECURITY = {True: 443, False: 80}
API_VERSION = '1.8'
__all__ = ["GoGridResponse",
@@ -36,8 +36,8 @@
class GoGridResponse(JsonResponse):
def __init__(self, *args, **kwargs):
- self.driver = BaseGoGridDriver
- super(GoGridResponse, self).__init__(*args, **kwargs)
+ self.driver = BaseGoGridDriver
+ super(GoGridResponse, self).__init__(*args, **kwargs)
def success(self):
if self.status == 403:
@@ -76,7 +76,7 @@ def add_default_params(self, params):
def get_signature(self, key, secret):
""" create sig from md5 of key + secret + time """
- m = hashlib.md5(b(key+secret+str(int(time.time()))))
+ m = hashlib.md5(b(key + secret + str(int(time.time()))))
return m.hexdigest()
class GoGridIpAddress(object):
@@ -111,8 +111,8 @@ def _to_ip(self, element):
return ip
def _to_ips(self, object):
- return [ self._to_ip(el)
- for el in object['list'] ]
+ return [self._to_ip(el)
+ for el in object['list']]
def _to_location(self, element):
location = NodeLocation(id=element['id'],
@@ -125,7 +125,6 @@ def _to_locations(self, object):
return [self._to_location(el)
for el in object['list']]
-
def ex_list_ips(self, **kwargs):
"""Return list of IP addresses assigned to
the account.
View
@@ -29,16 +29,16 @@
API_ROOT = '/'
# Constants that map a RAM figure to a PlanID (updated 6/28/10)
-LINODE_PLAN_IDS = {512:'1',
- 768:'2',
- 1024:'3',
- 1536:'4',
- 2048:'5',
- 4096:'6',
- 8192:'7',
- 12288:'8',
- 16384:'9',
- 20480:'10'}
+LINODE_PLAN_IDS = {512: '1',
+ 768: '2',
+ 1024: '3',
+ 1536: '4',
+ 2048: '5',
+ 4096: '6',
+ 8192: '7',
+ 12288: '8',
+ 16384: '9',
+ 20480: '10'}
class LinodeException(Exception):
View
@@ -375,9 +375,9 @@ class NodeDriver(BaseDriver):
def __init__(self, key, secret=None, secure=True, host=None, port=None,
api_version=None):
- super(NodeDriver, self).__init__(key=key, secret=secret, secure=secure,
- host=host, port=port,
- api_version=api_version)
+ super(NodeDriver, self).__init__(key=key, secret=secret, secure=secure,
+ host=host, port=port,
+ api_version=api_version)
def create_node(self, **kwargs):
"""Create a new node instance.
@@ -120,7 +120,7 @@ class MultiStepDeployment(Deployment):
"""
Runs a chain of Deployment steps.
"""
- def __init__(self, add = None):
+ def __init__(self, add=None):
"""
@type add: C{list}
@keyword add: Deployment steps to add.
@@ -32,7 +32,6 @@
from libcloud.common.base import JsonResponse, ConnectionUserAndKey
from libcloud.compute.providers import Provider
from libcloud.compute.types import NodeState, InvalidCredsError
-from libcloud.common.types import MalformedResponseError
from libcloud.compute.base import Node, NodeDriver
from libcloud.compute.base import NodeSize, NodeImage, NodeLocation
from libcloud.compute.base import NodeAuthPassword, NodeAuthSSHKey
@@ -76,11 +75,11 @@
RAM_PER_CPU = 2048
-NODE_STATE_MAP = { 'queued': NodeState.PENDING,
- 'building': NodeState.PENDING,
- 'running': NodeState.RUNNING,
- 'error': NodeState.TERMINATED,
- 'unknown': NodeState.UNKNOWN }
+NODE_STATE_MAP = {'queued': NodeState.PENDING,
+ 'building': NodeState.PENDING,
+ 'running': NodeState.RUNNING,
+ 'error': NodeState.TERMINATED,
+ 'unknown': NodeState.UNKNOWN}
class BlueboxResponse(JsonResponse):
def parse_error(self):
@@ -137,7 +136,7 @@ def list_sizes(self, location=None):
sizes = []
for key, values in list(BLUEBOX_INSTANCE_TYPES.items()):
attributes = copy.deepcopy(values)
- attributes.update({ 'price': self._get_size_price(size_id=key) })
+ attributes.update({'price': self._get_size_price(size_id=key)})
sizes.append(BlueboxNodeSize(driver=self.connection.driver,
**attributes))
@@ -147,12 +146,12 @@ def list_images(self, location=None):
result = self.connection.request('/api/block_templates.json')
images = []
for image in result.object:
- images.extend([self._to_image(image)])
+ images.extend([self._to_image(image)])
return images
def create_node(self, **kwargs):
- headers = { 'Content-Type': 'application/x-www-form-urlencoded' }
+ headers = {'Content-Type': 'application/x-www-form-urlencoded'}
size = kwargs["size"]
name = kwargs['name']
@@ -213,7 +212,7 @@ def _to_node(self, vm):
n = Node(id=vm['id'],
name=vm['hostname'],
state=state,
- public_ips=[ ip['address'] for ip in vm['ips'] ],
+ public_ips=[ip['address'] for ip in vm['ips']],
private_ips=[],
extra={'storage':vm['storage'], 'cpu':vm['cpu']},
driver=self.connection.driver)
Oops, something went wrong.

0 comments on commit 3cda3be

Please sign in to comment.