本文整理汇总了Python中azure.servicemanagement.ServiceManagementService.get_storage_account_properties方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManagementService.get_storage_account_properties方法的具体用法?Python ServiceManagementService.get_storage_account_properties怎么用?Python ServiceManagementService.get_storage_account_properties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicemanagement.ServiceManagementService
的用法示例。
在下文中一共展示了ServiceManagementService.get_storage_account_properties方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StorageManagementServiceTest
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_storage_account_properties [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_storage_account_properties [as 别名]
#.........这里部分代码省略.........
time.sleep(time_to_wait)
now = time.time()
def _getRoleInstances(self, service_name):
"""
Returns the role instances in the given cloud service deployment. The results are provided as
a dictionary where keys are role instance names and values are RoleInstance objects.
"""
role_instances = {}
if self._resource_exists(lambda: self.sms.get_deployment_by_name(service_name, service_name)):
deployment = self.sms.get_deployment_by_name(service_name, service_name)
for role_instance in deployment.role_instance_list:
role_instances[role_instance.instance_name] = role_instance
return role_instances
def _ensureAffinityGroupExists(self):
"""
Creates the affinity group if it does not exist.
"""
name = self.config.getAffinityGroupName()
location = self.config.getServiceLocation()
logger.info("Checking for existence of affinity group (name=%s; location=%s).", name, location)
if self._resource_exists(lambda: self.sms.get_affinity_group_properties(name)):
logger.warn("An affinity group named %s already exists.", name)
else:
self.sms.create_affinity_group(name, name, location)
logger.info("Created affinity group %s.", name)
def _ensureStorageAccountExists(self, name):
"""
Creates the storage account if it does not exist.
"""
logger.info("Checking for existence of storage account (name=%s).", name)
if self._resource_exists(lambda: self.sms.get_storage_account_properties(name)):
logger.warn("A storage account named %s already exists.", name)
else:
result = self.sms.create_storage_account(name, "", name, affinity_group=self.config.getAffinityGroupName())
self._wait_for_operation_success(result.request_id, timeout=self.config.getAzureOperationTimeout())
logger.info("Created storage account %s.", name)
def _getStorageAccountKey(self, account_name):
"""
Gets the storage account key (primary key) for the given storage account.
"""
storage_props = self.sms.get_storage_account_keys(account_name)
return storage_props.storage_service_keys.primary
def _ensureStorageContainersExist(self):
"""
Creates Blob storage containers required by the service.
"""
logger.info("Checking for existence of Blob containers.")
account_name = self.config.getServiceStorageAccountName()
account_key = self._getStorageAccountKey(account_name)
blob_service = BlobService(account_name, account_key)
name_and_access_list = [(self.config.getServicePublicStorageContainer(), 'blob'),
(self.config.getServiceBundleStorageContainer(), None)]
for name, access in name_and_access_list:
logger.info("Checking for existence of Blob container %s.", name)
blob_service.create_container(name, x_ms_blob_public_access=access, fail_on_exist=False)
access_info = 'private' if access is None else 'public {0}'.format(access)
logger.info("Blob container %s is ready (access: %s).", name, access_info)
def ensureStorageHasCorsConfiguration(self):
"""
Ensures Blob storage container for bundles is configured to allow cross-origin resource sharing.