Merge branch 'LIBCLOUD-556_azure_compute_driver' into
LIBCLOUD-556_azure_compute_driver_rebased
Updated sizes based on latest Microsoft documentation. Fixed some styling of
the merged changes
Conflicts:
libcloud/common/azure.py
libcloud/compute/drivers/azure.py
libcloud/compute/providers.py
libcloud/compute/types.py
libcloud/test/compute/test_azure.py
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6048e2e0
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6048e2e0
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6048e2e0
Branch: refs/heads/trunk
Commit: 6048e2e06b895637de2c6d1b53cc1d50fef0ca72
Parents: c9ce29e b331418
Author: Michael Bennett <[email protected]>
Authored: Fri Nov 21 00:42:53 2014 -0500
Committer: Michael Bennett <[email protected]>
Committed: Fri Nov 21 00:42:53 2014 -0500
----------------------------------------------------------------------
libcloud/common/azure.py | 3 +-
libcloud/compute/drivers/azure.py | 622 +++++++++++++++++----------------
libcloud/compute/types.py | 3 +
3 files changed, 320 insertions(+), 308 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/6048e2e0/libcloud/common/azure.py
----------------------------------------------------------------------
diff --cc libcloud/common/azure.py
index 1075c95,931da74..e76097c
--- a/libcloud/common/azure.py
+++ b/libcloud/common/azure.py
@@@ -31,8 -31,8 +31,7 @@@ except ImportError
from libcloud.common.types import InvalidCredsError
from libcloud.common.types import LibcloudError, MalformedResponseError
--from libcloud.common.base import ConnectionUserAndKey, RawResponse, \
-- CertificateConnection
++from libcloud.common.base import ConnectionUserAndKey, RawResponse,
CertificateConnection
from libcloud.common.base import XmlResponse
# Azure API version
http://git-wip-us.apache.org/repos/asf/libcloud/blob/6048e2e0/libcloud/compute/drivers/azure.py
----------------------------------------------------------------------
diff --cc libcloud/compute/drivers/azure.py
index f5e0524,18e0310..a25ee70
--- a/libcloud/compute/drivers/azure.py
+++ b/libcloud/compute/drivers/azure.py
@@@ -64,8 -69,8 +69,8 @@@ From http://msdn.microsoft.com/en-us/li
"""
AZURE_COMPUTE_INSTANCE_TYPES = {
'A0': {
- 'id': 'ExtraSmall',
- 'id': 'A0',
-- 'name': 'ExtraSmall Instance',
++ 'id': 'extra small',
++ 'name': 'Extra Small Instance',
'ram': 768,
'disk': 127,
'bandwidth': None,
@@@ -74,7 -79,7 +79,7 @@@
'cores': 'Shared'
},
'A1': {
- 'id': 'Small',
- 'id': 'A1',
++ 'id': 'small',
'name': 'Small Instance',
'ram': 1792,
'disk': 127,
@@@ -84,7 -89,7 +89,7 @@@
'cores': 1
},
'A2': {
- 'id': 'Medium',
- 'id': 'A2',
++ 'id': 'medium',
'name': 'Medium Instance',
'ram': 3584,
'disk': 127,
@@@ -94,7 -99,7 +99,7 @@@
'cores': 2
},
'A3': {
- 'id': 'Large',
- 'id': 'A3',
++ 'id': 'large',
'name': 'Large Instance',
'ram': 7168,
'disk': 127,
@@@ -104,8 -109,8 +109,8 @@@
'cores': 4
},
'A4': {
- 'id': 'ExtraLarge',
- 'id': 'A4',
-- 'name': 'ExtraLarge Instance',
++ 'id': 'extra large',
++ 'name': 'Extra Large Instance',
'ram': 14336,
'disk': 127,
'bandwidth': None,
@@@ -329,13 -309,14 +334,12 @@@ class AzureNodeDriver(NodeDriver)
raise ValueError("ex_cloud_service_name is required.")
if not ex_deployment_slot:
- ex_deployment_slot = "production"
-
- if not node:
- raise ValueError("node is required.")
+ ex_deployment_slot = "Production"
-
_deployment_name = self._get_deployment(
service_name=ex_cloud_service_name,
- deployment_slot=ex_deployment_slot).name
+ deployment_slot=ex_deployment_slot
+ ).name
try:
response = self._perform_post(
@@@ -475,38 -441,37 +479,38 @@@
network_config = ConfigurationSet()
network_config.configuration_set_type = 'NetworkConfiguration'
-- # We do this because we need to pass a Configuration to the
- # method. This will be either Linux or Windows.
- if re.search("Win|SQL|SharePoint|Visual|Dynamics|DynGP|BizTalk",
- image, re.I):
++ # We do this because we need to pass a Configuration to the
+ # method. This will be either Linux or Windows.
+ windows_server_regex =
re.compile(r'Win|SQL|SharePoint|Visual|Dynamics|DynGP|BizTalk')
+ if windows_server_regex.search(image.id, re.I):
machine_config = WindowsConfigurationSet(
- computer_name=name, admin_password=password,
- admin_user_name=ex_admin_user_id)
+ computer_name=name,
+ admin_password=password,
+ admin_user_name=ex_admin_user_id
+ )
machine_config.domain_join = None
- if node_list is None:
+ if node_list is None or ex_new_deployment:
port = "3389"
else:
- port = random.randint(41952,65535)
+ port = random.randint(41952, 65535)
endpoints = self._get_deployment(
service_name=ex_cloud_service_name,
- deployment_slot=ex_deployment_slot)
+ deployment_slot=ex_deployment_slot
+ )
for instances in endpoints.role_instance_list:
- ports = []
- for ep in instances.instance_endpoints:
- ports += [ep.public_port]
+ ports = [ep.public_port for ep in
instances.instance_endpoints]
while port in ports:
- port = random.randint(41952,65535)
+ port = random.randint(41952, 65535)
endpoint = ConfigurationSetInputEndpoint(
-- name='Remote Desktop',
-- protocol='tcp',
++ name=u'Remote Desktop',
++ protocol=u'tcp',
port=port,
-- local_port='3389',
++ local_port=u'3389',
load_balanced_endpoint_set_name=None,
enable_direct_server_return=False
)
@@@ -522,53 -486,28 +526,54 @@@
for instances in endpoints.role_instance_list:
ports = []
- for ep in instances.instance_endpoints:
- ports += [ep.public_port]
+ if instances.instance_endpoints is not None:
+ for ep in instances.instance_endpoints:
+ ports += [ep.public_port]
while port in ports:
-- port = random.randint(41952,65535)
++ port = random.randint(41952, 65535)
endpoint = ConfigurationSetInputEndpoint(
-- name='SSH',
-- protocol='tcp',
++ name=u'SSH',
++ protocol=u'tcp',
port=port,
-- local_port='22',
++ local_port=u'22',
load_balanced_endpoint_set_name=None,
enable_direct_server_return=False
)
machine_config = LinuxConfigurationSet(
- name, ex_admin_user_id, password, False)
+ name,
+ ex_admin_user_id,
+ password,
+ False
+ )
- network_config.input_endpoints.input_endpoints.append(endpoint)
+ network_config.input_endpoints.items.append(endpoint)
_storage_location = self._get_cloud_service_location(
-- service_name=ex_cloud_service_name)
-
++ service_name=ex_cloud_service_name
++ )
+
+ if "ex_storage_service_name" in kwargs:
+ ex_storage_service_name = kwargs['ex_storage_service_name']
+ else:
+ ex_storage_service_name = ex_cloud_service_name
+ ex_storage_service_name = re.sub(
+ ur'[\W_]+',
+ u'',
+ ex_storage_service_name.lower(),
+ flags=re.UNICODE
+ )
+
+ if self._is_storage_service_unique(
+ service_name=ex_storage_service_name):
+
+ self._create_storage_account(
+ service_name=ex_storage_service_name,
+ location=_storage_location.service_location,
+ is_affinity_group=_storage_location.is_affinity_group
+ )
+
# OK, bit annoying here. You must create a deployment before
# you can create an instance; however, the deployment function
# creates the first instance, but all subsequent instances
@@@ -583,25 -536,14 +588,25 @@@
else:
ex_deployment_name = ex_cloud_service_name
- blob_url = "http://" + ex_storage_service_name \
- + ".blob.core.windows.net"
+ vm_image_id = None
+ disk_config = None
- if image.extra['vm_image']:
- # Azure's pattern in the UI.
- disk_name = "{0}-{1}-{2}.vhd".format(
- ex_cloud_service_name,name,time.strftime("%Y-%m-%d"))
- media_link = blob_url + "/vhds/" + disk_name
- disk_config = OSVirtualHardDisk(image, media_link)
++ if image.extra.get('vm_image', False):
+ vm_image_id = image.id
+ #network_config = None
+ else:
+ blob_url = "http://" + ex_storage_service_name +
".blob.core.windows.net"
+
+ # Azure's pattern in the UI.
+ disk_name = "{0}-{1}-{2}.vhd".format(
+ ex_cloud_service_name,
+ name,
+ time.strftime("%Y-%m-%d")
+ )
+
+ media_link = blob_url + "/vhds/" + disk_name
+
+ disk_config = OSVirtualHardDisk(image.id, media_link)
response = self._perform_post(
self._get_deployment_path_using_name(ex_cloud_service_name),
@@@ -1193,16 -1049,17 +1198,16 @@@
return response
def _perform_post(self, path, body, response_type=None, async=False):
-- request = AzureHTTPRequest()
-- request.method = 'POST'
-- request.host = azure_service_management_host
-- request.path = path
-- request.body = self._get_request_body(body)
- request.path, request.query =
self._update_request_uri_query(request)
- request.path, request.query = \
- self._update_request_uri_query(request)
-- request.headers = self._update_management_header(request)
-- response = self._perform_request(request)
-
- return response
++ request = AzureHTTPRequest()
++ request.method = 'POST'
++ request.host = azure_service_management_host
++ request.path = path
++ request.body = self._get_request_body(body)
++ request.path, request.query = self._update_request_uri_query(request)
++ request.headers = self._update_management_header(request)
++ response = self._perform_request(request)
+
- return response
++ return response
def _perform_delete(self, path, async=False):
request = AzureHTTPRequest()
@@@ -1555,30 -1373,34 +1560,35 @@@
return request_body
def _convert_class_to_xml(self, source, xml_prefix=True):
- if source is None:
- return ''
- xmlstr = ''
- if xml_prefix:
- xmlstr = '<?xml version="1.0" encoding="utf-8"?>'
- root = ET.Element()
++ root = ET.Element()
+ doc = self._construct_element_tree(source, root)
+
+ return ET.tostring(doc, encoding='utf8', method='xml')
+
+ def _construct_element_tree(self, source, etree):
+ if source is None:
+ return ET.Element()
if isinstance(source, list):
- xmlstr += ''.join(self._convert_class_to_xml(value, False) for
value in source)
+ for value in source:
- etree.append( self._construct_element_tree(value, etree))
++ etree.append(self._construct_element_tree(value, etree))
++
elif isinstance(source, WindowsAzureData):
class_name = source.__class__.__name__
- xmlstr += '<' + class_name + '>'
+ etree.append(ET.Element(class_name))
++
for name, value in vars(source).items():
if value is not None:
- if isinstance(value, list) or \
- isinstance(value, WindowsAzureData):
+ if isinstance(value, list) or isinstance(value,
WindowsAzureData):
- xmlstr += self._convert_class_to_xml(value, False)
+ etree.append(self._construct_element_tree(value,
etree))
-
else:
- xmlstr += (
- '<' + self._get_serialization_name(name) + '>'
- + xml_escape(str(value))
- + '</' + self._get_serialization_name(name) + '>'
- )
- xmlstr += '</' + class_name + '>'
- return xmlstr
+ ele = ET.Element(self._get_serialization_name(name))
+ ele.text = xml_escape(str(value))
+ etree.append(ele)
++
+ etree.append(ET.Element(class_name))
+ return etree
def _parse_response_for_async_op(self, response):
if response is None:
@@@ -1684,15 -1488,11 +1694,15 @@@ Borrowed from the Azure SDK for Python
def _lower(text):
return text.lower()
-class AzureXmlSerializer():
+
- class AzureXmlSerializer():
++class AzureXmlSerializer(object):
@staticmethod
- def create_storage_service_input_to_xml(service_name, description, label,
- affinity_group, location,
+ def create_storage_service_input_to_xml(service_name,
+ description,
+ label,
+ affinity_group,
+ location,
geo_replication_enabled,
extended_properties):
return AzureXmlSerializer.doc_from_data(
@@@ -1943,274 -1673,216 +1953,265 @@@
@staticmethod
def restart_role_operation_to_xml():
- return AzureXmlSerializer.doc_from_xml(
+ xml = ET.Element("OperationType")
+ xml.text = "RestartRoleOperation"
+ doc = AzureXmlSerializer.doc_from_xml(
'RestartRoleOperation',
- '<OperationType>RestartRoleOperation</OperationType>'
- xml)
++ xml
+ )
+ return ET.tostring(doc, "UTF-8").replace("\n", "")
@staticmethod
def shutdown_role_operation_to_xml():
- return AzureXmlSerializer.doc_from_xml(
+ xml = ET.Element("OperationType")
+ xml.text = "ShutdownRoleOperation"
+ doc = AzureXmlSerializer.doc_from_xml(
'ShutdownRoleOperation',
- '<OperationType>ShutdownRoleOperation</OperationType>'
- xml)
++ xml
+ )
+ return ET.tostring(doc, "UTF-8").replace("\n", "")
@staticmethod
def start_role_operation_to_xml():
- return AzureXmlSerializer.doc_from_xml(
+ xml = ET.Element("OperationType")
+ xml.text = "StartRoleOperation"
+ doc = AzureXmlSerializer.doc_from_xml(
'StartRoleOperation',
- '<OperationType>StartRoleOperation</OperationType>'
- xml)
++ xml
+ )
+ return ET.tostring(doc, "UTF-8").replace("\n", "")
@staticmethod
- def windows_configuration_to_xml(configuration):
- xml = AzureXmlSerializer.data_to_xml(
- [
- ('ConfigurationSetType',
configuration.configuration_set_type),
- ('ComputerName', configuration.computer_name),
- ('AdminPassword', configuration.admin_password),
- (
- 'ResetPasswordOnFirstLogon',
- configuration.reset_password_on_first_logon,
- _lower
- ),
- (
- 'EnableAutomaticUpdates',
- configuration.enable_automatic_updates,
- _lower
- ),
- ('TimeZone', configuration.time_zone)
- ]
+ def windows_configuration_to_xml(configuration, xml):
+ AzureXmlSerializer.data_to_xml([('ConfigurationSetType',
configuration.configuration_set_type)], xml)
+ AzureXmlSerializer.data_to_xml([('ComputerName',
configuration.computer_name)], xml)
+ AzureXmlSerializer.data_to_xml([('AdminPassword',
configuration.admin_password)], xml)
- AzureXmlSerializer.data_to_xml([('ResetPasswordOnFirstLogon',
- configuration.reset_password_on_first_logon,
- _lower)], xml)
- AzureXmlSerializer.data_to_xml([('EnableAutomaticUpdates',
- configuration.enable_automatic_updates,
- _lower)], xml)
++
++ AzureXmlSerializer.data_to_xml(
++ [('ResetPasswordOnFirstLogon',
configuration.reset_password_on_first_logon, _lower)],
++ xml
+ )
+
++ AzureXmlSerializer.data_to_xml(
++ [('EnableAutomaticUpdates',
configuration.enable_automatic_updates, _lower)],
++ xml
++ )
++
+ AzureXmlSerializer.data_to_xml([('TimeZone',
configuration.time_zone)], xml)
+
if configuration.domain_join is not None:
- xml += '<DomainJoin>'
- xml += '<Credentials>'
- xml += AzureXmlSerializer.data_to_xml(
- [
- ('Domain', configuration.domain_join.credentials.domain),
- ('Username',
configuration.domain_join.credentials.username),
- ('Password',
configuration.domain_join.credentials.password)
- ]
+ domain = ET.xml("DomainJoin")
+ creds = ET.xml("Credentials")
+ domain.appemnd(creds)
+ xml.append(domain)
+
+ AzureXmlSerializer.data_to_xml(
- [('Domain', configuration.domain_join.credentials.domain)],
creds)
++ [('Domain', configuration.domain_join.credentials.domain)],
++ creds
+ )
- xml += '</Credentials>'
- xml += AzureXmlSerializer.data_to_xml(
- [
- ('JoinDomain', configuration.domain_join.join_domain),
- (
- 'MachineObjectOU',
- configuration.domain_join.machine_object_ou
- )
- ]
++
+ AzureXmlSerializer.data_to_xml([('Username',
configuration.domain_join.credentials.username)], creds)
+ AzureXmlSerializer.data_to_xml([('Password',
configuration.domain_join.credentials.password)], creds)
+
+ AzureXmlSerializer.data_to_xml(
- [('JoinDomain', configuration.domain_join.join_domain)],
domain)
- AzureXmlSerializer.data_to_xml([('MachineObjectOU',
- configuration.domain_join.machine_object_ou)], domain)
++ [('JoinDomain', configuration.domain_join.join_domain)],
++ domain
+ )
- xml += '</DomainJoin>'
- if configuration.stored_certificate_settings is not None:
- xml += '<StoredCertificateSettings>'
+
++ AzureXmlSerializer.data_to_xml(
++ [('MachineObjectOU',
configuration.domain_join.machine_object_ou)],
++ domain
++ )
+
+ if configuration.stored_certificate_settings is not None:
+ certsettings = ET.Element("StoredCertificateSettings")
+ xml.append(certsettings)
for cert in configuration.stored_certificate_settings:
- xml += '<CertificateSetting>'
- xml += AzureXmlSerializer.data_to_xml(
- [
- ('StoreLocation', cert.store_location),
- ('StoreName', cert.store_name),
- ('Thumbprint', cert.thumbprint)
- ]
+ certsetting = ET.Element("CertificateSetting")
+ certsettings.append(certsetting)
+
+ certsetting.append(AzureXmlSerializer.data_to_xml(
- [('StoreLocation', cert.store_location)]))
++ [('StoreLocation', cert.store_location)])
+ )
- xml += '</CertificateSetting>'
- xml += '</StoredCertificateSettings>'
+ AzureXmlSerializer.data_to_xml([('StoreName',
cert.store_name)], certsetting)
+ AzureXmlSerializer.data_to_xml([('Thumbprint',
cert.thumbprint)], certsetting)
- xml += AzureXmlSerializer.data_to_xml(
- [('AdminUsername', configuration.admin_user_name)]
+ AzureXmlSerializer.data_to_xml(
- [('AdminUsername', configuration.admin_user_name)], xml)
++ [('AdminUsername', configuration.admin_user_name)],
++ xml
+ )
return xml
@staticmethod
- def linux_configuration_to_xml(configuration):
- xml = AzureXmlSerializer.data_to_xml(
- [
- ('ConfigurationSetType',
configuration.configuration_set_type),
- ('HostName', configuration.host_name),
- ('UserName', configuration.user_name),
- ('UserPassword', configuration.user_password),
- (
- 'DisableSshPasswordAuthentication',
- configuration.disable_ssh_password_authentication,
- _lower
- )
- ]
+ def linux_configuration_to_xml(configuration, xml):
+ AzureXmlSerializer.data_to_xml([('ConfigurationSetType',
configuration.configuration_set_type)], xml)
+ AzureXmlSerializer.data_to_xml([('HostName',
configuration.host_name)], xml)
+ AzureXmlSerializer.data_to_xml([('UserName',
configuration.user_name)], xml)
+ AzureXmlSerializer.data_to_xml([('UserPassword',
configuration.user_password)], xml)
- AzureXmlSerializer.data_to_xml([('DisableSshPasswordAuthentication',
- configuration.disable_ssh_password_authentication,
- _lower)], xml)
++
++ AzureXmlSerializer.data_to_xml(
++ [('DisableSshPasswordAuthentication',
configuration.disable_ssh_password_authentication, _lower)],
++ xml
+ )
if configuration.ssh is not None:
- xml += '<SSH>'
- xml += '<PublicKeys>'
+ ssh = ET.Element("SSH")
+ pkeys = ET.Element("PublicKeys")
+ kpairs = ET.Element("KeyPairs")
+ ssh.append(pkeys)
+ ssh.append(kpairs)
+ xml.append(ssh)
for key in configuration.ssh.public_keys:
- xml += '<PublicKey>'
- xml += AzureXmlSerializer.data_to_xml(
- [
- ('Fingerprint', key.fingerprint),
- ('Path', key.path)
- ]
- )
- xml += '</PublicKey>'
-
- xml += '</PublicKeys>'
- xml += '<KeyPairs>'
+ pkey = ET.Element("PublicKey")
+ pkeys.append(pkey)
+ AzureXmlSerializer.data_to_xml([('Fingerprint',
key.fingerprint)], pkey)
+ AzureXmlSerializer.data_to_xml([('Path', key.path)], pkey)
for key in configuration.ssh.key_pairs:
- xml += '<KeyPair>'
- xml += AzureXmlSerializer.data_to_xml(
- [('Fingerprint', key.fingerprint),
- ('Path', key.path)])
- xml += '</KeyPair>'
-
- xml += '</KeyPairs>'
- xml += '</SSH>'
+ kpair = ET.Element("KeyPair")
+ kpairs.append(kpair)
+ AzureXmlSerializer.data_to_xml([('Fingerprint',
key.fingerprint)], kpair)
+ AzureXmlSerializer.data_to_xml([('Path', key.path)], kpair)
+
return xml
@staticmethod
- def network_configuration_to_xml(configuration):
- xml = AzureXmlSerializer.data_to_xml(
- [('ConfigurationSetType', configuration.configuration_set_type)]
+ def network_configuration_to_xml(configuration, xml):
+ AzureXmlSerializer.data_to_xml(
- [('ConfigurationSetType', configuration.configuration_set_type)],
xml)
++ [('ConfigurationSetType', configuration.configuration_set_type)],
++ xml
+ )
- xml += '<InputEndpoints>'
+
- iPoints = ET.Element("InputEndpoints")
- xml.append(iPoints)
++ input_endpoints = ET.Element("InputEndpoints")
++ xml.append(input_endpoints)
for endpoint in configuration.input_endpoints:
- xml += '<InputEndpoint>'
- xml += AzureXmlSerializer.data_to_xml(
- [
- (
- 'LoadBalancedEndpointSetName',
- endpoint.load_balanced_endpoint_set_name
- ),
- ('LocalPort', endpoint.local_port),
- ('Name', endpoint.name),
- ('Port', endpoint.port)
- ]
- iPoint = ET.Element("InputEndpoint")
- iPoints.append(iPoint)
++ input_endpoint = ET.Element("InputEndpoint")
++ input_endpoints.append(input_endpoint)
++
++ AzureXmlSerializer.data_to_xml(
++ [('LoadBalancedEndpointSetName',
endpoint.load_balanced_endpoint_set_name)],
++ input_endpoint
+ )
+
++ AzureXmlSerializer.data_to_xml([('LocalPort',
endpoint.local_port)], input_endpoint)
++ AzureXmlSerializer.data_to_xml([('Name', endpoint.name)],
input_endpoint)
++ AzureXmlSerializer.data_to_xml([('Port', endpoint.port)],
input_endpoint)
++
+ if (endpoint.load_balancer_probe.path or
- endpoint.load_balancer_probe.port or
- endpoint.load_balancer_probe.protocol):
- xml += '<LoadBalancerProbe>'
- xml += AzureXmlSerializer.data_to_xml(
- [
- ('Path', endpoint.load_balancer_probe.path),
- ('Port', endpoint.load_balancer_probe.port),
- ('Protocol', endpoint.load_balancer_probe.protocol)
- ]
++ endpoint.load_balancer_probe.port or
++ endpoint.load_balancer_probe.protocol):
++
++ load_balancer_probe = ET.Element("LoadBalancerProbe")
++ input_endpoint.append(load_balancer_probe)
++ AzureXmlSerializer.data_to_xml([('Path',
endpoint.load_balancer_probe.path)], load_balancer_probe)
++ AzureXmlSerializer.data_to_xml([('Port',
endpoint.load_balancer_probe.port)], load_balancer_probe)
++ AzureXmlSerializer.data_to_xml(
++ [('Protocol', endpoint.load_balancer_probe.protocol)],
++ load_balancer_probe
+ )
- xml += '</LoadBalancerProbe>'
-
- xml += AzureXmlSerializer.data_to_xml(
- [('Protocol', endpoint.protocol),
- ('EnableDirectServerReturn',
- endpoint.enable_direct_server_return,
- _lower)])
-
- xml += '</InputEndpoint>'
- xml += '</InputEndpoints>'
- xml += '<SubnetNames>'
- xml += ''.join(
- AzureXmlSerializer.data_to_xml([('SubnetName', name)])
- for name in configuration.subnet_names
- )
- xml += '</SubnetNames>'
++
++ AzureXmlSerializer.data_to_xml([('Protocol', endpoint.protocol)],
input_endpoint)
+ AzureXmlSerializer.data_to_xml(
- [('LoadBalancedEndpointSetName',
- endpoint.load_balanced_endpoint_set_name)], iPoint)
- AzureXmlSerializer.data_to_xml([('LocalPort',
endpoint.local_port)], iPoint)
- AzureXmlSerializer.data_to_xml([('Name', endpoint.name)], iPoint)
- AzureXmlSerializer.data_to_xml([('Port', endpoint.port)], iPoint)
-
- if endpoint.load_balancer_probe.path or\
- endpoint.load_balancer_probe.port or\
- endpoint.load_balancer_probe.protocol:
- lBalancerProbe = ET.Element("LoadBalancerProbe")
- iPoint.append(lBalancerProbe)
- AzureXmlSerializer.data_to_xml([('Path',
endpoint.load_balancer_probe.path)], lBalancerProbe)
- AzureXmlSerializer.data_to_xml([('Port',
endpoint.load_balancer_probe.port)], lBalancerProbe)
- AzureXmlSerializer.data_to_xml([('Protocol',
endpoint.load_balancer_probe.protocol)], lBalancerProbe)
-
-
- AzureXmlSerializer.data_to_xml([('Protocol', endpoint.protocol)],
iPoint)
- AzureXmlSerializer.data_to_xml([('EnableDirectServerReturn',
- endpoint.enable_direct_server_return,
- _lower)], iPoint)
-
- subnetNames = ET.Element("SubnetNames")
- xml.append(subnetNames)
++ [('EnableDirectServerReturn',
endpoint.enable_direct_server_return, _lower)],
++ input_endpoint
++ )
++
++ subnet_names = ET.Element("SubnetNames")
++ xml.append(subnet_names)
+ for name in configuration.subnet_names:
- AzureXmlSerializer.data_to_xml([('SubnetName', name)],
subnetNames)
++ AzureXmlSerializer.data_to_xml([('SubnetName', name)],
subnet_names)
+
return xml
@staticmethod
- def role_to_xml(availability_set_name, data_virtual_hard_disks,
- network_configuration_set, os_virtual_hard_disk,
role_name,
- role_size, role_type, system_configuration_set, xml):
+ def role_to_xml(availability_set_name,
+ data_virtual_hard_disks,
+ network_configuration_set,
+ os_virtual_hard_disk,
+ vm_image_name,
+ role_name,
+ role_size,
+ role_type,
- system_configuration_set):
- xml = AzureXmlSerializer.data_to_xml(
- [
- ('RoleName', role_name),
- ('RoleType', role_type)
- ]
- )
++ system_configuration_set,
++ xml):
- xml += '<ConfigurationSets>'
+ AzureXmlSerializer.data_to_xml([('RoleName', role_name)], xml)
+ AzureXmlSerializer.data_to_xml([('RoleType', role_type)], xml)
+
- configSets = ET.Element("ConfigurationSets")
- xml.append(configSets)
++ config_sets = ET.Element("ConfigurationSets")
++ xml.append(config_sets)
if system_configuration_set is not None:
- xml += '<ConfigurationSet>'
- configSet = ET.Element("ConfigurationSet")
- configSets.append(configSet)
++ config_set = ET.Element("ConfigurationSet")
++ config_sets.append(config_set)
+
if isinstance(system_configuration_set, WindowsConfigurationSet):
- xml += AzureXmlSerializer.windows_configuration_to_xml(
- system_configuration_set
+ AzureXmlSerializer.windows_configuration_to_xml(
- system_configuration_set, configSet)
++ system_configuration_set,
++ config_set
+ )
elif isinstance(system_configuration_set, LinuxConfigurationSet):
- xml += AzureXmlSerializer.linux_configuration_to_xml(
- system_configuration_set
+ AzureXmlSerializer.linux_configuration_to_xml(
- system_configuration_set, configSet)
-
++ system_configuration_set,
++ config_set
+ )
- xml += '</ConfigurationSet>'
if network_configuration_set is not None:
- xml += '<ConfigurationSet>'
- xml += AzureXmlSerializer.network_configuration_to_xml(
- network_configuration_set
- )
- xml += '</ConfigurationSet>'
- configSet = ET.Element("ConfigurationSet")
- configSets.append(configSet)
++ config_set = ET.Element("ConfigurationSet")
++ config_sets.append(config_set)
- xml += '</ConfigurationSets>'
+ AzureXmlSerializer.network_configuration_to_xml(
- network_configuration_set, configSet)
++ network_configuration_set,
++ config_set
++ )
if availability_set_name is not None:
- xml += AzureXmlSerializer.data_to_xml(
- [('AvailabilitySetName', availability_set_name)]
- )
+ AzureXmlSerializer.data_to_xml([('AvailabilitySetName',
availability_set_name)], xml)
if data_virtual_hard_disks is not None:
- xml += '<DataVirtualHardDisks>'
+ vhds = ET.Element("DataVirtualHardDisks")
+ xml.append(vhds)
+
for hd in data_virtual_hard_disks:
- xml += '<DataVirtualHardDisk>'
- xml += AzureXmlSerializer.data_to_xml(
- [
- ('HostCaching', hd.host_caching),
- ('DiskLabel', hd.disk_label),
- ('DiskName', hd.disk_name),
- ('Lun', hd.lun),
- ('LogicalDiskSizeInGB', hd.logical_disk_size_in_gb),
- ('MediaLink', hd.media_link)
- ]
- )
- xml += '</DataVirtualHardDisk>'
- xml += '</DataVirtualHardDisks>'
+ vhd = ET.Element("DataVirtualHardDisk")
+ vhds.append(vhd)
- AzureXmlSerializer.data_to_xml([('HostCaching',
hd.host_caching)],vhd)
- AzureXmlSerializer.data_to_xml([('DiskLabel',
hd.disk_label)],vhd)
- AzureXmlSerializer.data_to_xml([('DiskName',
hd.disk_name)],vhd)
- AzureXmlSerializer.data_to_xml([('Lun', hd.lun)],vhd)
- AzureXmlSerializer.data_to_xml([('LogicalDiskSizeInGB',
hd.logical_disk_size_in_gb)],vhd)
- AzureXmlSerializer.data_to_xml([('MediaLink',
hd.media_link)],vhd)
-
++ AzureXmlSerializer.data_to_xml([('HostCaching',
hd.host_caching)], vhd)
++ AzureXmlSerializer.data_to_xml([('DiskLabel',
hd.disk_label)], vhd)
++ AzureXmlSerializer.data_to_xml([('DiskName', hd.disk_name)],
vhd)
++ AzureXmlSerializer.data_to_xml([('Lun', hd.lun)], vhd)
++ AzureXmlSerializer.data_to_xml([('LogicalDiskSizeInGB',
hd.logical_disk_size_in_gb)], vhd)
++ AzureXmlSerializer.data_to_xml([('MediaLink',
hd.media_link)], vhd)
if os_virtual_hard_disk is not None:
- xml += '<OSVirtualHardDisk>'
- xml += AzureXmlSerializer.data_to_xml(
- [
- ('HostCaching', os_virtual_hard_disk.host_caching),
- ('DiskLabel', os_virtual_hard_disk.disk_label),
- ('DiskName', os_virtual_hard_disk.disk_name),
- ('MediaLink', os_virtual_hard_disk.media_link),
- ('SourceImageName',
os_virtual_hard_disk.source_image_name)
- ]
- )
- xml += '</OSVirtualHardDisk>'
+ hd = ET.Element("OSVirtualHardDisk")
+ xml.append(hd)
+ AzureXmlSerializer.data_to_xml([('HostCaching',
os_virtual_hard_disk.host_caching)], hd)
+ AzureXmlSerializer.data_to_xml([('DiskLabel',
os_virtual_hard_disk.disk_label)], hd)
+ AzureXmlSerializer.data_to_xml([('DiskName',
os_virtual_hard_disk.disk_name)], hd)
+ AzureXmlSerializer.data_to_xml([('MediaLink',
os_virtual_hard_disk.media_link)], hd)
+ AzureXmlSerializer.data_to_xml([('SourceImageName',
os_virtual_hard_disk.source_image_name)], hd)
+ if vm_image_name is not None:
+ xml += AzureXmlSerializer.data_to_xml([('VMImageName',
vm_image_name)])
+
if role_size is not None:
- xml += AzureXmlSerializer.data_to_xml([('RoleSize', role_size)])
+ AzureXmlSerializer.data_to_xml([('RoleSize', role_size)], xml)
return xml
@staticmethod
- def add_role_to_xml(role_name, system_configuration_set,
- os_virtual_hard_disk, role_type,
- network_configuration_set, availability_set_name,
- data_virtual_hard_disks, role_size):
+ def add_role_to_xml(role_name,
+ system_configuration_set,
+ os_virtual_hard_disk,
+ role_type,
+ network_configuration_set,
+ availability_set_name,
+ data_virtual_hard_disks,
+ vm_image_name,
+ role_size):
+ doc = AzureXmlSerializer.doc_from_xml('PersistentVMRole')
xml = AzureXmlSerializer.role_to_xml(
availability_set_name,
data_virtual_hard_disks,
@@@ -2220,86 -1891,70 +2221,91 @@@
role_name,
role_size,
role_type,
- system_configuration_set
- system_configuration_set, doc)
-
++ system_configuration_set,
++ doc
+ )
- return AzureXmlSerializer.doc_from_xml('PersistentVMRole', xml)
+ return ET.tostring(xml, "UTF-8").replace("\n", "")
@staticmethod
- def update_role_to_xml(role_name, os_virtual_hard_disk, role_type,
- network_configuration_set, availability_set_name,
- data_virtual_hard_disks, role_size):
+ def update_role_to_xml(role_name,
+ os_virtual_hard_disk,
+ role_type,
+ network_configuration_set,
+ availability_set_name,
- data_virtual_hard_disks,role_size):
- xml = AzureXmlSerializer.role_to_xml(
++ data_virtual_hard_disks,
++ vm_image_name,
++ role_size):
++
+ doc = AzureXmlSerializer.doc_from_xml('PersistentVMRole')
- xml = AzureXmlSerializer.role_to_xml(
++ AzureXmlSerializer.role_to_xml(
availability_set_name,
data_virtual_hard_disks,
network_configuration_set,
os_virtual_hard_disk,
++ vm_image_name,
role_name,
role_size,
role_type,
- None
- None, doc)
++ None,
++ doc
+ )
- return AzureXmlSerializer.doc_from_xml('PersistentVMRole', xml)
+
+ return ET.tostring(doc, "UTF-8").replace("\n", "")
@staticmethod
- def capture_role_to_xml(post_capture_action, target_image_name,
- target_image_label, provisioning_configuration):
+ def capture_role_to_xml(post_capture_action,
+ target_image_name,
+ target_image_label,
+ provisioning_configuration):
- xml = AzureXmlSerializer.data_to_xml(
- [
- ('OperationType', 'CaptureRoleOperation'),
- ('PostCaptureAction', post_capture_action)
- ]
- )
+ xml = AzureXmlSerializer.data_to_xml([('OperationType',
'CaptureRoleOperation')])
+ AzureXmlSerializer.data_to_xml([('PostCaptureAction',
post_capture_action)], xml)
if provisioning_configuration is not None:
- xml += '<ProvisioningConfiguration>'
- provConfig = ET.Element("ProvisioningConfiguration")
- xml.append(provConfig)
++ provisioning_config = ET.Element("ProvisioningConfiguration")
++ xml.append(provisioning_config)
++
if isinstance(provisioning_configuration,
WindowsConfigurationSet):
- xml += AzureXmlSerializer.windows_configuration_to_xml(
- provisioning_configuration
+ AzureXmlSerializer.windows_configuration_to_xml(
- provisioning_configuration, provConfig)
++ provisioning_configuration,
++ provisioning_config
+ )
elif isinstance(provisioning_configuration,
LinuxConfigurationSet):
- xml += AzureXmlSerializer.linux_configuration_to_xml(
- provisioning_configuration
+ AzureXmlSerializer.linux_configuration_to_xml(
- provisioning_configuration, provConfig)
-
++ provisioning_configuration,
++ provisioning_config
+ )
- xml += '</ProvisioningConfiguration>'
-
- xml += AzureXmlSerializer.data_to_xml(
- [
- ('TargetImageLabel', target_image_label),
- ('TargetImageName', target_image_name)
- ]
- )
- return AzureXmlSerializer.doc_from_xml('CaptureRoleOperation', xml)
- AzureXmlSerializer.data_to_xml([('TargetImageLabel',
target_image_label)],xml)
++ AzureXmlSerializer.data_to_xml([('TargetImageLabel',
target_image_label)], xml)
+ AzureXmlSerializer.data_to_xml([('TargetImageName',
target_image_name)], xml)
+ doc = AzureXmlSerializer.doc_from_xml('CaptureRoleOperation', xml)
+ return ET.tostring(doc, "UTF-8").replace("\n", "")
@staticmethod
- def virtual_machine_deployment_to_xml(deployment_name, deployment_slot,
- label, role_name,
+ def virtual_machine_deployment_to_xml(deployment_name,
+ deployment_slot,
+ label,
+ role_name,
system_configuration_set,
- os_virtual_hard_disk, role_type,
+ os_virtual_hard_disk,
+ role_type,
network_configuration_set,
availability_set_name,
- data_virtual_hard_disks, role_size,
- virtual_network_name):
+ data_virtual_hard_disks,
+ role_size,
+ virtual_network_name,
+ vm_image_name):
- xml = AzureXmlSerializer.data_to_xml(
- [
- ('Name', deployment_name),
- ('DeploymentSlot', deployment_slot),
- ('Label', label)
- ]
- )
- xml += '<RoleList>'
- xml += '<Role>'
- xml += AzureXmlSerializer.role_to_xml(
+
+ doc = AzureXmlSerializer.doc_from_xml('Deployment')
+ AzureXmlSerializer.data_to_xml([('Name', deployment_name)], doc)
+ AzureXmlSerializer.data_to_xml([('DeploymentSlot', deployment_slot)],
doc)
+ AzureXmlSerializer.data_to_xml([('Label', label)], doc)
+
- roleList = ET.Element("RoleList")
++ role_list = ET.Element("RoleList")
+ role = ET.Element("Role")
- roleList.append(role)
- doc.append(roleList)
++ role_list.append(role)
++ doc.append(role_list)
+
+ AzureXmlSerializer.role_to_xml(
availability_set_name,
data_virtual_hard_disks,
network_configuration_set,
@@@ -2308,27 -1962,24 +2314,28 @@@
role_name,
role_size,
role_type,
- system_configuration_set
- system_configuration_set, role)
-
-
++ system_configuration_set,
++ role
+ )
- xml += '</Role>'
- xml += '</RoleList>'
if virtual_network_name is not None:
- xml += AzureXmlSerializer.data_to_xml(
- [('VirtualNetworkName', virtual_network_name)]
- doc.append(AzureXmlSerializer.data_to_xml(
- [('VirtualNetworkName', virtual_network_name)]))
++ doc.append(
++ AzureXmlSerializer.data_to_xml(
++ [('VirtualNetworkName', virtual_network_name)]
++ )
+ )
- return AzureXmlSerializer.doc_from_xml('Deployment', xml)
+ return ET.tostring(doc, "UTF-8").replace("\n", "")
@staticmethod
- def data_to_xml(data):
+ def data_to_xml(data, xml=None):
- '''Creates an xml fragment from the specified data.
+ """
+ Creates an xml fragment from the specified data.
data: Array of tuples, where first: xml element name
second: xml element text
third: conversion function
- '''
+ """
- xml = ''
+
for element in data:
name = element[0]
val = element[1]
@@@ -2343,99 -1994,74 +2350,98 @@@
else:
text = _str(val)
- xml += ''.join(['<', name, '>', text, '</', name, '>'])
+ entry = ET.Element(name)
+ entry.text = text
+ if xml is not None:
+ xml.append(entry)
+ else:
+ return entry
+ return xml
@staticmethod
- def doc_from_xml(document_element_name, inner_xml):
+ def doc_from_xml(document_element_name, inner_xml=None):
- '''Wraps the specified xml in an xml root element with default azure
- namespaces'''
+ """
+ Wraps the specified xml in an xml root element with default azure
+ namespaces
+ """
- xml = ''.join(
- [
- '<',
- document_element_name,
- ' xmlns:i="http://www.w3.org/2001/XMLSchema-instance"',
- ' xmlns="http://schemas.microsoft.com/windowsazure">'
- ]
- )
- xml += inner_xml
- xml += ''.join(['</', document_element_name, '>'])
+ xml = ET.Element(document_element_name)
+ xml.attrib["xmlns:i"] = "http://www.w3.org/2001/XMLSchema-instance"
+ xml.attrib["xmlns"] = "http://schemas.microsoft.com/windowsazure"
+
- if(inner_xml != None):
++ if inner_xml is not None:
+ xml.append(inner_xml)
+
return xml
-
-
@staticmethod
def doc_from_data(document_element_name, data, extended_properties=None):
- xml = AzureXmlSerializer.data_to_xml(data)
- doc = AzureXmlSerializer.doc_from_xml(document_element_name)
++ doc = AzureXmlSerializer.doc_from_xml(document_element_name)
+ AzureXmlSerializer.data_to_xml(data, doc)
if extended_properties is not None:
- xml +=
AzureXmlSerializer.extended_properties_dict_to_xml_fragment(
- extended_properties
-
doc.append(AzureXmlSerializer.extended_properties_dict_to_xml_fragment(
- extended_properties))
-
++ doc.append(
++ AzureXmlSerializer.extended_properties_dict_to_xml_fragment(
++ extended_properties
++ )
+ )
- return AzureXmlSerializer.doc_from_xml(document_element_name, xml)
+
+ return ET.tostring(doc, "UTF-8").replace("\n", "")
@staticmethod
def extended_properties_dict_to_xml_fragment(extended_properties):
- xml = ''
+
if extended_properties is not None and len(extended_properties) > 0:
- xml += '<ExtendedProperties>'
+ xml = ET.Element("ExtendedProperties")
for key, val in extended_properties.items():
- xml += ''.join(
- [
- '<ExtendedProperty>',
- '<Name>',
- _str(key),
- '</Name>',
- '<Value>',
- _str(val),
- '</Value>',
- '</ExtendedProperty>'
- ]
- )
- xml += '</ExtendedProperties>'
- return xml
- eProp = ET.Element("ExtendedProperty")
++ extended_property = ET.Element("ExtendedProperty")
+ name = ET.Element("Name")
+ name.text = _str(key)
+ value = ET.Element("Value")
+ value.text = _str(val)
+
- eProp.append(name)
- eProp.append(value)
- xml.append(eProp)
++ extended_property.append(name)
++ extended_property.append(value)
++ xml.append(extended_property)
+
+ return xml
+
-
-"""Data Classes
+"""
+Data Classes
Borrowed from the Azure SDK for Python.
"""
-
class WindowsAzureData(object):
- ''' This is the base of data class.
- It is only used to check whether it is instance or not. '''
+ """
+ This is the base of data class.
+ It is only used to check whether it is instance or not.
+ """
pass
+
+class WindowsAzureDataTypedList(WindowsAzureData):
+
+ list_type = None
+ xml_element_name = None
+
+ def __init__(self):
+ self.items = _list_of(self.list_type, self.xml_element_name)
+
+ def __iter__(self):
+ return iter(self.items)
+
+ def __len__(self):
+ return len(self.items)
+
+ def __getitem__(self, index):
+ return self.items[index]
+
+
class OSVirtualHardDisk(WindowsAzureData):
- def __init__(self,
- source_image_name=None,
- media_link=None,
- host_caching=None,
- disk_label=None,
- disk_name=None):
+ def __init__(self, source_image_name=None, media_link=None,
+ host_caching=None, disk_label=None, disk_name=None):
self.source_image_name = source_image_name
self.media_link = media_link
self.host_caching = host_caching
@@@ -2702,9 -2344,21 +2708,11 @@@ class HostedServiceProperties(WindowsAz
self.date_created = u''
self.date_last_modified = u''
self.extended_properties = _dict_of(
- 'ExtendedProperty', 'Name', 'Value'
- 'ExtendedProperty', 'Name', 'Value')
-
-class Deployments(WindowsAzureData):
-
- def __init__(self):
- self.deployments = _list_of(Deployment)
-
- def __iter__(self):
- return iter(self.deployments)
-
- def __len__(self):
- return len(self.deployments)
++ 'ExtendedProperty',
++ 'Name',
++ 'Value'
+ )
- def __getitem__(self, index):
- return self.deployments[index]
class Deployment(WindowsAzureData):
@@@ -2728,15 -2382,7 +2736,17 @@@
self.created_time = u''
self.last_modified_time = u''
self.extended_properties = _dict_of(
- 'ExtendedProperty', 'Name', 'Value'
- 'ExtendedProperty', 'Name', 'Value')
++ 'ExtendedProperty',
++ 'Name',
++ 'Value'
+ )
+ self.virtual_ips = VirtualIPs()
+
+
+class Deployments(WindowsAzureDataTypedList):
+
+ list_type = Deployment
+
class UpgradeStatus(WindowsAzureData):
http://git-wip-us.apache.org/repos/asf/libcloud/blob/6048e2e0/libcloud/compute/types.py
----------------------------------------------------------------------
diff --cc libcloud/compute/types.py
index 398a269,4fbd513..f617df0
--- a/libcloud/compute/types.py
+++ b/libcloud/compute/types.py
@@@ -74,10 -74,6 +74,13 @@@ class Provider(object)
:cvar NEPHOSCALE: NephoScale driver
:cvar EXOSCALE: Exoscale driver.
:cvar IKOULA: Ikoula driver.
++<<<<<<< HEAD
+ :cvar OUTSCALE_SAS: Outscale SAS driver.
+ :cvar OUTSCALE_INC: Outscale INC driver.
+ :cvar PROFIT_BRICKS: ProfitBricks driver.
+ :cvar VULTR: vultr driver.
++=======
++>>>>>>> LIBCLOUD-556_azure_compute_driver
:cvar AZURE: Azure driver.
"""
AZURE = 'azure'