Skip to content

Commit

Permalink
Update msazure to avoid azure.mgmt.*.models imports where deprecated.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshriver committed Jul 15, 2019
1 parent 47123c8 commit 48fa1de
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions wrapanapi/systems/msazure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
from azure.common.credentials import ServicePrincipalCredentials
from azure.common.exceptions import CloudError
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.compute.models import (DiskCreateOptionTypes, VirtualHardDisk,
VirtualMachineCaptureParameters,
VirtualMachineSizeTypes)
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.network.models import NetworkSecurityGroup, SecurityRule
from azure.mgmt.resource import ResourceManagementClient, SubscriptionClient
Expand Down Expand Up @@ -256,17 +253,23 @@ def suspend(self):

def capture(self, container, image_name, overwrite_vhds=True):
self.logger.info("Attempting to Capture Azure VM '%s'", self.name)
params = VirtualMachineCaptureParameters(vhd_prefix=image_name,
destination_container_name=container,
overwrite_vhds=overwrite_vhds)
# vm capture parameters resolved to correct class by API, url below to doc
# https://github.com/Azure/azure-sdk-for-python/wiki/
# Direct-access-to-%22models%22-is-deprecated
params = ComputeManagementClient.models().VirtualMachineCaptureParameters(
vhd_prefix=image_name,
destination_container_name=container,
overwrite_vhds=overwrite_vhds
)
self.stop()
self.logger.info("Generalizing VM '%s'", self.name)
operation = self._api.generalize(
resource_group_name=self._resource_group, vm_name=self.name)
operation = self._api.generalize(resource_group_name=self._resource_group,
vm_name=self.name)
self._wait_on_operation(operation)
self.logger.info("Capturing VM '%s'", self.name)
operation = self._api.capture(
resource_group_name=self._resource_group, vm_name=self.name, parameters=params)
operation = self._api.capture(resource_group_name=self._resource_group,
vm_name=self.name,
parameters=params)
return self._wait_on_operation(operation)

def get_vhd_uri(self):
Expand Down Expand Up @@ -347,7 +350,7 @@ def deploy(self, vm_name, **vm_settings):
vnet_name = vm_settings['virtual_net']

# checking whether passed vm size value is correct
vm_sizes = {t.value for t in VirtualMachineSizeTypes}
vm_sizes = {t.value for t in ComputeManagementClient.models().VirtualMachineSizeTypes}
vm_size = vm_settings['vm_size']
if vm_size not in vm_sizes:
raise ValueError("wrong vm size %s passed. possible size: %s", vm_size,
Expand Down Expand Up @@ -441,8 +444,9 @@ def _create_or_update_nic():
'os_disk': {
'os_type': 'Linux', # TODO: why is this hardcoded?
'name': vm_name,
'vhd': VirtualHardDisk(uri=image_uri + ".vhd"),
'create_option': DiskCreateOptionTypes.attach,
'vhd': ComputeManagementClient.models().VirtualHardDisk(uri='{}.vhd'
.format(image_uri)),
'create_option': ComputeManagementClient.models().DiskCreateOptionTypes.attach,
}
},
'network_profile': {
Expand Down

0 comments on commit 48fa1de

Please sign in to comment.