From 5e76b8a42b87ed71e8540b0ea6afa5c7396e6c53 Mon Sep 17 00:00:00 2001 From: Patrick Chanezon Date: Fri, 7 Nov 2014 15:13:34 -0800 Subject: [PATCH 1/2] added supprot for vip --- azure/__init__.py | 5 +- azure/servicemanagement/__init__.py | 268 +++++++--------------------- 2 files changed, 65 insertions(+), 208 deletions(-) diff --git a/azure/__init__.py b/azure/__init__.py index e23deb7e61cb..5d42bd6355df 100644 --- a/azure/__init__.py +++ b/azure/__init__.py @@ -301,9 +301,8 @@ def _to_datetime(strtime): 'persistent_vm_downtime_info': 'PersistentVMDowntimeInfo', 'copy_id': 'CopyId', 'os_state': 'OSState', - 'vm_image': 'VMImage', - 'vm_images': 'VMImages', - 'os_disk_configuration': 'OSDiskConfiguration', + 'public_ips': 'PublicIPs', + 'public_ip': 'PublicIP', } diff --git a/azure/servicemanagement/__init__.py b/azure/servicemanagement/__init__.py index d727ec588b46..b4f5b7c26e5b 100644 --- a/azure/servicemanagement/__init__.py +++ b/azure/servicemanagement/__init__.py @@ -83,7 +83,6 @@ def __init__(self): self.status_of_secondary = u'' self.last_geo_failover_time = u'' self.creation_time = u'' - self.account_type = u'' class StorageServiceKeys(WindowsAzureData): @@ -395,101 +394,6 @@ def __init__(self): self.default_win_rm_certificate_thumbprint = u'' -class CaptureRoleAsVMImage: - - def __init__(self, os_state=None, vm_image_name=None, vm_image_label=None, - description=None, language=None, image_family=None, - recommended_vm_size=None): - self.os_state = os_state - self.vm_image_name = vm_image_name - self.vm_image_label = vm_image_label - self.description = description - self.language = language - self.image_family = image_family - self.recommended_vm_size = recommended_vm_size - - -class OSDiskConfiguration(WindowsAzureData): - - def __init__(self): - self.name = None - self.host_caching = None - self.os_state = None - self.os = None - self.media_link = None - self.logical_disk_size_in_gb = -1 - - -class DataDiskConfigurations(WindowsAzureData): - - def __init__(self): - self.data_disk_configurations = _list_of(DataDiskConfiguration) - - def __iter__(self): - return iter(self.data_disk_configurations) - - def __len__(self): - return len(self.data_disk_configurations) - - def __getitem__(self, index): - return self.data_disk_configurations[index] - - -class DataDiskConfiguration(WindowsAzureData): - - def __init__(self): - self.name = None - self.host_caching = None - self.lun = -1 - self.media_link = None - self.logical_disk_size_in_gb = -1 - - -class VMImages(WindowsAzureData): - - def __init__(self): - self.vm_images = _list_of(VMImage) - - def __iter__(self): - return iter(self.vm_images) - - def __len__(self): - return len(self.vm_images) - - def __getitem__(self, index): - return self.vm_images[index] - - -class VMImage(WindowsAzureData): - - def __init__(self, name=None, label=None, description=None): - self.name = name - self.label = label - self.category = None # read-only - self.description = description - self.os_disk_configuration = OSDiskConfiguration() - self.data_disk_configurations = DataDiskConfigurations() - self.service_name = None # read-only - self.deployment_name = None # read-only - self.role_name = None # read-only - self.location = None # read-only - self.affinity_group = None # read-only - self.created_time = None # read-only - self.modified_time = None # read-only - self.language = None - self.image_family = None - self.recommended_vm_size = None - self.is_premium = False # read-only - self.eula = None - self.icon_uri = None - self.small_icon_uri = None - self.privacy_uri = None - self.publisher_name = None # read-only - self.published_date = None - self.show_in_gui = False - self.pricing_detail_link = None # read-only - - class PersistentVMDowntimeInfo(WindowsAzureData): def __init__(self): @@ -797,7 +701,27 @@ def __init__(self): self.role_type = u'' self.input_endpoints = ConfigurationSetInputEndpoints() self.subnet_names = _scalar_list_of(str, 'SubnetName') + self.public_ips = PublicIPs() + +class PublicIPs(WindowsAzureData): + + def __init__(self): + self.public_ips = _list_of(PublicIP) + + def __iter__(self): + return iter(self.public_ips) + + def __len__(self): + return len(self.public_ips) + + def __getitem__(self, index): + return self.public_ips[index] + +class PublicIP(WindowsAzureData): + def __init__(self, name=u''): + self.name = name + self.idle_timeout_in_minutes = 4 class ConfigurationSetInputEndpoints(WindowsAzureData): @@ -1457,6 +1381,28 @@ def __init__(self): self.max_size_bytes = 0 +def _update_management_header(request): + ''' Add additional headers for management. ''' + + if request.method in ['PUT', 'POST', 'MERGE', 'DELETE']: + request.headers.append(('Content-Length', str(len(request.body)))) + + # append additional headers base on the service + request.headers.append(('x-ms-version', X_MS_VERSION)) + + # if it is not GET or HEAD request, must set content-type. + if not request.method in ['GET', 'HEAD']: + for name, _ in request.headers: + if 'content-type' == name.lower(): + break + else: + request.headers.append( + ('Content-Type', + 'application/atom+xml;type=entry;charset=utf-8')) + + return request.headers + + def _parse_response_for_async_op(response): ''' Extracts request id from response header. ''' @@ -1486,32 +1432,28 @@ class _XmlSerializer(object): @staticmethod def create_storage_service_input_to_xml(service_name, description, label, affinity_group, location, - account_type, + geo_replication_enabled, extended_properties): - xml = _XmlSerializer.data_to_xml( + return _XmlSerializer.doc_from_data( + 'CreateStorageServiceInput', [('ServiceName', service_name), ('Description', description), ('Label', label, _encode_base64), ('AffinityGroup', affinity_group), - ('Location', location)]) - if extended_properties is not None: - xml += _XmlSerializer.extended_properties_dict_to_xml_fragment( - extended_properties) - xml += _XmlSerializer.data_to_xml([('AccountType', account_type)]) - return _XmlSerializer.doc_from_xml('CreateStorageServiceInput', xml) + ('Location', location), + ('GeoReplicationEnabled', geo_replication_enabled, _lower)], + extended_properties) @staticmethod def update_storage_service_input_to_xml(description, label, - account_type, + geo_replication_enabled, extended_properties): - xml = _XmlSerializer.data_to_xml( + return _XmlSerializer.doc_from_data( + 'UpdateStorageServiceInput', [('Description', description), - ('Label', label, _encode_base64)]) - if extended_properties is not None: - xml += _XmlSerializer.extended_properties_dict_to_xml_fragment( - extended_properties) - xml += _XmlSerializer.data_to_xml([('AccountType', account_type)]) - return _XmlSerializer.doc_from_xml('UpdateStorageServiceInput', xml) + ('Label', label, _encode_base64), + ('GeoReplicationEnabled', geo_replication_enabled, _lower)], + extended_properties) @staticmethod def regenerate_keys_to_xml(key_type): @@ -1832,6 +1774,15 @@ def network_configuration_to_xml(configuration): for name in configuration.subnet_names: xml += _XmlSerializer.data_to_xml([('SubnetName', name)]) xml += '' + if configuration.public_ips: + xml += '' + for public_ip in configuration.public_ips: + xml += '' + xml += _XmlSerializer.data_to_xml( + [('Name', public_ip.name), + ('IdleTimeoutInMinutes', public_ip.idle_timeout_in_minutes)]) + xml += '' + xml += '' return xml @staticmethod @@ -1982,99 +1933,6 @@ def virtual_machine_deployment_to_xml(deployment_name, deployment_slot, return _XmlSerializer.doc_from_xml('Deployment', xml) - @staticmethod - def capture_vm_image_to_xml(options): - return _XmlSerializer.doc_from_data( - 'CaptureRoleAsVMImageOperation ', - [('OperationType', 'CaptureRoleAsVMImageOperation'), - ('OSState', options.os_state), - ('VMImageName', options.vm_image_name), - ('VMImageLabel', options.vm_image_label), - ('Description', options.description), - ('Language', options.language), - ('ImageFamily', options.image_family), - ('RecommendedVMSize', options.recommended_vm_size)]) - - @staticmethod - def create_vm_image_to_xml(image): - xml = '' - - xml += _XmlSerializer.data_to_xml( - [('Name', image.name), - ('Label', image.label), - ('Description', image.description)]) - - os_disk = image.os_disk_configuration - xml += '' - xml += _XmlSerializer.data_to_xml( - [('HostCaching', os_disk.host_caching), - ('OSState', os_disk.os_state), - ('OS', os_disk.os), - ('MediaLink', os_disk.media_link)]) - xml += '' - - if image.data_disk_configurations: - xml += '' - for data_disk in image.data_disk_configurations: - xml += '' - xml += _XmlSerializer.data_to_xml( - [('HostCaching', data_disk.host_caching), - ('Lun', data_disk.lun), - ('MediaLink', data_disk.media_link), - ('LogicalDiskSizeInGB', data_disk.logical_disk_size_in_gb)]) - xml += '' - xml += '' - - xml += _XmlSerializer.data_to_xml( - [('Language', image.language), - ('ImageFamily', image.image_family), - ('RecommendedVMSize', image.recommended_vm_size), - ('Eula', image.eula), - ('IconUri', image.icon_uri), - ('SmallIconUri', image.small_icon_uri), - ('PrivacyUri', image.privacy_uri), - ('PublishedDate', image.published_date), - ('ShowInGui', image.show_in_gui)]) - - xml += '' - - return _XmlSerializer.doc_from_xml('VMImages', xml) - - @staticmethod - def update_vm_image_to_xml(image): - xml = _XmlSerializer.data_to_xml( - [('Label', image.label)]) - - os_disk = image.os_disk_configuration - xml += '' - xml += _XmlSerializer.data_to_xml( - [('HostCaching', os_disk.host_caching)]) - xml += '' - - xml += '' - for data_disk in image.data_disk_configurations: - xml += '' - xml += _XmlSerializer.data_to_xml( - [('Name', data_disk.name), - ('HostCaching', data_disk.host_caching), - ('Lun', data_disk.lun)]) - xml += '' - xml += '' - - xml += _XmlSerializer.data_to_xml( - [('Description', image.description), - ('Language', image.language), - ('ImageFamily', image.image_family), - ('RecommendedVMSize', image.recommended_vm_size), - ('Eula', image.eula), - ('IconUri', image.icon_uri), - ('SmallIconUri', image.small_icon_uri), - ('PrivacyUri', image.privacy_uri), - ('PublishedDate', image.published_date), - ('ShowInGui', image.show_in_gui)]) - - return _XmlSerializer.doc_from_xml('VMImage', xml) - @staticmethod def create_website_to_xml(webspace_name, website_name, geo_region, plan, host_names, compute_mode, server_farm, site_mode): From f8973fcca86f01f49b2439463d921cf9227c6383 Mon Sep 17 00:00:00 2001 From: Patrick Chanezon Date: Fri, 7 Nov 2014 16:42:01 -0800 Subject: [PATCH 2/2] added support for getting vip in get_deployment_by_name --- azure/servicemanagement/__init__.py | 352 ++++++++++++++++++++++++---- 1 file changed, 308 insertions(+), 44 deletions(-) diff --git a/azure/servicemanagement/__init__.py b/azure/servicemanagement/__init__.py index b4f5b7c26e5b..d02807212801 100644 --- a/azure/servicemanagement/__init__.py +++ b/azure/servicemanagement/__init__.py @@ -83,6 +83,7 @@ def __init__(self): self.status_of_secondary = u'' self.last_geo_failover_time = u'' self.creation_time = u'' + self.account_type = u'' class StorageServiceKeys(WindowsAzureData): @@ -307,7 +308,7 @@ def __init__(self): self.power_state = u'' self.fqdn = u'' self.host_name = u'' - + self.public_ips = PublicIPs() class InstanceEndpoints(WindowsAzureData): @@ -394,6 +395,188 @@ def __init__(self): self.default_win_rm_certificate_thumbprint = u'' +class CaptureRoleAsVMImage: + + def __init__(self, os_state=None, vm_image_name=None, vm_image_label=None, + description=None, language=None, image_family=None, + recommended_vm_size=None): + self.os_state = os_state + self.vm_image_name = vm_image_name + self.vm_image_label = vm_image_label + self.description = description + self.language = language + self.image_family = image_family + self.recommended_vm_size = recommended_vm_size + + +class OSDiskConfiguration(WindowsAzureData): + + def __init__(self): + self.name = None + self.host_caching = None + self.os_state = None + self.os = None + self.media_link = None + self.logical_disk_size_in_gb = -1 + + +class DataDiskConfigurations(WindowsAzureData): + + def __init__(self): + self.data_disk_configurations = _list_of(DataDiskConfiguration) + + def __iter__(self): + return iter(self.data_disk_configurations) + + def __len__(self): + return len(self.data_disk_configurations) + + def __getitem__(self, index): + return self.data_disk_configurations[index] + + +class DataDiskConfiguration(WindowsAzureData): + + def __init__(self): + self.name = None + self.host_caching = None + self.lun = -1 + self.media_link = None + self.logical_disk_size_in_gb = -1 + + +class VMImages(WindowsAzureData): + + def __init__(self): + self.vm_images = _list_of(VMImage) + + def __iter__(self): + return iter(self.vm_images) + + def __len__(self): + return len(self.vm_images) + + def __getitem__(self, index): + return self.vm_images[index] + + +class VMImage(WindowsAzureData): + + def __init__(self, name=None, label=None, description=None): + self.name = name + self.label = label + self.category = None # read-only + self.description = description + self.os_disk_configuration = OSDiskConfiguration() + self.data_disk_configurations = DataDiskConfigurations() + self.service_name = None # read-only + self.deployment_name = None # read-only + self.role_name = None # read-only + self.location = None # read-only + self.affinity_group = None # read-only + self.created_time = None # read-only + self.modified_time = None # read-only + self.language = None + self.image_family = None + self.recommended_vm_size = None + self.is_premium = False # read-only + self.eula = None + self.icon_uri = None + self.small_icon_uri = None + self.privacy_uri = None + self.publisher_name = None # read-only + self.published_date = None + self.show_in_gui = False + self.pricing_detail_link = None # read-only + + +class ResourceExtensions(WindowsAzureData): + + def __init__(self): + self.resource_extensions = _list_of(ResourceExtension) + + def __iter__(self): + return iter(self.resource_extensions) + + def __len__(self): + return len(self.resource_extensions) + + def __getitem__(self, index): + return self.resource_extensions[index] + + +class ResourceExtension(WindowsAzureData): + + def __init__(self): + self.publisher = u'' + self.name = u'' + self.version = u'' + self.label = u'' + self.description = u'' + self.public_configuration_schema = u'' + self.private_configuration_schema = u'' + self.sample_config = u'' + self.replication_completed = False + self.eula = u'' + self.privacy_uri = u'' + self.homepage_uri = u'' + self.is_json_extension = False + self.is_internal_extension = False + self.disallow_major_version_upgrade = False + self.company_name = u'' + self.supported_os = u'' + self.published_date = u'' + + +class ResourceExtensionParameterValues(WindowsAzureData): + + def __init__(self): + self.resource_extension_parameter_values = _list_of(ResourceExtensionParameterValue) + + def __iter__(self): + return iter(self.resource_extension_parameter_values) + + def __len__(self): + return len(self.resource_extension_parameter_values) + + def __getitem__(self, index): + return self.resource_extension_parameter_values[index] + + +class ResourceExtensionParameterValue(WindowsAzureData): + + def __init__(self): + self.key = u'' + self.value = u'' + self.type = u'' + + +class ResourceExtensionReferences(WindowsAzureData): + + def __init__(self): + self.resource_extension_references = _list_of(ResourceExtensionReference) + + def __iter__(self): + return iter(self.resource_extension_references) + + def __len__(self): + return len(self.resource_extension_references) + + def __getitem__(self, index): + return self.resource_extension_references[index] + + +class ResourceExtensionReference(WindowsAzureData): + + def __init__(self): + self.reference_name = u'' + self.publisher = u'' + self.version = u'' + self.resource_extension_parameter_values = ResourceExtensionParameterValues() + self.state = u'' + self.certificates = Certificates() + + class PersistentVMDowntimeInfo(WindowsAzureData): def __init__(self): @@ -694,15 +877,6 @@ def __getitem__(self, index): return self.configuration_sets[index] -class ConfigurationSet(WindowsAzureData): - - def __init__(self): - self.configuration_set_type = u'NetworkConfiguration' - self.role_type = u'' - self.input_endpoints = ConfigurationSetInputEndpoints() - self.subnet_names = _scalar_list_of(str, 'SubnetName') - self.public_ips = PublicIPs() - class PublicIPs(WindowsAzureData): def __init__(self): @@ -717,11 +891,24 @@ def __len__(self): def __getitem__(self, index): return self.public_ips[index] + class PublicIP(WindowsAzureData): def __init__(self, name=u''): self.name = name self.idle_timeout_in_minutes = 4 + self.address = None + + +class ConfigurationSet(WindowsAzureData): + + def __init__(self): + self.configuration_set_type = u'NetworkConfiguration' + self.role_type = u'' + self.input_endpoints = ConfigurationSetInputEndpoints() + self.subnet_names = _scalar_list_of(str, 'SubnetName') + self.public_ips = PublicIPs() + class ConfigurationSetInputEndpoints(WindowsAzureData): @@ -1381,28 +1568,6 @@ def __init__(self): self.max_size_bytes = 0 -def _update_management_header(request): - ''' Add additional headers for management. ''' - - if request.method in ['PUT', 'POST', 'MERGE', 'DELETE']: - request.headers.append(('Content-Length', str(len(request.body)))) - - # append additional headers base on the service - request.headers.append(('x-ms-version', X_MS_VERSION)) - - # if it is not GET or HEAD request, must set content-type. - if not request.method in ['GET', 'HEAD']: - for name, _ in request.headers: - if 'content-type' == name.lower(): - break - else: - request.headers.append( - ('Content-Type', - 'application/atom+xml;type=entry;charset=utf-8')) - - return request.headers - - def _parse_response_for_async_op(response): ''' Extracts request id from response header. ''' @@ -1432,28 +1597,32 @@ class _XmlSerializer(object): @staticmethod def create_storage_service_input_to_xml(service_name, description, label, affinity_group, location, - geo_replication_enabled, + account_type, extended_properties): - return _XmlSerializer.doc_from_data( - 'CreateStorageServiceInput', + xml = _XmlSerializer.data_to_xml( [('ServiceName', service_name), ('Description', description), ('Label', label, _encode_base64), ('AffinityGroup', affinity_group), - ('Location', location), - ('GeoReplicationEnabled', geo_replication_enabled, _lower)], - extended_properties) + ('Location', location)]) + if extended_properties is not None: + xml += _XmlSerializer.extended_properties_dict_to_xml_fragment( + extended_properties) + xml += _XmlSerializer.data_to_xml([('AccountType', account_type)]) + return _XmlSerializer.doc_from_xml('CreateStorageServiceInput', xml) @staticmethod def update_storage_service_input_to_xml(description, label, - geo_replication_enabled, + account_type, extended_properties): - return _XmlSerializer.doc_from_data( - 'UpdateStorageServiceInput', + xml = _XmlSerializer.data_to_xml( [('Description', description), - ('Label', label, _encode_base64), - ('GeoReplicationEnabled', geo_replication_enabled, _lower)], - extended_properties) + ('Label', label, _encode_base64)]) + if extended_properties is not None: + xml += _XmlSerializer.extended_properties_dict_to_xml_fragment( + extended_properties) + xml += _XmlSerializer.data_to_xml([('AccountType', account_type)]) + return _XmlSerializer.doc_from_xml('UpdateStorageServiceInput', xml) @staticmethod def regenerate_keys_to_xml(key_type): @@ -1774,6 +1943,7 @@ def network_configuration_to_xml(configuration): for name in configuration.subnet_names: xml += _XmlSerializer.data_to_xml([('SubnetName', name)]) xml += '' + if configuration.public_ips: xml += '' for public_ip in configuration.public_ips: @@ -1783,6 +1953,7 @@ def network_configuration_to_xml(configuration): ('IdleTimeoutInMinutes', public_ip.idle_timeout_in_minutes)]) xml += '' xml += '' + return xml @staticmethod @@ -1933,6 +2104,99 @@ def virtual_machine_deployment_to_xml(deployment_name, deployment_slot, return _XmlSerializer.doc_from_xml('Deployment', xml) + @staticmethod + def capture_vm_image_to_xml(options): + return _XmlSerializer.doc_from_data( + 'CaptureRoleAsVMImageOperation ', + [('OperationType', 'CaptureRoleAsVMImageOperation'), + ('OSState', options.os_state), + ('VMImageName', options.vm_image_name), + ('VMImageLabel', options.vm_image_label), + ('Description', options.description), + ('Language', options.language), + ('ImageFamily', options.image_family), + ('RecommendedVMSize', options.recommended_vm_size)]) + + @staticmethod + def create_vm_image_to_xml(image): + xml = '' + + xml += _XmlSerializer.data_to_xml( + [('Name', image.name), + ('Label', image.label), + ('Description', image.description)]) + + os_disk = image.os_disk_configuration + xml += '' + xml += _XmlSerializer.data_to_xml( + [('HostCaching', os_disk.host_caching), + ('OSState', os_disk.os_state), + ('OS', os_disk.os), + ('MediaLink', os_disk.media_link)]) + xml += '' + + if image.data_disk_configurations: + xml += '' + for data_disk in image.data_disk_configurations: + xml += '' + xml += _XmlSerializer.data_to_xml( + [('HostCaching', data_disk.host_caching), + ('Lun', data_disk.lun), + ('MediaLink', data_disk.media_link), + ('LogicalDiskSizeInGB', data_disk.logical_disk_size_in_gb)]) + xml += '' + xml += '' + + xml += _XmlSerializer.data_to_xml( + [('Language', image.language), + ('ImageFamily', image.image_family), + ('RecommendedVMSize', image.recommended_vm_size), + ('Eula', image.eula), + ('IconUri', image.icon_uri), + ('SmallIconUri', image.small_icon_uri), + ('PrivacyUri', image.privacy_uri), + ('PublishedDate', image.published_date), + ('ShowInGui', image.show_in_gui)]) + + xml += '' + + return _XmlSerializer.doc_from_xml('VMImages', xml) + + @staticmethod + def update_vm_image_to_xml(image): + xml = _XmlSerializer.data_to_xml( + [('Label', image.label)]) + + os_disk = image.os_disk_configuration + xml += '' + xml += _XmlSerializer.data_to_xml( + [('HostCaching', os_disk.host_caching)]) + xml += '' + + xml += '' + for data_disk in image.data_disk_configurations: + xml += '' + xml += _XmlSerializer.data_to_xml( + [('Name', data_disk.name), + ('HostCaching', data_disk.host_caching), + ('Lun', data_disk.lun)]) + xml += '' + xml += '' + + xml += _XmlSerializer.data_to_xml( + [('Description', image.description), + ('Language', image.language), + ('ImageFamily', image.image_family), + ('RecommendedVMSize', image.recommended_vm_size), + ('Eula', image.eula), + ('IconUri', image.icon_uri), + ('SmallIconUri', image.small_icon_uri), + ('PrivacyUri', image.privacy_uri), + ('PublishedDate', image.published_date), + ('ShowInGui', image.show_in_gui)]) + + return _XmlSerializer.doc_from_xml('VMImage', xml) + @staticmethod def create_website_to_xml(webspace_name, website_name, geo_region, plan, host_names, compute_mode, server_farm, site_mode):