本文整理汇总了Python中azure.servicemanagement.ServiceManagementService.capture_vm_image方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManagementService.capture_vm_image方法的具体用法?Python ServiceManagementService.capture_vm_image怎么用?Python ServiceManagementService.capture_vm_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicemanagement.ServiceManagementService
的用法示例。
在下文中一共展示了ServiceManagementService.capture_vm_image方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import capture_vm_image [as 别名]
#.........这里部分代码省略.........
return vm_list
def power_on(self, service_name, vm_name):
resp = self.sms.start_role(service_name, vm_name, vm_name)
return resp.request_id
def power_off(self, service_name, vm_name):
resp = self.sms.shutdown_role(service_name, vm_name, vm_name)
return resp.request_id
def soft_reboot(self, service_name, vm_name):
resp = self.sms.restart_role(service_name, vm_name, vm_name)
return resp.request_id
def hard_reboot(self, service_name, vm_name):
resp = self.sms.reboot_role_instance(service_name, vm_name, vm_name)
return resp.request_id
def attach_volume(self, service_name, vm_name, size, lun):
disk_name = utils.generate_random_name(5, vm_name)
media_link = self._get_media_link(vm_name, disk_name)
self.sms.add_data_disk(service_name,
vm_name,
vm_name,
lun,
host_caching='ReadWrite',
media_link=media_link,
disk_name=disk_name,
logical_disk_size_in_gb=size)
def detach_volume(self, service_name, vm_name, lun):
self.sms.delete_data_disk(service_name, vm_name, vm_name, lun, True)
def get_available_lun(self, service_name, vm_name):
try:
role = self.sms.get_role(service_name, vm_name, vm_name)
except Exception:
return 0
disks = role.data_virtual_hard_disks
luns = [disk.lun for disk in disks].sort()
for i in range(1, 16):
if i not in luns:
return i
return None
def snapshot(self, service_name, vm_name, image_id, snanshot_name):
image_desc = 'Snapshot for image %s' % vm_name
image = CaptureRoleAsVMImage('Specialized', snanshot_name,
image_id, image_desc, 'english')
resp = self.sms.capture_vm_image(service_name, vm_name, vm_name, image)
self.sms.wait_for_operation_status(resp.request_id)
def _get_media_link(self, vm_name, filename=None, storage_account=None):
""" The MediaLink should be constructed as:
https://<storageAccount>.<blobLink>/<blobContainer>/<filename>.vhd
"""
if not storage_account:
storage_account = self._get_or_create_storage_account()
container = self.container
filename = vm_name if filename is None else filename
blob = vm_name + '-' + filename + '.vhd'
media_link = "http://%s.%s/%s/%s" % (storage_account,
self.windows_blob_url,
container, blob)
return media_link
def _get_or_create_storage_account(self):
account_list = self.sms.list_storage_accounts()
if account_list:
return account_list[-1].service_name
storage_account = utils.generate_random_name(10)
description = "Storage account %s description" % storage_account
label = storage_account + 'label'
self.sms.create_storage_account(storage_account,
description,
label,
location=self.location)
return storage_account
def _wait_for_operation(self, request_id, timeout=3000,
failure_callback=None,
failure_callback_kwargs=None):
try:
self.sms.wait_for_operation_status(request_id, timeout=timeout)
except Exception as ex:
if failure_callback and failure_callback_kwargs:
failure_callback(**failure_callback_kwargs)
raise ex