You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/10/26 00:01:46 UTC
[6/9] Add new "lint" target to tox,
flake8 fixes in the whole codebase.
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/compute/drivers/vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py
index 68ec73d..a457d88 100644
--- a/libcloud/compute/drivers/vcloud.py
+++ b/libcloud/compute/drivers/vcloud.py
@@ -38,7 +38,7 @@ from libcloud.common.types import InvalidCredsError, LibcloudError
from libcloud.compute.providers import Provider
from libcloud.compute.types import NodeState
from libcloud.compute.base import Node, NodeDriver, NodeLocation
-from libcloud.compute.base import NodeSize, NodeImage, NodeAuthPassword
+from libcloud.compute.base import NodeSize, NodeImage
"""
From vcloud api "The VirtualQuantity element defines the number of MB
@@ -75,7 +75,6 @@ class Vdc(object):
"""
Virtual datacenter (vDC) representation
"""
-
def __init__(self, id, name, driver, allocation_model=None, cpu=None,
memory=None, storage=None):
self.id = id
@@ -109,7 +108,6 @@ class ControlAccess(object):
"""
Represents control access settings of a node
"""
-
class AccessLevel(object):
READ_ONLY = 'ReadOnly'
CHANGE = 'Change'
@@ -123,7 +121,8 @@ class ControlAccess(object):
self.subjects = subjects
def __repr__(self):
- return ('<ControlAccess: node=%s, everyone_access_level=%s, subjects=%s>'
+ return ('<ControlAccess: node=%s, everyone_access_level=%s, '
+ 'subjects=%s>'
% (self.node, self.everyone_access_level, self.subjects))
@@ -143,6 +142,7 @@ class Subject(object):
class InstantiateVAppXML(object):
+
def __init__(self, name, template, net_href, cpus, memory,
password=None, row=None, group=None):
self.name = name
@@ -164,7 +164,7 @@ class InstantiateVAppXML(object):
self._add_vapp_template(self.root)
instantiation_params = ET.SubElement(self.root,
- "InstantiationParams")
+ "InstantiationParams")
# product and virtual hardware
self._make_product_section(instantiation_params)
@@ -296,12 +296,14 @@ class InstantiateVAppXML(object):
class VCloudResponse(XmlResponse):
+
def success(self):
return self.status in (httplib.OK, httplib.CREATED,
httplib.NO_CONTENT, httplib.ACCEPTED)
class VCloudConnection(ConnectionUserAndKey):
+
"""
Connection class for the vCloud driver
"""
@@ -354,6 +356,7 @@ class VCloudConnection(ConnectionUserAndKey):
class VCloudNodeDriver(NodeDriver):
+
"""
vCloud node driver
"""
@@ -397,7 +400,7 @@ class VCloudNodeDriver(NodeDriver):
:rtype: ``list`` of :class:`Vdc`
"""
if not self._vdcs:
- self.connection.check_org() # make sure the org is set. # pylint: disable-msg=E1101
+ self.connection.check_org() # make sure the org is set.
res = self.connection.request(self.org)
self._vdcs = [
self._to_vdc(
@@ -575,23 +578,25 @@ class VCloudNodeDriver(NodeDriver):
vapps = [
(i.get('name'), i.get('href'))
for i in elms
- if i.get('type')
- == 'application/vnd.vmware.vcloud.vApp+xml'
- and i.get('name')
+ if i.get('type') == 'application/vnd.vmware.vcloud.vApp+xml'
+ and i.get('name')
]
for vapp_name, vapp_href in vapps:
try:
res = self.connection.request(
get_url_path(vapp_href),
- headers={'Content-Type': 'application/vnd.vmware.vcloud.vApp+xml'}
+ headers={'Content-Type':
+ 'application/vnd.vmware.vcloud.vApp+xml'}
)
nodes.append(self._to_node(res.object))
except Exception:
- # The vApp was probably removed since the previous vDC query, ignore
+ # The vApp was probably removed since the previous vDC
+ # query, ignore
e = sys.exc_info()[1]
if not (e.args[0].tag.endswith('Error') and
- e.args[0].get('minorErrorCode') == 'ACCESS_TO_RESOURCE_IS_FORBIDDEN'):
+ e.args[0].get('minorErrorCode') ==
+ 'ACCESS_TO_RESOURCE_IS_FORBIDDEN'):
raise
return nodes
@@ -625,7 +630,7 @@ class VCloudNodeDriver(NodeDriver):
cat_item_hrefs = [i.get('href')
for i in cat_items
if i.get('type') ==
- 'application/vnd.vmware.vcloud.catalogItem+xml']
+ 'application/vnd.vmware.vcloud.catalogItem+xml']
return cat_item_hrefs
@@ -634,8 +639,7 @@ class VCloudNodeDriver(NodeDriver):
res = self.connection.request(
get_url_path(catalog_item),
headers={
- 'Content-Type':
- 'application/vnd.vmware.vcloud.catalogItem+xml'
+ 'Content-Type': 'application/vnd.vmware.vcloud.catalogItem+xml'
}
).object
@@ -652,7 +656,7 @@ class VCloudNodeDriver(NodeDriver):
self._to_image(i)
for i in res_ents
if i.get('type') ==
- 'application/vnd.vmware.vcloud.vAppTemplate+xml'
+ 'application/vnd.vmware.vcloud.vAppTemplate+xml'
]
for catalog in self._get_catalog_hrefs():
@@ -663,7 +667,7 @@ class VCloudNodeDriver(NodeDriver):
self._to_image(i)
for i in res_ents
if i.get('type') ==
- 'application/vnd.vmware.vcloud.vAppTemplate+xml'
+ 'application/vnd.vmware.vcloud.vAppTemplate+xml'
]
def idfun(image):
@@ -734,12 +738,15 @@ class VCloudNodeDriver(NodeDriver):
)
vdc = self._get_vdc(kwargs.get('ex_vdc', None))
+
# Instantiate VM and get identifier.
+ content_type = \
+ 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'
res = self.connection.request(
'%s/action/instantiateVAppTemplate' % get_url_path(vdc.id),
data=instantiate_xml.tostring(),
method='POST',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'}
+ headers={'Content-Type': content_type}
)
vapp_path = get_url_path(res.object.get('href'))
@@ -763,6 +770,7 @@ class VCloudNodeDriver(NodeDriver):
class HostingComConnection(VCloudConnection):
+
"""
vCloud connection subclass for Hosting.com
"""
@@ -779,6 +787,7 @@ class HostingComConnection(VCloudConnection):
class HostingComDriver(VCloudNodeDriver):
+
"""
vCloud node driver for Hosting.com
"""
@@ -786,6 +795,7 @@ class HostingComDriver(VCloudNodeDriver):
class TerremarkConnection(VCloudConnection):
+
"""
vCloud connection subclass for Terremark
"""
@@ -794,6 +804,7 @@ class TerremarkConnection(VCloudConnection):
class TerremarkDriver(VCloudNodeDriver):
+
"""
vCloud node driver for Terremark
"""
@@ -805,6 +816,7 @@ class TerremarkDriver(VCloudNodeDriver):
class VCloud_1_5_Connection(VCloudConnection):
+
def _get_auth_headers(self):
"""Compatibility for using v1.5 API under vCloud Director 5.1"""
return {
@@ -836,7 +848,8 @@ class VCloud_1_5_Connection(VCloudConnection):
self.org_name = body.get('org')
org_list_url = get_url_path(
next((link for link in body.findall(fixxpath(body, 'Link'))
- if link.get('type') == 'application/vnd.vmware.vcloud.orgList+xml')).get('href')
+ if link.get('type') ==
+ 'application/vnd.vmware.vcloud.orgList+xml')).get('href')
)
conn.request(method='GET', url=org_list_url,
@@ -844,7 +857,7 @@ class VCloud_1_5_Connection(VCloudConnection):
body = ET.XML(conn.getresponse().read())
self.driver.org = get_url_path(
next((org for org in body.findall(fixxpath(body, 'Org'))
- if org.get('name') == self.org_name)).get('href')
+ if org.get('name') == self.org_name)).get('href')
)
def add_default_headers(self, headers):
@@ -854,6 +867,7 @@ class VCloud_1_5_Connection(VCloudConnection):
class Instantiate_1_5_VAppXML(object):
+
def __init__(self, name, template, network, vm_network=None,
vm_fence=None):
self.name = name
@@ -925,7 +939,9 @@ class Instantiate_1_5_VAppXML(object):
class VCloud_1_5_NodeDriver(VCloudNodeDriver):
connectionCls = VCloud_1_5_Connection
- # Based on http://pubs.vmware.com/vcloud-api-1-5/api_prog/GUID-843BE3AD-5EF6-4442-B864-BCAE44A51867.html
+ # Based on
+ # http://pubs.vmware.com/vcloud-api-1-5/api_prog/
+ # GUID-843BE3AD-5EF6-4442-B864-BCAE44A51867.html
NODE_STATE_MAP = {'-1': NodeState.UNKNOWN,
'0': NodeState.PENDING,
'1': NodeState.PENDING,
@@ -940,17 +956,19 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
'10': NodeState.UNKNOWN}
def list_locations(self):
- return [NodeLocation(id=self.connection.host, name=self.connection.host, country="N/A", driver=self)]
+ return [NodeLocation(id=self.connection.host,
+ name=self.connection.host, country="N/A", driver=self)]
def ex_find_node(self, node_name, vdcs=None):
"""
- Searches for node across specified vDCs. This is more effective than querying all nodes to get a single
- instance.
+ Searches for node across specified vDCs. This is more effective than
+ querying all nodes to get a single instance.
:param node_name: The name of the node to search for
:type node_name: ``str``
- :param vdcs: None, vDC or a list of vDCs to search in. If None all vDCs will be searched.
+ :param vdcs: None, vDC or a list of vDCs to search in. If None all vDCs
+ will be searched.
:type vdcs: :class:`Vdc`
:return: node instance or None if not found
@@ -962,11 +980,17 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
vdcs = [vdcs]
for vdc in vdcs:
res = self.connection.request(get_url_path(vdc.id))
- entity_elems = res.object.findall(fixxpath(res.object, "ResourceEntities/ResourceEntity"))
+ xpath = fixxpath(res.object, "ResourceEntities/ResourceEntity")
+ entity_elems = res.object.findall(xpath)
for entity_elem in entity_elems:
- if entity_elem.get('type') == 'application/vnd.vmware.vcloud.vApp+xml' and entity_elem.get('name') == node_name:
- res = self.connection.request(get_url_path(entity_elem.get('href')),
- headers={'Content-Type': 'application/vnd.vmware.vcloud.vApp+xml'})
+ if entity_elem.get('type') == \
+ 'application/vnd.vmware.vcloud.vApp+xml' and \
+ entity_elem.get('name') == node_name:
+ path = get_url_path(entity_elem.get('href'))
+ headers = {'Content-Type':
+ 'application/vnd.vmware.vcloud.vApp+xml'}
+ res = self.connection.request(path,
+ headers=headers)
return self._to_node(res.object)
return None
@@ -1000,14 +1024,18 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
:rtype: :class:`Node`
"""
- deploy_xml = ET.Element('DeployVAppParams', {'powerOn': 'true',
- 'xmlns': 'http://www.vmware.com/vcloud/v1.5'})
- res = self.connection.request('%s/action/deploy' % get_url_path(node.id),
+ data = {'powerOn': 'true',
+ 'xmlns': 'http://www.vmware.com/vcloud/v1.5'}
+ deploy_xml = ET.Element('DeployVAppParams', data)
+ path = get_url_path(node.id)
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.deployVAppParams+xml'
+ }
+ res = self.connection.request('%s/action/deploy' % path,
data=ET.tostring(deploy_xml),
method='POST',
- headers={
- 'Content-Type': 'application/vnd.vmware.vcloud.deployVAppParams+xml'
- })
+ headers=headers)
self._wait_for_task_completion(res.object.get('href'))
res = self.connection.request(get_url_path(node.id))
return self._to_node(res.object)
@@ -1021,18 +1049,24 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
:rtype: :class:`Node`
"""
- undeploy_xml = ET.Element('UndeployVAppParams', {'xmlns': 'http://www.vmware.com/vcloud/v1.5'})
- undeploy_power_action_xml = ET.SubElement(undeploy_xml, 'UndeployPowerAction')
+ data = {'xmlns': 'http://www.vmware.com/vcloud/v1.5'}
+ undeploy_xml = ET.Element('UndeployVAppParams', data)
+ undeploy_power_action_xml = ET.SubElement(undeploy_xml,
+ 'UndeployPowerAction')
undeploy_power_action_xml.text = 'shutdown'
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.undeployVAppParams+xml'
+ }
+
try:
res = self.connection.request(
'%s/action/undeploy' % get_url_path(node.id),
data=ET.tostring(undeploy_xml),
method='POST',
- headers={
- 'Content-Type': 'application/vnd.vmware.vcloud.undeployVAppParams+xml'
- })
+ headers=headers)
+
self._wait_for_task_completion(res.object.get('href'))
except Exception:
undeploy_power_action_xml.text = 'powerOff'
@@ -1040,9 +1074,7 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
'%s/action/undeploy' % get_url_path(node.id),
data=ET.tostring(undeploy_xml),
method='POST',
- headers={
- 'Content-Type': 'application/vnd.vmware.vcloud.undeployVAppParams+xml'
- })
+ headers=headers)
self._wait_for_task_completion(res.object.get('href'))
res = self.connection.request(get_url_path(node.id))
@@ -1118,21 +1150,24 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
everyone_access_level = None
is_shared_elem = res.object.find(
fixxpath(res.object, "IsSharedToEveryone"))
- if is_shared_elem is not None and is_shared_elem.text == 'true':
+ if is_shared_elem is not None and is_shared_elem.text == 'true':
everyone_access_level = res.object.find(
fixxpath(res.object, "EveryoneAccessLevel")).text
# Parse all subjects
subjects = []
- for elem in res.object.findall(
- fixxpath(res.object, "AccessSettings/AccessSetting")):
+ xpath = fixxpath(res.object, "AccessSettings/AccessSetting")
+ for elem in res.object.findall(xpath):
access_level = elem.find(fixxpath(res.object, "AccessLevel")).text
subject_elem = elem.find(fixxpath(res.object, "Subject"))
- if subject_elem.get('type') == 'application/vnd.vmware.admin.group+xml':
+ if subject_elem.get('type') == \
+ 'application/vnd.vmware.admin.group+xml':
subj_type = 'group'
else:
subj_type = 'user'
- res = self.connection.request(get_url_path(subject_elem.get('href')))
+
+ path = get_url_path(subject_elem.get('href'))
+ res = self.connection.request(path)
name = res.object.get('name')
subject = Subject(type=subj_type,
name=name,
@@ -1155,7 +1190,7 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
:rtype: ``None``
"""
xml = ET.Element('ControlAccessParams',
- {'xmlns': 'http://www.vmware.com/vcloud/v1.5'})
+ {'xmlns': 'http://www.vmware.com/vcloud/v1.5'})
shared_to_everyone = ET.SubElement(xml, 'IsSharedToEveryone')
if control_access.everyone_access_level:
shared_to_everyone.text = 'true'
@@ -1172,7 +1207,8 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
if subject.id:
href = subject.id
else:
- res = self.ex_query(type=subject.type, filter='name==' + subject.name)
+ res = self.ex_query(type=subject.type, filter='name==' +
+ subject.name)
if not res:
raise LibcloudError('Specified subject "%s %s" not found '
% (subject.type, subject.name))
@@ -1180,12 +1216,13 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
ET.SubElement(setting, 'Subject', {'href': href})
ET.SubElement(setting, 'AccessLevel').text = subject.access_level
+ headers = {
+ 'Content-Type': 'application/vnd.vmware.vcloud.controlAccess+xml'
+ }
self.connection.request(
'%s/action/controlAccess' % get_url_path(node.id),
data=ET.tostring(xml),
- headers={
- 'Content-Type': 'application/vnd.vmware.vcloud.controlAccess+xml'
- },
+ headers=headers,
method='POST')
def ex_get_metadata(self, node):
@@ -1197,7 +1234,8 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
:rtype: dictionary mapping ``str`` to ``str``
"""
res = self.connection.request('%s/metadata' % (get_url_path(node.id)))
- metadata_entries = res.object.findall(fixxpath(res.object, 'MetadataEntry'))
+ xpath = fixxpath(res.object, 'MetadataEntry')
+ metadata_entries = res.object.findall(xpath)
res_dict = {}
for entry in metadata_entries:
@@ -1244,9 +1282,10 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
def ex_query(self, type, filter=None, page=1, page_size=100, sort_asc=None,
sort_desc=None):
"""
- Queries vCloud for specified type. See http://www.vmware.com/pdf/vcd_15_api_guide.pdf
- for details. Each element of the returned list is a dictionary with all
- attributes from the record.
+ Queries vCloud for specified type. See
+ http://www.vmware.com/pdf/vcd_15_api_guide.pdf for details. Each
+ element of the returned list is a dictionary with all attributes from
+ the record.
:param type: type to query (r.g. user, group, vApp etc.)
:type type: ``str``
@@ -1299,55 +1338,70 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
def create_node(self, **kwargs):
"""Creates and returns node. If the source image is:
- vApp template - a new vApp is instantiated from template
- - existing vApp - a new vApp is cloned from the source vApp. Can not clone more vApps is parallel otherwise
+ - existing vApp - a new vApp is cloned from the source vApp. Can
+ not clone more vApps is parallel otherwise
resource busy error is raised.
@inherits: :class:`NodeDriver.create_node`
- :keyword image: OS Image to boot on node. (required). Can be a NodeImage or existing Node that will be
- cloned.
+ :keyword image: OS Image to boot on node. (required). Can be a
+ NodeImage or existing Node that will be cloned.
:type image: :class:`NodeImage` or :class:`Node`
- :keyword ex_network: Organisation's network name for attaching vApp VMs to.
+ :keyword ex_network: Organisation's network name for attaching vApp
+ VMs to.
:type ex_network: ``str``
- :keyword ex_vdc: Name of organisation's virtual data center where vApp VMs will be deployed.
+ :keyword ex_vdc: Name of organisation's virtual data center where
+ vApp VMs will be deployed.
:type ex_vdc: ``str``
- :keyword ex_vm_names: list of names to be used as a VM and computer name. The name must be max. 15 characters
+ :keyword ex_vm_names: list of names to be used as a VM and computer
+ name. The name must be max. 15 characters
long and follow the host name requirements.
:type ex_vm_names: ``list`` of ``str``
- :keyword ex_vm_cpu: number of virtual CPUs/cores to allocate for each vApp VM.
+ :keyword ex_vm_cpu: number of virtual CPUs/cores to allocate for
+ each vApp VM.
:type ex_vm_cpu: ``int``
- :keyword ex_vm_memory: amount of memory in MB to allocate for each vApp VM.
+ :keyword ex_vm_memory: amount of memory in MB to allocate for each
+ vApp VM.
:type ex_vm_memory: ``int``
- :keyword ex_vm_script: full path to file containing guest customisation script for each vApp VM.
- Useful for creating users & pushing out public SSH keys etc.
+ :keyword ex_vm_script: full path to file containing guest
+ customisation script for each vApp VM.
+ Useful for creating users & pushing out
+ public SSH keys etc.
:type ex_vm_script: ``str``
- :keyword ex_vm_network: Override default vApp VM network name. Useful for when you've imported an OVF
+ :keyword ex_vm_network: Override default vApp VM network name.
+ Useful for when you've imported an OVF
originating from outside of the vCloud.
:type ex_vm_network: ``str``
- :keyword ex_vm_fence: Fence mode for connecting the vApp VM network (ex_vm_network) to the parent
+ :keyword ex_vm_fence: Fence mode for connecting the vApp VM network
+ (ex_vm_network) to the parent
organisation network (ex_network).
:type ex_vm_fence: ``str``
- :keyword ex_vm_ipmode: IP address allocation mode for all vApp VM network connections.
+ :keyword ex_vm_ipmode: IP address allocation mode for all vApp VM
+ network connections.
:type ex_vm_ipmode: ``str``
- :keyword ex_deploy: set to False if the node shouldn't be deployed (started) after creation
+ :keyword ex_deploy: set to False if the node shouldn't be deployed
+ (started) after creation
:type ex_deploy: ``bool``
- :keyword ex_clone_timeout: timeout in seconds for clone/instantiate VM operation.
- Cloning might be a time consuming operation especially
- when linked clones are disabled or VMs are created
- on different datastores.
- Overrides the default task completion value.
+ :keyword ex_clone_timeout: timeout in seconds for clone/instantiate
+ VM operation.
+ Cloning might be a time consuming
+ operation especially when linked clones
+ are disabled or VMs are created on
+ different datastores.
+ Overrides the default task completion
+ value.
:type ex_clone_timeout: ``int``
"""
name = kwargs['name']
@@ -1402,7 +1456,8 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
# Power on the VM.
if ex_deploy:
- # Retry 3 times: when instantiating large number of VMs at the same time some may fail on resource allocation
+ # Retry 3 times: when instantiating large number of VMs at the same
+ # time some may fail on resource allocation
retry = 3
while True:
try:
@@ -1432,11 +1487,15 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
)
# Instantiate VM and get identifier.
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'
+ }
res = self.connection.request(
'%s/action/instantiateVAppTemplate' % get_url_path(vdc.id),
data=instantiate_xml.tostring(),
method='POST',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'}
+ headers=headers
)
vapp_name = res.object.get('name')
vapp_href = res.object.get('href')
@@ -1457,16 +1516,20 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
'Description').text = 'Clone of ' + sourceNode.name
ET.SubElement(clone_xml, 'Source', {'href': sourceNode.id})
+ headers = {
+ 'Content-Type': 'application/vnd.vmware.vcloud.cloneVAppParams+xml'
+ }
res = self.connection.request(
'%s/action/cloneVApp' % get_url_path(vdc.id),
data=ET.tostring(clone_xml),
method='POST',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.cloneVAppParams+xml'}
+ headers=headers
)
vapp_name = res.object.get('name')
vapp_href = res.object.get('href')
- task_href = res.object.find(fixxpath(res.object, "Tasks/Task")).get('href')
+ task_href = res.object.find(
+ fixxpath(res.object, "Tasks/Task")).get('href')
self._wait_for_task_completion(task_href, clone_timeout)
res = self.connection.request(get_url_path(vapp_href))
@@ -1480,12 +1543,18 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
'ovf:required': 'false',
'xmlns': "http://www.vmware.com/vcloud/v1.5",
'xmlns:ovf': 'http://schemas.dmtf.org/ovf/envelope/1'})
- ET.SubElement(network_xml, "ovf:Info").text = 'Specifies the available VM network connections'
+ ET.SubElement(network_xml, "ovf:Info").text = \
+ 'Specifies the available VM network connections'
+
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.networkConnectionSection+xml'
+ }
res = self.connection.request(
'%s/networkConnectionSection' % get_url_path(vm.get('href')),
data=ET.tostring(network_xml),
method='PUT',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.networkConnectionSection+xml'}
+ headers=headers
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1499,12 +1568,15 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
network_conn_xml.remove(
network_conn_xml.find(fixxpath(network_xml, 'MACAddress')))
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.networkConnectionSection+xml'
+ }
res = self.connection.request(
'%s/networkConnectionSection' % get_url_path(vm.get('href')),
data=ET.tostring(network_xml),
method='PUT',
- headers={
- 'Content-Type': 'application/vnd.vmware.vcloud.networkConnectionSection+xml'}
+ headers=headers
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1512,17 +1584,21 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
def ex_set_vm_cpu(self, vapp_or_vm_id, vm_cpu):
"""
- Sets the number of virtual CPUs for the specified VM or VMs under the vApp. If the vapp_or_vm_id param
- represents a link to an vApp all VMs that are attached to this vApp will be modified.
+ Sets the number of virtual CPUs for the specified VM or VMs under
+ the vApp. If the vapp_or_vm_id param represents a link to an vApp
+ all VMs that are attached to this vApp will be modified.
- Please ensure that hot-adding a virtual CPU is enabled for the powered on virtual machines.
- Otherwise use this method on undeployed vApp.
+ Please ensure that hot-adding a virtual CPU is enabled for the
+ powered on virtual machines. Otherwise use this method on undeployed
+ vApp.
- :keyword vapp_or_vm_id: vApp or VM ID that will be modified. If a vApp ID is used here all attached VMs
+ :keyword vapp_or_vm_id: vApp or VM ID that will be modified. If
+ a vApp ID is used here all attached VMs
will be modified
:type vapp_or_vm_id: ``str``
- :keyword vm_cpu: number of virtual CPUs/cores to allocate for specified VMs
+ :keyword vm_cpu: number of virtual CPUs/cores to allocate for
+ specified VMs
:type vm_cpu: ``int``
:rtype: ``None``
@@ -1532,18 +1608,21 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
def ex_set_vm_memory(self, vapp_or_vm_id, vm_memory):
"""
- Sets the virtual memory in MB to allocate for the specified VM or VMs under the vApp.
- If the vapp_or_vm_id param represents a link to an vApp all VMs that are attached to
- this vApp will be modified.
+ Sets the virtual memory in MB to allocate for the specified VM or
+ VMs under the vApp. If the vapp_or_vm_id param represents a link
+ to an vApp all VMs that are attached to this vApp will be modified.
- Please ensure that hot-change of virtual memory is enabled for the powered on virtual machines.
- Otherwise use this method on undeployed vApp.
+ Please ensure that hot-change of virtual memory is enabled for the
+ powered on virtual machines. Otherwise use this method on undeployed
+ vApp.
- :keyword vapp_or_vm_id: vApp or VM ID that will be modified. If a vApp ID is used here all attached VMs
+ :keyword vapp_or_vm_id: vApp or VM ID that will be modified. If
+ a vApp ID is used here all attached VMs
will be modified
:type vapp_or_vm_id: ``str``
- :keyword vm_memory: virtual memory in MB to allocate for the specified VM or VMs
+ :keyword vm_memory: virtual memory in MB to allocate for the
+ specified VM or VMs
:type vm_memory: ``int``
:rtype: ``None``
@@ -1553,14 +1632,17 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
def ex_add_vm_disk(self, vapp_or_vm_id, vm_disk_size):
"""
- Adds a virtual disk to the specified VM or VMs under the vApp. If the vapp_or_vm_id param
- represents a link to an vApp all VMs that are attached to this vApp will be modified.
+ Adds a virtual disk to the specified VM or VMs under the vApp. If the
+ vapp_or_vm_id param represents a link to an vApp all VMs that are
+ attached to this vApp will be modified.
- :keyword vapp_or_vm_id: vApp or VM ID that will be modified. If a vApp ID is used here all attached VMs
+ :keyword vapp_or_vm_id: vApp or VM ID that will be modified. If a
+ vApp ID is used here all attached VMs
will be modified
:type vapp_or_vm_id: ``str``
- :keyword vm_disk_size: the disk capacity in GB that will be added to the specified VM or VMs
+ :keyword vm_disk_size: the disk capacity in GB that will be added
+ to the specified VM or VMs
:type vm_disk_size: ``int``
:rtype: ``None``
@@ -1572,12 +1654,17 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
def _validate_vm_names(names):
if names is None:
return
- hname_re = re.compile('^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9]*)[\-])*([A-Za-z]|[A-Za-z][A-Za-z0-9]*[A-Za-z0-9])$')
+ hname_re = re.compile(
+ '^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9]*)[\-])*([A-Za-z]|[A-Za-z][A-Za-z0-9]*[A-Za-z0-9])$') # NOQA
for name in names:
if len(name) > 15:
- raise ValueError('The VM name "' + name + '" is too long for the computer name (max 15 chars allowed).')
+ raise ValueError(
+ 'The VM name "' + name + '" is too long for the computer '
+ 'name (max 15 chars allowed).')
if not hname_re.match(name):
- raise ValueError('The VM name "' + name + '" can not be used. "' + name + '" is not a valid computer name for the VM.')
+ raise ValueError('The VM name "' + name + '" can not be '
+ 'used. "' + name + '" is not a valid '
+ 'computer name for the VM.')
@staticmethod
def _validate_vm_memory(vm_memory):
@@ -1631,9 +1718,13 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
if vm_ipmode is None:
return
elif vm_ipmode == 'MANUAL':
- raise NotImplementedError('MANUAL IP mode: The interface for supplying IPAddress does not exist yet')
+ raise NotImplementedError(
+ 'MANUAL IP mode: The interface for supplying '
+ 'IPAddress does not exist yet')
elif vm_ipmode not in IP_MODE_VALS_1_5:
- raise ValueError('%s is not a valid IP address allocation mode value' % vm_ipmode)
+ raise ValueError(
+ '%s is not a valid IP address allocation mode value'
+ % vm_ipmode)
def _change_vm_names(self, vapp_or_vm_id, vm_names):
if vm_names is None:
@@ -1649,16 +1740,22 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
'%s/guestCustomizationSection' % get_url_path(vm.get('href')))
# Update GuestCustomizationSection
- res.object.find(fixxpath(res.object, 'ComputerName')).text = vm_names[i]
+ res.object.find(
+ fixxpath(res.object, 'ComputerName')).text = vm_names[i]
# Remove AdminPassword from customization section
admin_pass = res.object.find(fixxpath(res.object, 'AdminPassword'))
if admin_pass is not None:
res.object.remove(admin_pass)
+
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.guestCustomizationSection+xml'
+ }
res = self.connection.request(
'%s/guestCustomizationSection' % get_url_path(vm.get('href')),
data=ET.tostring(res.object),
method='PUT',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.guestCustomizationSection+xml'}
+ headers=headers
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1670,7 +1767,8 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
get_url_path(vm.get('href')),
data=ET.tostring(req_xml),
method='PUT',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.vm+xml'}
+ headers={
+ 'Content-Type': 'application/vnd.vmware.vcloud.vm+xml'}
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1685,14 +1783,18 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
'%s/virtualHardwareSection/cpu' % get_url_path(vm.get('href')))
# Update VirtualQuantity field
- res.object.find(
- '{http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData}VirtualQuantity'
- ).text = str(vm_cpu)
+ xpath = ('{http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/'
+ 'CIM_ResourceAllocationSettingData}VirtualQuantity')
+ res.object.find(xpath).text = str(vm_cpu)
+
+ headers = {
+ 'Content-Type': 'application/vnd.vmware.vcloud.rasdItem+xml'
+ }
res = self.connection.request(
'%s/virtualHardwareSection/cpu' % get_url_path(vm.get('href')),
data=ET.tostring(res.object),
method='PUT',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.rasdItem+xml'}
+ headers=headers
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1703,17 +1805,24 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
vms = self._get_vm_elements(vapp_or_vm_id)
for vm in vms:
# Get virtualHardwareSection/memory section
- res = self.connection.request('%s/virtualHardwareSection/memory' % get_url_path(vm.get('href')))
+ res = self.connection.request(
+ '%s/virtualHardwareSection/memory' %
+ get_url_path(vm.get('href')))
# Update VirtualQuantity field
- res.object.find(
- '{http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData}VirtualQuantity'
- ).text = str(vm_memory)
+ xpath = ('{http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/'
+ 'CIM_ResourceAllocationSettingData}VirtualQuantity')
+ res.object.find(xpath).text = str(vm_memory)
+
+ headers = {
+ 'Content-Type': 'application/vnd.vmware.vcloud.rasdItem+xml'
+ }
res = self.connection.request(
- '%s/virtualHardwareSection/memory' % get_url_path(vm.get('href')),
+ '%s/virtualHardwareSection/memory' % get_url_path(
+ vm.get('href')),
data=ET.tostring(res.object),
method='PUT',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.rasdItem+xml'}
+ headers=headers
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1721,12 +1830,15 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
if vm_disk is None:
return
- rasd_ns = '{http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData}'
+ rasd_ns = ('{http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/'
+ 'CIM_ResourceAllocationSettingData}')
vms = self._get_vm_elements(vapp_or_vm_id)
for vm in vms:
# Get virtualHardwareSection/disks section
- res = self.connection.request('%s/virtualHardwareSection/disks' % get_url_path(vm.get('href')))
+ res = self.connection.request(
+ '%s/virtualHardwareSection/disks' %
+ get_url_path(vm.get('href')))
existing_ids = []
new_disk = None
@@ -1735,7 +1847,8 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
for elem in item:
if elem.tag == '%sInstanceID' % rasd_ns:
existing_ids.append(int(elem.text))
- if elem.tag in ['%sAddressOnParent' % rasd_ns, '%sParent' % rasd_ns]:
+ if elem.tag in ['%sAddressOnParent' % rasd_ns,
+ '%sParent' % rasd_ns]:
item.remove(elem)
if item.find('%sHostResource' % rasd_ns) is not None:
new_disk = item
@@ -1743,15 +1856,22 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
new_disk = copy.deepcopy(new_disk)
disk_id = max(existing_ids) + 1
new_disk.find('%sInstanceID' % rasd_ns).text = str(disk_id)
- new_disk.find('%sElementName' % rasd_ns).text = 'Hard Disk ' + str(disk_id)
- new_disk.find('%sHostResource' % rasd_ns).set(fixxpath(new_disk, 'capacity'), str(int(vm_disk) * 1024))
+ new_disk.find('%sElementName' %
+ rasd_ns).text = 'Hard Disk ' + str(disk_id)
+ new_disk.find('%sHostResource' % rasd_ns).set(
+ fixxpath(new_disk, 'capacity'), str(int(vm_disk) * 1024))
res.object.append(new_disk)
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.rasditemslist+xml'
+ }
res = self.connection.request(
- '%s/virtualHardwareSection/disks' % get_url_path(vm.get('href')),
+ '%s/virtualHardwareSection/disks' % get_url_path(
+ vm.get('href')),
data=ET.tostring(res.object),
method='PUT',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.rasditemslist+xml'}
+ headers=headers
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1765,8 +1885,10 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
except:
return
- # ElementTree escapes script characters automatically. Escape requirements:
- # http://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/types/GuestCustomizationSectionType.html
+ # ElementTree escapes script characters automatically. Escape
+ # requirements:
+ # http://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/types/
+ # GuestCustomizationSectionType.html
for vm in vms:
# Get GuestCustomizationSection
res = self.connection.request(
@@ -1777,26 +1899,33 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
res.object.find(
fixxpath(res.object, 'CustomizationScript')).text = script
except:
- # CustomizationScript section does not exist, insert it just before ComputerName
+ # CustomizationScript section does not exist, insert it just
+ # before ComputerName
for i, e in enumerate(res.object):
- if e.tag == '{http://www.vmware.com/vcloud/v1.5}ComputerName':
+ if e.tag == \
+ '{http://www.vmware.com/vcloud/v1.5}ComputerName':
break
e = ET.Element(
'{http://www.vmware.com/vcloud/v1.5}CustomizationScript')
e.text = script
res.object.insert(i, e)
- # Remove AdminPassword from customization section due to an API quirk
+ # Remove AdminPassword from customization section due to an API
+ # quirk
admin_pass = res.object.find(fixxpath(res.object, 'AdminPassword'))
if admin_pass is not None:
res.object.remove(admin_pass)
# Update VM's GuestCustomizationSection
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.guestCustomizationSection+xml'
+ }
res = self.connection.request(
'%s/guestCustomizationSection' % get_url_path(vm.get('href')),
data=ET.tostring(res.object),
method='PUT',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.guestCustomizationSection+xml'}
+ headers=headers
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1814,11 +1943,16 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
for c in net_conns:
c.find(fixxpath(c, 'IpAddressAllocationMode')).text = vm_ipmode
+ headers = {
+ 'Content-Type':
+ 'application/vnd.vmware.vcloud.networkConnectionSection+xml'
+ }
+
res = self.connection.request(
'%s/networkConnectionSection' % get_url_path(vm.get('href')),
data=ET.tostring(res.object),
method='PUT',
- headers={'Content-Type': 'application/vnd.vmware.vcloud.networkConnectionSection+xml'}
+ headers=headers
)
self._wait_for_task_completion(res.object.get('href'))
@@ -1829,8 +1963,9 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
res = self.connection.request(self.org)
links = res.object.findall(fixxpath(res.object, 'Link'))
for l in links:
- if l.attrib['type'] == 'application/vnd.vmware.vcloud.orgNetwork+xml'\
- and l.attrib['name'] == network_name:
+ if l.attrib['type'] == \
+ 'application/vnd.vmware.vcloud.orgNetwork+xml' \
+ and l.attrib['name'] == network_name:
network_href = l.attrib['href']
if network_href is None:
@@ -1859,7 +1994,10 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
for vm_elem in node_elm.findall(fixxpath(node_elm, 'Children/Vm')):
public_ips = []
private_ips = []
- for connection in vm_elem.findall(fixxpath(vm_elem, 'NetworkConnectionSection/NetworkConnection')):
+
+ xpath = fixxpath(vm_elem,
+ 'NetworkConnectionSection/NetworkConnection')
+ for connection in vm_elem.findall(xpath):
ip = connection.find(fixxpath(connection, "IpAddress"))
if ip is not None:
private_ips.append(ip.text)
@@ -1869,9 +2007,13 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
public_ips.append(external_ip.text)
elif ip is not None:
public_ips.append(ip.text)
- os_type_elem = vm_elem.find('{http://schemas.dmtf.org/ovf/envelope/1}OperatingSystemSection')
- if os_type_elem:
- os_type = os_type_elem.get('{http://www.vmware.com/schema/ovf}osType')
+
+ xpath = ('{http://schemas.dmtf.org/ovf/envelope/1}'
+ 'OperatingSystemSection')
+ os_type_elem = vm_elem.find(xpath)
+ if os_type_elem is not None:
+ os_type = os_type_elem.get(
+ '{http://www.vmware.com/schema/ovf}osType')
else:
os_type = None
vm = {
@@ -1892,8 +2034,10 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
private_ips.extend(vm['private_ips'])
# Find vDC
- vdc_id = next(link.get('href') for link in node_elm.findall(fixxpath(node_elm, 'Link'))
- if link.get('type') == 'application/vnd.vmware.vcloud.vdc+xml')
+ vdc_id = next(link.get('href') for link
+ in node_elm.findall(fixxpath(node_elm, 'Link'))
+ if link.get('type') ==
+ 'application/vnd.vmware.vcloud.vdc+xml')
vdc = next(vdc for vdc in self.vdcs if vdc.id == vdc_id)
node = Node(id=node_elm.get('href'),
@@ -1915,14 +2059,18 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
units = capacity_elm.findtext(fixxpath(capacity_elm, 'Units'))
return Capacity(limit, used, units)
- cpu = get_capacity_values(vdc_elm.find(fixxpath(vdc_elm, 'ComputeCapacity/Cpu')))
- memory = get_capacity_values(vdc_elm.find(fixxpath(vdc_elm, 'ComputeCapacity/Memory')))
- storage = get_capacity_values(vdc_elm.find(fixxpath(vdc_elm, 'StorageCapacity')))
+ cpu = get_capacity_values(
+ vdc_elm.find(fixxpath(vdc_elm, 'ComputeCapacity/Cpu')))
+ memory = get_capacity_values(
+ vdc_elm.find(fixxpath(vdc_elm, 'ComputeCapacity/Memory')))
+ storage = get_capacity_values(
+ vdc_elm.find(fixxpath(vdc_elm, 'StorageCapacity')))
return Vdc(id=vdc_elm.get('href'),
name=vdc_elm.get('name'),
driver=self,
- allocation_model=vdc_elm.findtext(fixxpath(vdc_elm, 'AllocationModel')),
+ allocation_model=vdc_elm.findtext(
+ fixxpath(vdc_elm, 'AllocationModel')),
cpu=cpu,
memory=memory,
storage=storage)
@@ -1935,6 +2083,7 @@ class VCloud_5_1_NodeDriver(VCloud_1_5_NodeDriver):
if vm_memory is None:
return None
elif (vm_memory % 4) != 0:
- #The vcd 5.1 virtual machine memory size must be a multiple of 4 MB
+ # The vcd 5.1 virtual machine memory size must be a multiple of 4
+ # MB
raise ValueError(
'%s is not a valid vApp VM memory value' % (vm_memory))
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/compute/drivers/vpsnet.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vpsnet.py b/libcloud/compute/drivers/vpsnet.py
index 607113e..ec0dd5d 100644
--- a/libcloud/compute/drivers/vpsnet.py
+++ b/libcloud/compute/drivers/vpsnet.py
@@ -136,12 +136,11 @@ class VPSNetNodeDriver(NodeDriver):
"""
headers = {'Content-Type': 'application/json'}
request = {'virtual_machine':
- {'label': name,
- 'fqdn': kwargs.get('ex_fqdn', ''),
- 'system_template_id': image.id,
- 'backups_enabled': kwargs.get('ex_backups_enabled',
- 0),
- 'slices_required': size.id}}
+ {'label': name,
+ 'fqdn': kwargs.get('ex_fqdn', ''),
+ 'system_template_id': image.id,
+ 'backups_enabled': kwargs.get('ex_backups_enabled', 0),
+ 'slices_required': size.id}}
res = self.connection.request('/virtual_machines.%s' % (API_VERSION,),
data=json.dumps(request),
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/compute/providers.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/providers.py b/libcloud/compute/providers.py
index 26bc284..5376081 100644
--- a/libcloud/compute/providers.py
+++ b/libcloud/compute/providers.py
@@ -28,115 +28,115 @@ __all__ = [
DRIVERS = {
Provider.DUMMY:
- ('libcloud.compute.drivers.dummy', 'DummyNodeDriver'),
+ ('libcloud.compute.drivers.dummy', 'DummyNodeDriver'),
Provider.EC2_US_EAST:
- ('libcloud.compute.drivers.ec2', 'EC2NodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EC2NodeDriver'),
Provider.EC2_EU_WEST:
- ('libcloud.compute.drivers.ec2', 'EC2EUNodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EC2EUNodeDriver'),
Provider.EC2_US_WEST:
- ('libcloud.compute.drivers.ec2', 'EC2USWestNodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EC2USWestNodeDriver'),
Provider.EC2_US_WEST_OREGON:
- ('libcloud.compute.drivers.ec2', 'EC2USWestOregonNodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EC2USWestOregonNodeDriver'),
Provider.EC2_AP_SOUTHEAST:
- ('libcloud.compute.drivers.ec2', 'EC2APSENodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EC2APSENodeDriver'),
Provider.EC2_AP_NORTHEAST:
- ('libcloud.compute.drivers.ec2', 'EC2APNENodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EC2APNENodeDriver'),
Provider.EC2_SA_EAST:
- ('libcloud.compute.drivers.ec2', 'EC2SAEastNodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EC2SAEastNodeDriver'),
Provider.EC2_AP_SOUTHEAST2:
- ('libcloud.compute.drivers.ec2', 'EC2APSESydneyNodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EC2APSESydneyNodeDriver'),
Provider.ECP:
- ('libcloud.compute.drivers.ecp', 'ECPNodeDriver'),
+ ('libcloud.compute.drivers.ecp', 'ECPNodeDriver'),
Provider.ELASTICHOSTS:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsNodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsNodeDriver'),
Provider.ELASTICHOSTS_UK1:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUK1NodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUK1NodeDriver'),
Provider.ELASTICHOSTS_UK2:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUK2NodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUK2NodeDriver'),
Provider.ELASTICHOSTS_US1:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS1NodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS1NodeDriver'),
Provider.ELASTICHOSTS_US2:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS2NodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS2NodeDriver'),
Provider.ELASTICHOSTS_US3:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS3NodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsUS3NodeDriver'),
Provider.ELASTICHOSTS_CA1:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsCA1NodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsCA1NodeDriver'),
Provider.ELASTICHOSTS_AU1:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsAU1NodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsAU1NodeDriver'),
Provider.ELASTICHOSTS_CN1:
- ('libcloud.compute.drivers.elastichosts', 'ElasticHostsCN1NodeDriver'),
+ ('libcloud.compute.drivers.elastichosts', 'ElasticHostsCN1NodeDriver'),
Provider.SKALICLOUD:
- ('libcloud.compute.drivers.skalicloud', 'SkaliCloudNodeDriver'),
+ ('libcloud.compute.drivers.skalicloud', 'SkaliCloudNodeDriver'),
Provider.SERVERLOVE:
- ('libcloud.compute.drivers.serverlove', 'ServerLoveNodeDriver'),
+ ('libcloud.compute.drivers.serverlove', 'ServerLoveNodeDriver'),
Provider.CLOUDSIGMA:
- ('libcloud.compute.drivers.cloudsigma', 'CloudSigmaZrhNodeDriver'),
+ ('libcloud.compute.drivers.cloudsigma', 'CloudSigmaZrhNodeDriver'),
Provider.CLOUDSIGMA_US:
- ('libcloud.compute.drivers.cloudsigma', 'CloudSigmaLvsNodeDriver'),
+ ('libcloud.compute.drivers.cloudsigma', 'CloudSigmaLvsNodeDriver'),
Provider.GCE:
- ('libcloud.compute.drivers.gce', 'GCENodeDriver'),
+ ('libcloud.compute.drivers.gce', 'GCENodeDriver'),
Provider.GOGRID:
- ('libcloud.compute.drivers.gogrid', 'GoGridNodeDriver'),
+ ('libcloud.compute.drivers.gogrid', 'GoGridNodeDriver'),
Provider.RACKSPACE:
- ('libcloud.compute.drivers.rackspace', 'RackspaceNodeDriver'),
+ ('libcloud.compute.drivers.rackspace', 'RackspaceNodeDriver'),
Provider.RACKSPACE_FIRST_GEN:
- ('libcloud.compute.drivers.rackspace', 'RackspaceFirstGenNodeDriver'),
+ ('libcloud.compute.drivers.rackspace', 'RackspaceFirstGenNodeDriver'),
Provider.SLICEHOST:
- ('libcloud.compute.drivers.slicehost', 'SlicehostNodeDriver'),
+ ('libcloud.compute.drivers.slicehost', 'SlicehostNodeDriver'),
Provider.VPSNET:
- ('libcloud.compute.drivers.vpsnet', 'VPSNetNodeDriver'),
+ ('libcloud.compute.drivers.vpsnet', 'VPSNetNodeDriver'),
Provider.LINODE:
- ('libcloud.compute.drivers.linode', 'LinodeNodeDriver'),
+ ('libcloud.compute.drivers.linode', 'LinodeNodeDriver'),
Provider.RIMUHOSTING:
- ('libcloud.compute.drivers.rimuhosting', 'RimuHostingNodeDriver'),
+ ('libcloud.compute.drivers.rimuhosting', 'RimuHostingNodeDriver'),
Provider.VOXEL:
- ('libcloud.compute.drivers.voxel', 'VoxelNodeDriver'),
+ ('libcloud.compute.drivers.voxel', 'VoxelNodeDriver'),
Provider.SOFTLAYER:
- ('libcloud.compute.drivers.softlayer', 'SoftLayerNodeDriver'),
+ ('libcloud.compute.drivers.softlayer', 'SoftLayerNodeDriver'),
Provider.EUCALYPTUS:
- ('libcloud.compute.drivers.ec2', 'EucNodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'EucNodeDriver'),
Provider.IBM:
- ('libcloud.compute.drivers.ibm_sce', 'IBMNodeDriver'),
+ ('libcloud.compute.drivers.ibm_sce', 'IBMNodeDriver'),
Provider.OPENNEBULA:
- ('libcloud.compute.drivers.opennebula', 'OpenNebulaNodeDriver'),
+ ('libcloud.compute.drivers.opennebula', 'OpenNebulaNodeDriver'),
Provider.DREAMHOST:
- ('libcloud.compute.drivers.dreamhost', 'DreamhostNodeDriver'),
+ ('libcloud.compute.drivers.dreamhost', 'DreamhostNodeDriver'),
Provider.BRIGHTBOX:
- ('libcloud.compute.drivers.brightbox', 'BrightboxNodeDriver'),
+ ('libcloud.compute.drivers.brightbox', 'BrightboxNodeDriver'),
Provider.NIMBUS:
- ('libcloud.compute.drivers.ec2', 'NimbusNodeDriver'),
+ ('libcloud.compute.drivers.ec2', 'NimbusNodeDriver'),
Provider.BLUEBOX:
- ('libcloud.compute.drivers.bluebox', 'BlueboxNodeDriver'),
+ ('libcloud.compute.drivers.bluebox', 'BlueboxNodeDriver'),
Provider.GANDI:
- ('libcloud.compute.drivers.gandi', 'GandiNodeDriver'),
+ ('libcloud.compute.drivers.gandi', 'GandiNodeDriver'),
Provider.OPSOURCE:
- ('libcloud.compute.drivers.opsource', 'OpsourceNodeDriver'),
+ ('libcloud.compute.drivers.opsource', 'OpsourceNodeDriver'),
Provider.OPENSTACK:
- ('libcloud.compute.drivers.openstack', 'OpenStackNodeDriver'),
+ ('libcloud.compute.drivers.openstack', 'OpenStackNodeDriver'),
Provider.NINEFOLD:
- ('libcloud.compute.drivers.ninefold', 'NinefoldNodeDriver'),
+ ('libcloud.compute.drivers.ninefold', 'NinefoldNodeDriver'),
Provider.VCLOUD:
- ('libcloud.compute.drivers.vcloud', 'VCloudNodeDriver'),
+ ('libcloud.compute.drivers.vcloud', 'VCloudNodeDriver'),
Provider.TERREMARK:
- ('libcloud.compute.drivers.vcloud', 'TerremarkDriver'),
+ ('libcloud.compute.drivers.vcloud', 'TerremarkDriver'),
Provider.CLOUDSTACK:
- ('libcloud.compute.drivers.cloudstack', 'CloudStackNodeDriver'),
+ ('libcloud.compute.drivers.cloudstack', 'CloudStackNodeDriver'),
Provider.LIBVIRT:
- ('libcloud.compute.drivers.libvirt_driver', 'LibvirtNodeDriver'),
+ ('libcloud.compute.drivers.libvirt_driver', 'LibvirtNodeDriver'),
Provider.JOYENT:
- ('libcloud.compute.drivers.joyent', 'JoyentNodeDriver'),
+ ('libcloud.compute.drivers.joyent', 'JoyentNodeDriver'),
Provider.VCL:
- ('libcloud.compute.drivers.vcl', 'VCLNodeDriver'),
+ ('libcloud.compute.drivers.vcl', 'VCLNodeDriver'),
Provider.KTUCLOUD:
- ('libcloud.compute.drivers.ktucloud', 'KTUCloudNodeDriver'),
+ ('libcloud.compute.drivers.ktucloud', 'KTUCloudNodeDriver'),
Provider.HOSTVIRTUAL:
- ('libcloud.compute.drivers.hostvirtual', 'HostVirtualNodeDriver'),
+ ('libcloud.compute.drivers.hostvirtual', 'HostVirtualNodeDriver'),
Provider.ABIQUO:
- ('libcloud.compute.drivers.abiquo', 'AbiquoNodeDriver'),
+ ('libcloud.compute.drivers.abiquo', 'AbiquoNodeDriver'),
Provider.DIGITAL_OCEAN:
- ('libcloud.compute.drivers.digitalocean', 'DigitalOceanNodeDriver'),
+ ('libcloud.compute.drivers.digitalocean', 'DigitalOceanNodeDriver'),
Provider.NEPHOSCALE:
- ('libcloud.compute.drivers.nephoscale', 'NephoscaleNodeDriver')
+ ('libcloud.compute.drivers.nephoscale', 'NephoscaleNodeDriver')
}
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/dns/drivers/zerigo.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/zerigo.py b/libcloud/dns/drivers/zerigo.py
index 85a2cee..db2ef07 100644
--- a/libcloud/dns/drivers/zerigo.py
+++ b/libcloud/dns/drivers/zerigo.py
@@ -440,8 +440,8 @@ class ZerigoDNSDriver(DNSDriver):
last_key = None
while not exhausted:
- items, last_key, exhausted = self._get_data(
- rtype, last_key, **kwargs)
+ items, last_key, exhausted = self._get_data(rtype, last_key,
+ **kwargs)
for item in items:
yield item
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/dns/providers.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/providers.py b/libcloud/dns/providers.py
index e3a0f82..53aa724 100644
--- a/libcloud/dns/providers.py
+++ b/libcloud/dns/providers.py
@@ -19,30 +19,31 @@ from libcloud.dns.types import Provider
DRIVERS = {
Provider.DUMMY:
- ('libcloud.dns.drivers.dummy', 'DummyDNSDriver'),
+ ('libcloud.dns.drivers.dummy', 'DummyDNSDriver'),
Provider.LINODE:
- ('libcloud.dns.drivers.linode', 'LinodeDNSDriver'),
+ ('libcloud.dns.drivers.linode', 'LinodeDNSDriver'),
Provider.ZERIGO:
- ('libcloud.dns.drivers.zerigo', 'ZerigoDNSDriver'),
+ ('libcloud.dns.drivers.zerigo', 'ZerigoDNSDriver'),
Provider.RACKSPACE:
- ('libcloud.dns.drivers.rackspace', 'RackspaceDNSDriver'),
+ ('libcloud.dns.drivers.rackspace', 'RackspaceDNSDriver'),
Provider.HOSTVIRTUAL:
- ('libcloud.dns.drivers.hostvirtual', 'HostVirtualDNSDriver'),
+ ('libcloud.dns.drivers.hostvirtual', 'HostVirtualDNSDriver'),
Provider.ROUTE53:
- ('libcloud.dns.drivers.route53', 'Route53DNSDriver'),
+ ('libcloud.dns.drivers.route53', 'Route53DNSDriver'),
Provider.GANDI:
- ('libcloud.dns.drivers.gandi', 'GandiDNSDriver'),
+ ('libcloud.dns.drivers.gandi', 'GandiDNSDriver'),
# Deprecated
Provider.RACKSPACE_US:
- ('libcloud.dns.drivers.rackspace', 'RackspaceUSDNSDriver'),
+ ('libcloud.dns.drivers.rackspace', 'RackspaceUSDNSDriver'),
Provider.RACKSPACE_UK:
- ('libcloud.dns.drivers.rackspace', 'RackspaceUKDNSDriver')
+ ('libcloud.dns.drivers.rackspace', 'RackspaceUKDNSDriver')
}
def get_driver(provider):
return get_provider_driver(DRIVERS, provider)
+
def set_driver(provider, module, klass):
return set_provider_driver(DRIVERS, provider, module, klass)
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/loadbalancer/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/cloudstack.py b/libcloud/loadbalancer/drivers/cloudstack.py
index 117fc6a..dcec636 100644
--- a/libcloud/loadbalancer/drivers/cloudstack.py
+++ b/libcloud/loadbalancer/drivers/cloudstack.py
@@ -140,7 +140,7 @@ class CloudStackLBDriver(CloudStackDriverMixIn, Driver):
members = self._sync_request('listLoadBalancerRuleInstances',
id=balancer.id)
members = members['loadbalancerruleinstance']
- return [self._to_member(m, balancer.ex_private_port, balancer) \
+ return [self._to_member(m, balancer.ex_private_port, balancer)
for m in members]
def _to_balancer(self, obj):
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/loadbalancer/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/gce.py b/libcloud/loadbalancer/drivers/gce.py
index 904ff9c..75f18a5 100644
--- a/libcloud/loadbalancer/drivers/gce.py
+++ b/libcloud/loadbalancer/drivers/gce.py
@@ -16,7 +16,7 @@
try:
import simplejson as json
except ImportError:
- import json
+ import json # NOQA
from libcloud.loadbalancer.base import LoadBalancer, Member, Driver, Algorithm
from libcloud.compute.drivers.gce import GCEConnection, GCENodeDriver
@@ -125,7 +125,8 @@ class GCELBDriver(Driver):
:keyword ex_healthchecks: Optional list of healthcheck objects or
names to add to the load balancer.
- :type ex_healthchecks: ``list`` of :class:`GCEHealthCheck` or ``str``
+ :type ex_healthchecks: ``list`` of :class:`GCEHealthCheck` or
+ ``str``
:keyword ex_address: Optional static address object to be assigned to
the load balancer.
@@ -134,8 +135,6 @@ class GCELBDriver(Driver):
:return: LoadBalancer object
:rtype: :class:`LoadBalancer`
"""
- unused = algorithm
-
node_list = []
for member in members:
# Member object
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/loadbalancer/drivers/gogrid.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/gogrid.py b/libcloud/loadbalancer/drivers/gogrid.py
index a688f06..201ad03 100644
--- a/libcloud/loadbalancer/drivers/gogrid.py
+++ b/libcloud/loadbalancer/drivers/gogrid.py
@@ -164,8 +164,9 @@ class GoGridLBDriver(BaseGoGridDriver, Driver):
resp = self._update_balancer(params)
return [m for m in
- self._to_members(resp.object["list"][0]["realiplist"], balancer)
- if m.ip == member.ip][0]
+ self._to_members(resp.object["list"][0]["realiplist"],
+ balancer)
+ if m.ip == member.ip][0]
def balancer_detach_member(self, balancer, member):
members = self.balancer_list_members(balancer)
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/loadbalancer/providers.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/providers.py b/libcloud/loadbalancer/providers.py
index f3d9dec..f11e450 100644
--- a/libcloud/loadbalancer/providers.py
+++ b/libcloud/loadbalancer/providers.py
@@ -24,31 +24,32 @@ __all__ = [
]
DRIVERS = {
- Provider.RACKSPACE:
- ('libcloud.loadbalancer.drivers.rackspace', 'RackspaceLBDriver'),
- Provider.GOGRID:
- ('libcloud.loadbalancer.drivers.gogrid', 'GoGridLBDriver'),
- Provider.NINEFOLD:
- ('libcloud.loadbalancer.drivers.ninefold', 'NinefoldLBDriver'),
- Provider.BRIGHTBOX:
- ('libcloud.loadbalancer.drivers.brightbox', 'BrightboxLBDriver'),
- Provider.ELB:
- ('libcloud.loadbalancer.drivers.elb', 'ElasticLBDriver'),
- Provider.CLOUDSTACK:
- ('libcloud.loadbalancer.drivers.cloudstack', 'CloudStackLBDriver'),
- Provider.GCE:
- ('libcloud.loadbalancer.drivers.gce', 'GCELBDriver'),
-
- # Deprecated
- Provider.RACKSPACE_US:
- ('libcloud.loadbalancer.drivers.rackspace', 'RackspaceLBDriver'),
- Provider.RACKSPACE_UK:
- ('libcloud.loadbalancer.drivers.rackspace', 'RackspaceUKLBDriver'),
+ Provider.RACKSPACE:
+ ('libcloud.loadbalancer.drivers.rackspace', 'RackspaceLBDriver'),
+ Provider.GOGRID:
+ ('libcloud.loadbalancer.drivers.gogrid', 'GoGridLBDriver'),
+ Provider.NINEFOLD:
+ ('libcloud.loadbalancer.drivers.ninefold', 'NinefoldLBDriver'),
+ Provider.BRIGHTBOX:
+ ('libcloud.loadbalancer.drivers.brightbox', 'BrightboxLBDriver'),
+ Provider.ELB:
+ ('libcloud.loadbalancer.drivers.elb', 'ElasticLBDriver'),
+ Provider.CLOUDSTACK:
+ ('libcloud.loadbalancer.drivers.cloudstack', 'CloudStackLBDriver'),
+ Provider.GCE:
+ ('libcloud.loadbalancer.drivers.gce', 'GCELBDriver'),
+
+ # Deprecated
+ Provider.RACKSPACE_US:
+ ('libcloud.loadbalancer.drivers.rackspace', 'RackspaceLBDriver'),
+ Provider.RACKSPACE_UK:
+ ('libcloud.loadbalancer.drivers.rackspace', 'RackspaceUKLBDriver'),
}
def get_driver(provider):
return get_provider_driver(DRIVERS, provider)
+
def set_driver(provider, module, klass):
return set_provider_driver(DRIVERS, provider, module, klass)
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/pricing.py
----------------------------------------------------------------------
diff --git a/libcloud/pricing.py b/libcloud/pricing.py
index 5e4cb89..dd8de96 100644
--- a/libcloud/pricing.py
+++ b/libcloud/pricing.py
@@ -37,7 +37,7 @@ __all__ = [
]
# Default URL to the pricing file
-DEFAULT_FILE_URL = 'https://git-wip-us.apache.org/repos/asf?p=libcloud.git;a=blob_plain;f=libcloud/data/pricing.json'
+DEFAULT_FILE_URL = 'https://git-wip-us.apache.org/repos/asf?p=libcloud.git;a=blob_plain;f=libcloud/data/pricing.json' # NOQA
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
DEFAULT_PRICING_FILE_PATH = pjoin(CURRENT_DIRECTORY, 'data/pricing.json')
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/storage/drivers/atmos.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/atmos.py b/libcloud/storage/drivers/atmos.py
index 271fbef..a1e12cc 100644
--- a/libcloud/storage/drivers/atmos.py
+++ b/libcloud/storage/drivers/atmos.py
@@ -467,7 +467,6 @@ class AtmosDriver(StorageDriver):
path = self._namespace_path(container.name) + '/'
result = self.connection.request(path, headers=headers)
entries = self._list_objects(result.object, object_type='regular')
- objects = []
for entry in entries:
metadata = {'object_id': entry['id']}
yield Object(entry['name'], 0, '', {}, metadata, container, self)
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/storage/drivers/azure_blobs.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/azure_blobs.py b/libcloud/storage/drivers/azure_blobs.py
index d11a105..8d00a8d 100644
--- a/libcloud/storage/drivers/azure_blobs.py
+++ b/libcloud/storage/drivers/azure_blobs.py
@@ -15,14 +15,10 @@
from __future__ import with_statement
-import time
import base64
-import hmac
-import re
import os
import binascii
-from hashlib import sha256
from xml.etree.ElementTree import Element, SubElement
from libcloud.utils.py3 import PY3
@@ -31,7 +27,7 @@ from libcloud.utils.py3 import urlquote
from libcloud.utils.py3 import tostring
from libcloud.utils.py3 import b
-from libcloud.utils.xml import fixxpath, findtext
+from libcloud.utils.xml import fixxpath
from libcloud.utils.files import read_in_chunks
from libcloud.common.types import LibcloudError
from libcloud.common.azure import AzureConnection
@@ -182,10 +178,9 @@ class AzureBlobsStorageDriver(StorageDriver):
# so for every request. Minor performance improvement
secret = base64.b64decode(b(secret))
- super(AzureBlobsStorageDriver, self).__init__(
- key=key, secret=secret,
- secure=secure, host=host,
- port=port, **kwargs)
+ super(AzureBlobsStorageDriver, self).__init__(key=key, secret=secret,
+ secure=secure, host=host,
+ port=port, **kwargs)
def _ex_connection_class_kwargs(self):
result = {}
@@ -296,9 +291,9 @@ class AzureBlobsStorageDriver(StorageDriver):
'duration': props.findtext(fixxpath(xpath='LeaseDuration')),
},
'content_encoding': props.findtext(fixxpath(
- xpath='Content-Encoding')),
+ xpath='Content-Encoding')),
'content_language': props.findtext(fixxpath(
- xpath='Content-Language')),
+ xpath='Content-Language')),
'blob_type': props.findtext(fixxpath(xpath='BlobType'))
}
@@ -659,7 +654,7 @@ class AzureBlobsStorageDriver(StorageDriver):
else:
headers['x-ms-page-write'] = 'update'
headers['x-ms-range'] = 'bytes=%d-%d' % \
- (offset, bytes_transferred-1)
+ (offset, bytes_transferred-1)
# Renew lease before updating
lease.renew()
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/storage/drivers/dummy.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/dummy.py b/libcloud/storage/drivers/dummy.py
index 8e4539a..affd265 100644
--- a/libcloud/storage/drivers/dummy.py
+++ b/libcloud/storage/drivers/dummy.py
@@ -113,10 +113,13 @@ class DummyStorageDriver(StorageDriver):
0
>>> driver.get_meta_data()['bytes_used']
0
- >>> container = driver.create_container(container_name='test container 1')
- >>> container = driver.create_container(container_name='test container 2')
+ >>> container_name = 'test container 1'
+ >>> container = driver.create_container(container_name=container_name)
+ >>> container_name = 'test container 2'
+ >>> container = driver.create_container(container_name=container_name)
>>> obj = container.upload_object_via_stream(
- ... object_name='test object', iterator=DummyFileObject(5, 10), extra={})
+ ... object_name='test object', iterator=DummyFileObject(5, 10),
+ ... extra={})
>>> driver.get_meta_data()['object_count']
1
>>> driver.get_meta_data()['container_count']
@@ -146,20 +149,23 @@ class DummyStorageDriver(StorageDriver):
>>> driver = DummyStorageDriver('key', 'secret')
>>> list(driver.iterate_containers())
[]
- >>> container = driver.create_container(container_name='test container 1')
+ >>> container_name = 'test container 1'
+ >>> container = driver.create_container(container_name=container_name)
>>> container
<Container: name=test container 1, provider=Dummy Storage Provider>
>>> container.name
'test container 1'
- >>> container = driver.create_container(container_name='test container 2')
+ >>> container_name = 'test container 2'
+ >>> container = driver.create_container(container_name=container_name)
>>> container
<Container: name=test container 2, provider=Dummy Storage Provider>
>>> container = driver.create_container(
- ... container_name='test container 2') #doctest: +IGNORE_EXCEPTION_DETAIL
+ ... container_name='test container 2')
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ContainerAlreadyExistsError:
>>> container_list=list(driver.iterate_containers())
- >>> sorted([container.name for container in container_list])
+ >>> sorted([c.name for c in container_list])
['test container 1', 'test container 2']
@inherits: :class:`StorageDriver.iterate_containers`
@@ -179,7 +185,8 @@ class DummyStorageDriver(StorageDriver):
>>> driver.get_container('unknown') #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ContainerDoesNotExistError:
- >>> container = driver.create_container(container_name='test container 1')
+ >>> container_name = 'test container 1'
+ >>> container = driver.create_container(container_name=container_name)
>>> container
<Container: name=test container 1, provider=Dummy Storage Provider>
>>> container.name
@@ -202,7 +209,8 @@ class DummyStorageDriver(StorageDriver):
>>> driver.get_container('unknown') #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ContainerDoesNotExistError:
- >>> container = driver.create_container(container_name='test container 1')
+ >>> container_name = 'test container 1'
+ >>> container = driver.create_container(container_name=container_name)
>>> container
<Container: name=test container 1, provider=Dummy Storage Provider>
>>> container.name
@@ -222,10 +230,12 @@ class DummyStorageDriver(StorageDriver):
def get_object(self, container_name, object_name):
"""
>>> driver = DummyStorageDriver('key', 'secret')
- >>> driver.get_object('unknown', 'unknown') #doctest: +IGNORE_EXCEPTION_DETAIL
+ >>> driver.get_object('unknown', 'unknown')
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ContainerDoesNotExistError:
- >>> container = driver.create_container(container_name='test container 1')
+ >>> container_name = 'test container 1'
+ >>> container = driver.create_container(container_name=container_name)
>>> container
<Container: name=test container 1, provider=Dummy Storage Provider>
>>> driver.get_object(
@@ -234,8 +244,10 @@ class DummyStorageDriver(StorageDriver):
ObjectDoesNotExistError:
>>> obj = container.upload_object_via_stream(object_name='test object',
... iterator=DummyFileObject(5, 10), extra={})
- >>> obj
- <Object: name=test object, size=50, hash=None, provider=Dummy Storage Provider ...>
+ >>> obj.name
+ 'test object'
+ >>> obj.size
+ 50
@inherits: :class:`StorageDriver.get_object`
"""
@@ -251,13 +263,15 @@ class DummyStorageDriver(StorageDriver):
def get_object_cdn_url(self, obj):
"""
>>> driver = DummyStorageDriver('key', 'secret')
- >>> container = driver.create_container(container_name='test container 1')
+ >>> container_name = 'test container 1'
+ >>> container = driver.create_container(container_name=container_name)
>>> container
<Container: name=test container 1, provider=Dummy Storage Provider>
- >>> obj = container.upload_object_via_stream(object_name='test object 5',
+ >>> obj = container.upload_object_via_stream(
+ ... object_name='test object 5',
... iterator=DummyFileObject(5, 10), extra={})
- >>> obj
- <Object: name=test object 5, size=50, hash=None, provider=Dummy Storage Provider ...>
+ >>> obj.name
+ 'test object 5'
>>> obj.get_cdn_url()
'http://www.test.com/object/test_object_5'
@@ -275,11 +289,13 @@ class DummyStorageDriver(StorageDriver):
def create_container(self, container_name):
"""
>>> driver = DummyStorageDriver('key', 'secret')
- >>> container = driver.create_container(container_name='test container 1')
+ >>> container_name = 'test container 1'
+ >>> container = driver.create_container(container_name=container_name)
>>> container
<Container: name=test container 1, provider=Dummy Storage Provider>
>>> container = driver.create_container(
- ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL
+ ... container_name='test container 1')
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ContainerAlreadyExistsError:
@@ -296,7 +312,8 @@ class DummyStorageDriver(StorageDriver):
self._containers[container_name] = {'container': container,
'objects': {},
'cdn_url':
- 'http://www.test.com/container/%s' %
+ 'http://www.test.com/container/%s'
+ %
(container_name.replace(' ', '_'))
}
return container
@@ -306,11 +323,13 @@ class DummyStorageDriver(StorageDriver):
>>> driver = DummyStorageDriver('key', 'secret')
>>> container = Container(name = 'test container',
... extra={'object_count': 0}, driver=driver)
- >>> driver.delete_container(container=container)#doctest: +IGNORE_EXCEPTION_DETAIL
+ >>> driver.delete_container(container=container)
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ContainerDoesNotExistError:
>>> container = driver.create_container(
- ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL
+ ... container_name='test container 1')
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
>>> len(driver._containers)
1
>>> driver.delete_container(container=container)
@@ -318,10 +337,13 @@ class DummyStorageDriver(StorageDriver):
>>> len(driver._containers)
0
>>> container = driver.create_container(
- ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL
+ ... container_name='test container 1')
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
>>> obj = container.upload_object_via_stream(
- ... object_name='test object', iterator=DummyFileObject(5, 10), extra={})
- >>> driver.delete_container(container=container)#doctest: +IGNORE_EXCEPTION_DETAIL
+ ... object_name='test object', iterator=DummyFileObject(5, 10),
+ ... extra={})
+ >>> driver.delete_container(container=container)
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ContainerIsNotEmptyError:
@@ -355,7 +377,8 @@ class DummyStorageDriver(StorageDriver):
"""
>>> driver = DummyStorageDriver('key', 'secret')
>>> container = driver.create_container(
- ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL
+ ... container_name='test container 1')
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
>>> obj = container.upload_object_via_stream(object_name='test object',
... iterator=DummyFileObject(5, 10), extra={})
>>> stream = container.download_object_as_stream(obj)
@@ -371,14 +394,16 @@ class DummyStorageDriver(StorageDriver):
file_hash=None):
"""
>>> driver = DummyStorageDriver('key', 'secret')
- >>> container = driver.create_container(container_name='test container 1')
+ >>> container_name = 'test container 1'
+ >>> container = driver.create_container(container_name=container_name)
>>> container.upload_object(file_path='/tmp/inexistent.file',
... object_name='test') #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
LibcloudError:
>>> file_path = path = os.path.abspath(__file__)
>>> file_size = os.path.getsize(file_path)
- >>> obj = container.upload_object(file_path=file_path, object_name='test')
+ >>> obj = container.upload_object(file_path=file_path,
+ ... object_name='test')
>>> obj #doctest: +ELLIPSIS
<Object: name=test, size=...>
>>> obj.size == file_size
@@ -402,9 +427,11 @@ class DummyStorageDriver(StorageDriver):
"""
>>> driver = DummyStorageDriver('key', 'secret')
>>> container = driver.create_container(
- ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL
+ ... container_name='test container 1')
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
>>> obj = container.upload_object_via_stream(
- ... object_name='test object', iterator=DummyFileObject(5, 10), extra={})
+ ... object_name='test object', iterator=DummyFileObject(5, 10),
+ ... extra={})
>>> obj #doctest: +ELLIPSIS
<Object: name=test object, size=50, ...>
@@ -419,7 +446,8 @@ class DummyStorageDriver(StorageDriver):
"""
>>> driver = DummyStorageDriver('key', 'secret')
>>> container = driver.create_container(
- ... container_name='test container 1') #doctest: +IGNORE_EXCEPTION_DETAIL
+ ... container_name='test container 1')
+ ... #doctest: +IGNORE_EXCEPTION_DETAIL
>>> obj = container.upload_object_via_stream(object_name='test object',
... iterator=DummyFileObject(5, 10), extra={})
>>> obj #doctest: +ELLIPSIS
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/storage/drivers/local.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/local.py b/libcloud/storage/drivers/local.py
index fee53f7..cfcf410 100644
--- a/libcloud/storage/drivers/local.py
+++ b/libcloud/storage/drivers/local.py
@@ -25,9 +25,10 @@ import shutil
import sys
try:
+ import lockfile
from lockfile import LockTimeout, mkdirlockfile
except ImportError:
- raise ImportError('Missing lockfile dependency, you can install it ' \
+ raise ImportError('Missing lockfile dependency, you can install it '
'using pip: pip install lockfile')
from libcloud.utils.files import read_in_chunks
@@ -305,9 +306,9 @@ class LocalStorageDriver(StorageDriver):
"""
path = self.get_container_cdn_url(container)
- lock = lockfile.MkdirFileLock(path, threaded=True)
+ lockfile.MkdirFileLock(path, threaded=True)
- with LockLocalStorage(path) as lock:
+ with LockLocalStorage(path):
self._make_path(path)
return True
@@ -323,7 +324,7 @@ class LocalStorageDriver(StorageDriver):
"""
path = self.get_object_cdn_url(obj)
- with LockLocalStorage(path) as lock:
+ with LockLocalStorage(path):
if os.path.exists(path):
return False
try:
@@ -438,7 +439,7 @@ class LocalStorageDriver(StorageDriver):
self._make_path(base_path)
- with LockLocalStorage(obj_path) as lock:
+ with LockLocalStorage(obj_path):
shutil.copy(file_path, obj_path)
os.chmod(obj_path, int('664', 8))
@@ -488,7 +489,7 @@ class LocalStorageDriver(StorageDriver):
self._make_path(base_path)
- with LockLocalStorage(obj_path) as lock:
+ with LockLocalStorage(obj_path):
obj_file = open(obj_path, 'w')
for data in iterator:
obj_file.write(data)
@@ -512,7 +513,7 @@ class LocalStorageDriver(StorageDriver):
path = self.get_object_cdn_url(obj)
- with LockLocalStorage(path) as lock:
+ with LockLocalStorage(path):
try:
os.unlink(path)
except Exception:
@@ -585,11 +586,12 @@ class LocalStorageDriver(StorageDriver):
# Check if there are any objects inside this
for obj in self._get_objects(container):
raise ContainerIsNotEmptyError(value='Container is not empty',
- container_name=container.name, driver=self)
+ container_name=container.name,
+ driver=self)
path = self.get_container_cdn_url(container, check=True)
- with LockLocalStorage(path) as lock:
+ with LockLocalStorage(path):
try:
shutil.rmtree(path)
except Exception:
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a73a3bd8/libcloud/storage/drivers/nimbus.py
----------------------------------------------------------------------
diff --git a/libcloud/storage/drivers/nimbus.py b/libcloud/storage/drivers/nimbus.py
index 201488d..172c701 100644
--- a/libcloud/storage/drivers/nimbus.py
+++ b/libcloud/storage/drivers/nimbus.py
@@ -20,7 +20,7 @@ import hmac
try:
import simplejson as json
except ImportError:
- import json
+ import json # NOQA
from libcloud.utils.py3 import httplib
from libcloud.utils.py3 import urlencode