本文整理汇总了Python中azure.servicemanagement.ServiceManagementService.get_operation_status方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManagementService.get_operation_status方法的具体用法?Python ServiceManagementService.get_operation_status怎么用?Python ServiceManagementService.get_operation_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicemanagement.ServiceManagementService
的用法示例。
在下文中一共展示了ServiceManagementService.get_operation_status方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StorageManagementServiceTest
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_operation_status [as 别名]
class StorageManagementServiceTest(AzureTestCase):
def setUp(self):
proxy_host = credentials.getProxyHost()
proxy_port = credentials.getProxyPort()
self.sms = ServiceManagementService(credentials.getSubscriptionId(), credentials.getManagementCertFile())
if proxy_host:
self.sms.set_proxy(proxy_host, proxy_port)
self.storage_account_name = getUniqueNameBasedOnCurrentTime('utstorage')
def tearDown(self):
try:
self.sms.delete_storage_account(self.storage_account_name)
except: pass
#--Helpers-----------------------------------------------------------------
def _wait_for_async(self, request_id):
count = 0
result = self.sms.get_operation_status(request_id)
while result.status == 'InProgress':
count = count + 1
if count > 120:
self.assertTrue(False, 'Timed out waiting for async operation to complete.')
time.sleep(5)
result = self.sms.get_operation_status(request_id)
self.assertEqual(result.status, 'Succeeded')
def _create_storage_account(self, name):
result = self.sms.create_storage_account(name, name + 'description', name + 'label', None, 'West US', False, {'ext1':'val1', 'ext2':42})
self._wait_for_async(result.request_id)
def _storage_account_exists(self, name):
try:
props = self.sms.get_storage_account_properties(name)
return props is not None
except:
return False
#--Test cases for storage accounts -----------------------------------
def test_list_storage_accounts(self):
# Arrange
self._create_storage_account(self.storage_account_name)
# Act
result = self.sms.list_storage_accounts()
# Assert
self.assertIsNotNone(result)
self.assertTrue(len(result) > 0)
storage = None
for temp in result:
if temp.service_name == self.storage_account_name:
storage = temp
break
self.assertIsNotNone(storage)
self.assertIsNotNone(storage.service_name)
self.assertIsNone(storage.storage_service_keys)
self.assertIsNotNone(storage.storage_service_properties)
self.assertIsNotNone(storage.storage_service_properties.affinity_group)
self.assertIsNotNone(storage.storage_service_properties.description)
self.assertIsNotNone(storage.storage_service_properties.geo_primary_region)
self.assertIsNotNone(storage.storage_service_properties.geo_replication_enabled)
self.assertIsNotNone(storage.storage_service_properties.geo_secondary_region)
self.assertIsNotNone(storage.storage_service_properties.label)
self.assertIsNotNone(storage.storage_service_properties.last_geo_failover_time)
self.assertIsNotNone(storage.storage_service_properties.location)
self.assertIsNotNone(storage.storage_service_properties.status)
self.assertIsNotNone(storage.storage_service_properties.status_of_primary)
self.assertIsNotNone(storage.storage_service_properties.status_of_secondary)
self.assertIsNotNone(storage.storage_service_properties.endpoints)
self.assertTrue(len(storage.storage_service_properties.endpoints) > 0)
self.assertIsNotNone(storage.extended_properties)
self.assertTrue(len(storage.extended_properties) > 0)
def test_get_storage_account_properties(self):
# Arrange
self._create_storage_account(self.storage_account_name)
# Act
result = self.sms.get_storage_account_properties(self.storage_account_name)
# Assert
self.assertIsNotNone(result)
self.assertEqual(result.service_name, self.storage_account_name)
self.assertIsNotNone(result.url)
self.assertIsNone(result.storage_service_keys)
self.assertIsNotNone(result.storage_service_properties)
self.assertIsNotNone(result.storage_service_properties.affinity_group)
self.assertIsNotNone(result.storage_service_properties.description)
self.assertIsNotNone(result.storage_service_properties.geo_primary_region)
self.assertIsNotNone(result.storage_service_properties.geo_replication_enabled)
self.assertIsNotNone(result.storage_service_properties.geo_secondary_region)
self.assertIsNotNone(result.storage_service_properties.label)
self.assertIsNotNone(result.storage_service_properties.last_geo_failover_time)
self.assertIsNotNone(result.storage_service_properties.location)
self.assertIsNotNone(result.storage_service_properties.status)
#.........这里部分代码省略.........
示例2: Deployment
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_operation_status [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()
#.........这里部分代码省略.........
示例3: AzureStorageBlockDeviceAPI
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_operation_status [as 别名]
#.........这里部分代码省略.........
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...')
while role_name is not None or lun is not None:
(target_disk, role_name, lun) = \
self._get_disk_vmname_lun(blockdevice_id)
time.sleep(1)
timeout_count += 1
if timeout_count > 5000:
raise AsynchronousTimeout()
log_info('Disk Detached')
def _wait_for_attach(self, blockdevice_id):
timeout_count = 0
lun = None
log_info('waiting for azure to report disk as attached...')
while lun is None:
(target_disk, role_name, lun) = \
self._get_disk_vmname_lun(blockdevice_id)
time.sleep(.001)
timeout_count += 1
if timeout_count > 5000:
raise AsynchronousTimeout()
def _wait_for_async(self, request_id, timeout):
count = 0
result = self._azure_service_client.get_operation_status(request_id)
while result.status == 'InProgress':
count = count + 1
if count > timeout:
log_error('Timed out waiting for async operation to complete.')
raise AsynchronousTimeout()
time.sleep(.001)
log_info('.')
result = self._azure_service_client.get_operation_status(
request_id)
if result.error:
log_error(result.error.code)
log_error(str(result.error.message))
log_error(result.status + ' in ' + str(count * 5) + 's')
def _gibytes_to_bytes(self, size):
return int(GiB(size).to_Byte().value)
def _blockdevicevolume_from_azure_volume(self, label, size,
attached_to_name):
# azure will report the disk size excluding the 512 byte footer
# however flocker expects the exact value it requested for disk size
# so offset the reported size to flocker by 512 bytes
return BlockDeviceVolume(
blockdevice_id=unicode(label),
size=int(size),
attached_to=attached_to_name,
dataset_id=self._dataset_id_for_disk_label(label)
) # disk labels are formatted as flocker-<data_set_id>
示例4: ServiceManagementService
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_operation_status [as 别名]
subscription_id = config_params["subscription_id"]
certificate_path = config_params["mgmt_cert_path"]
sms = ServiceManagementService(subscription_id, certificate_path)
# Because the name has to be unique in Their cloud :/
hosted_service_name = name_generator()
label = 'devOps test'
desc = 'Service for basic nginx server'
location = 'Central US'
# image_list = sms.list_os_images()
result = sms.create_hosted_service(hosted_service_name, label, desc, location)
operation_result = sms.get_operation_status(result.request_id)
storage_acc_name = name_generator()
label = 'mystorageaccount'
location = 'Central US'
desc = 'My storage account description.'
result = sms.create_storage_account(storage_acc_name, desc, label,
location=location)
operation_result = sms.get_operation_status(result.request_id)
print('Operation status: ' + operation_result.status)
print "The following services are now up:"
result = sms.list_hosted_services()
示例5: provision
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_operation_status [as 别名]
def provision(instance_id):
"""
Provision an instance of this service
for the given org and space
PUT /v2/service_instances/<instance_id>:
<instance_id> is provided by the Cloud
Controller and will be used for future
requests to bind, unbind and deprovision
BODY:
{
"service_id": "<service-guid>",
"plan_id": "<plan-guid>",
"organization_guid": "<org-guid>",
"space_guid": "<space-guid>"
}
return:
JSON document with details about the
services offered through this broker
"""
if 'application/json' not in request.content_type:
abort(415, 'Unsupported Content-Type: expecting application/json, actual {0}'.format(request.content_type))
global subscription_id
global cert
global cert_file
global account_name
global account_key
if subscription_id and cert and (not account_name):
sms = ServiceManagementService(subscription_id, cert_file)
name = '{0}{1}'.format(STORAGE_ACCOUNT_NAME_PREFIX, instance_id.split('-')[0])
desc = name
label = name
location = 'West US'
result = None
try:
result = sms.create_storage_account(name, desc, label, location=location)
except WindowsAzureConflictError as e:
pass
if result:
req_id = result.request_id
operation = sms.get_operation_status(req_id)
while operation.status == 'InProgress':
time.sleep(5)
operation = sms.get_operation_status(req_id)
app.logger.info('Request ID: {0}, Operation Status: {1}'.format(req_id, operation.status))
if operation.status == 'Succeeded':
app.logger.info('Request ID: {0}, Operation Status: {1}'.format(req_id, operation.status))
account_name = name
account_key = sms.get_storage_account_keys(account_name).storage_service_keys.primary
app.logger.info('Account Name: {0}, Account key: {1}'.format(account_name, account_key))
if account_name:
blob_service = BlobService(account_name, account_key)
container_name = '{0}-{1}'.format(CONTAINER_NAME_PREFIX, instance_id)
app.logger.info('Container Name: {0}'.format(container_name))
request_body = request.get_json()
if request_body.has_key('parameters'):
parameters = request_body.pop('parameters')
container_tags = request_body
container_tags['instance_id'] = instance_id
blob_service.create_container(
container_name = container_name,
x_ms_meta_name_values = container_tags)
return jsonify({})