本文整理汇总了Python中azure.servicemanagement.ServiceManagementService.get_role方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManagementService.get_role方法的具体用法?Python ServiceManagementService.get_role怎么用?Python ServiceManagementService.get_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicemanagement.ServiceManagementService
的用法示例。
在下文中一共展示了ServiceManagementService.get_role方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: azure_add_endpoints
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_role [as 别名]
def azure_add_endpoints(name, portConfigs):
sms = ServiceManagementService(AZURE_SUBSCRIPTION_ID, AZURE_CERTIFICATE)
role = sms.get_role(name, name, name)
network_config = role.configuration_sets[0]
for i, portConfig in enumerate(portConfigs):
network_config.input_endpoints.input_endpoints.append(
ConfigurationSetInputEndpoint(
name=portConfig["service"],
protocol=portConfig["protocol"],
port=portConfig["port"],
local_port=portConfig["local_port"],
load_balanced_endpoint_set_name=None,
enable_direct_server_return=True if portConfig["protocol"] == "udp" else False,
idle_timeout_in_minutes=None if portConfig["protocol"] == "udp" else 4)
)
try:
sms.update_role(name, name, name, network_config=network_config)
except AzureHttpError as e:
debug.warn("Exception opening ports for %s: %r" % (name, e))
示例2: __init__
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_role [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
示例3: AzureStorageBlockDeviceAPI
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_role [as 别名]
#.........这里部分代码省略.........
label
:param string disk_label: The disk label
:returns UUID: The UUID of the dataset
"""
return UUID(disk_label.replace('flocker-', ''))
def _get_disk_vmname_lun(self, blockdevice_id):
target_disk = None
target_lun = None
role_name = None
disk_list = self._azure_service_client.list_disks()
for d in disk_list:
if 'flocker-' not in d.label:
continue
if d.label == str(blockdevice_id):
target_disk = d
break
if target_disk is None:
# check for unregisterd disk
blobs = self._get_flocker_blobs()
blob = None
if str(blockdevice_id) in blobs:
blob = blobs[str(blockdevice_id)]
return blob, None, None
vm_info = None
if hasattr(target_disk.attached_to, 'role_name'):
vm_info = self._azure_service_client.get_role(
self._service_name, self._service_name,
target_disk.attached_to.role_name)
for d in vm_info.data_virtual_hard_disks:
if d.disk_name == target_disk.name:
target_lun = d.lun
break
role_name = target_disk.attached_to.role_name
return (target_disk, role_name, target_lun)
def _get_flocker_blobs(self):
all_blobs = {}
blobs = self._azure_storage_client.list_blobs(
self._disk_container_name,
prefix='flocker-')
for b in blobs:
# todo - this could be big!
all_blobs[b.name] = b
return all_blobs
def _wait_for_detach(self, blockdevice_id):
role_name = ''
lun = -1
timeout_count = 0
log_info('waiting for azure to ' + 'report disk as detached...')