本文整理汇总了Python中azure.servicemanagement.ServiceManagementService.get_deployment_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManagementService.get_deployment_by_name方法的具体用法?Python ServiceManagementService.get_deployment_by_name怎么用?Python ServiceManagementService.get_deployment_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicemanagement.ServiceManagementService
的用法示例。
在下文中一共展示了ServiceManagementService.get_deployment_by_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_deployment_by_name [as 别名]
#.........这里部分代码省略.........
# Hard disk for the OS
os_hd = OSVirtualHardDisk(image_name, media_link)
# Create vm
result = self.sms.create_virtual_machine_deployment(
service_name=service_name, deployment_name=vm_name,
deployment_slot='production', label=vm_name,
role_name=vm_name, system_config=linux_config,
os_virtual_hard_disk=os_hd,
role_size=role_size
)
request_id = result.request_id
return {
'request_id': request_id,
'media_link': media_link
}
def delete_virtual_machine(self, service_name, vm_name):
resp = self.sms.delete_deployment(service_name, vm_name, True)
self.sms.wait_for_operation_status(resp.request_id)
result = self.sms.delete_hosted_service(service_name)
return result
def generate_cloud_service_name(self, os_user=None, random=False):
if random:
return utils.generate_random_name(10)
return '-'.join((os_user, utils.generate_random_name(6)))
@utils.resource_not_found_handler
def get_virtual_machine_info(self, service_name, vm_name):
vm_info = {}
deploy_info = self.sms.get_deployment_by_name(service_name, vm_name)
if deploy_info and deploy_info.role_instance_list:
vm_info = deploy_info.role_instance_list[0].__dict__
return vm_info
def list_virtual_machines(self):
vm_list = []
services = self.sms.list_hosted_services()
for service in services:
deploys = service.deployments
if deploys and deploys.role_instance_list:
vm_name = deploys.role_instance_list[0].instance_name
vm_list.append(vm_name)
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
示例2: Deployment
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_deployment_by_name [as 别名]
class Deployment(object):
"""
Helper class to handle deployment of the web site.
"""
def __init__(self, config):
self.config = config
self.sms = ServiceManagementService(config.getAzureSubscriptionId(), config.getAzureCertificatePath())
self.sbms = ServiceBusManagementService(config.getAzureSubscriptionId(), config.getAzureCertificatePath())
@staticmethod
def _resource_exists(get_resource):
"""
Helper to check for the existence of a resource in Azure.
get_resource: Parameter-less function to invoke in order to get the resource. The resource
is assumed to exist when the call to get_resource() returns a value that is not None.
If the call to get_resource() returns None or throws a WindowsAzureMissingResourceError
exception, then it is assumed that the resource does not exist.
Returns: A boolean value which is True if the resource exists.
"""
resource = None
try:
resource = get_resource()
except WindowsAzureMissingResourceError:
pass
return resource is not None
def _wait_for_operation_success(self, request_id, timeout=600, wait=5):
"""
Waits for an asynchronous Azure operation to finish.
request_id: The ID of the request to track.
timeout: Maximum duration (in seconds) allowed for the operation to complete.
wait: Wait time (in seconds) between consecutive calls to fetch the latest operation status.
"""
result = self.sms.get_operation_status(request_id)
start_time = time.time()
max_time = start_time + timeout
now = start_time
while result.status == 'InProgress':
if now >= max_time:
raise Exception("Operation did not finish within the expected timeout")
logger.info('Waiting for operation to finish (last_status=%s wait_so_far=%s)',
result.status, round(now - start_time, 1))
time_to_wait = max(0.0, min(max_time - now, wait))
time.sleep(time_to_wait)
result = self.sms.get_operation_status(request_id)
now = time.time()
if result.status != 'Succeeded':
raise Exception("Operation terminated but it did not succeed.")
def _wait_for_role_instance_status(self, role_instance_name, service_name, expected_status, timeout=600, wait=5):
"""
Waits for a role instance within the web site's cloud service to reach the status specified.
role_instance_name: Name of the role instance.
service_name: Name of service in which to find the role instance.
expected_status: Expected instance status.
timeout: Maximum duration (in seconds) allowed for the operation to complete.
wait: Wait time (in seconds) between consecutive calls to fetch the latest role status.
"""
start_time = time.time()
max_time = start_time + timeout
now = start_time
while True:
status = None
deployment = self.sms.get_deployment_by_name(service_name, service_name)
for role_instance in deployment.role_instance_list:
if role_instance.instance_name == role_instance_name:
status = role_instance.instance_status
if status == expected_status:
break
if now >= max_time:
raise Exception("Operation did not finish within the expected timeout")
logger.info('Waiting for deployment status: expecting %s but got %s (wait_so_far=%s)',
expected_status, status, round(now - start_time, 1))
time_to_wait = max(0.0, min(max_time - now, wait))
time.sleep(time_to_wait)
now = time.time()
def _wait_for_disk_deletion(self, disk_name, timeout=600, wait=5):
"""
Waits for a VM disk to disappear when it is being deleted.
disk_name: Name of the VHD.
timeout: Maximum duration (in seconds) allowed for the operation to complete.
wait: Wait time (in seconds) between consecutive calls to check for the existence of the disk.
"""
start_time = time.time()
max_time = start_time + timeout
now = start_time
logger.info("Checking that disk %s has been deleted.", disk_name)
while self._resource_exists(lambda: self.sms.get_disk(disk_name)):
if now >= max_time:
raise Exception("Disk %s was not deleted within the expected timeout.".format(disk_name))
logger.info("Waiting for disk %s to disappear (wait_so_far=%s).", disk_name, round(now - start_time, 1))
time_to_wait = max(0.0, min(max_time - now, wait))
time.sleep(time_to_wait)
now = time.time()
#.........这里部分代码省略.........