本文整理汇总了Python中azure.servicemanagement.ServiceManagementService.create_storage_account方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManagementService.create_storage_account方法的具体用法?Python ServiceManagementService.create_storage_account怎么用?Python ServiceManagementService.create_storage_account使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicemanagement.ServiceManagementService
的用法示例。
在下文中一共展示了ServiceManagementService.create_storage_account方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AffinityGroupManagementServiceTest
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import create_storage_account [as 别名]
class AffinityGroupManagementServiceTest(AzureTestCase):
def setUp(self):
self.sms = ServiceManagementService(credentials.getSubscriptionId(),
credentials.getManagementCertFile())
self.sms.set_proxy(credentials.getProxyHost(),
credentials.getProxyPort(),
credentials.getProxyUser(),
credentials.getProxyPassword())
self.affinity_group_name = getUniqueNameBasedOnCurrentTime('utaffgrp')
self.hosted_service_name = None
self.storage_account_name = None
def tearDown(self):
try:
if self.hosted_service_name is not None:
self.sms.delete_hosted_service(self.hosted_service_name)
except: pass
try:
if self.storage_account_name is not None:
self.sms.delete_storage_account(self.storage_account_name)
except: pass
try:
self.sms.delete_affinity_group(self.affinity_group_name)
except: pass
#--Helpers-----------------------------------------------------------------
def _create_affinity_group(self, name):
result = self.sms.create_affinity_group(name, 'tstmgmtaffgrp', 'West US', 'tstmgmt affinity group')
self.assertIsNone(result)
def _affinity_group_exists(self, name):
try:
props = self.sms.get_affinity_group_properties(name)
return props is not None
except:
return False
#--Test cases for affinity groups ------------------------------------
def test_list_affinity_groups(self):
# Arrange
self._create_affinity_group(self.affinity_group_name)
# Act
result = self.sms.list_affinity_groups()
# Assert
self.assertIsNotNone(result)
self.assertTrue(len(result) > 0)
group = None
for temp in result:
if temp.name == self.affinity_group_name:
group = temp
break
self.assertIsNotNone(group)
self.assertIsNotNone(group.name)
self.assertIsNotNone(group.label)
self.assertIsNotNone(group.description)
self.assertIsNotNone(group.location)
self.assertIsNotNone(group.capabilities)
self.assertTrue(len(group.capabilities) > 0)
def test_get_affinity_group_properties(self):
# Arrange
self.hosted_service_name = getUniqueNameBasedOnCurrentTime('utsvc')
self.storage_account_name = getUniqueNameBasedOnCurrentTime('utstorage')
self._create_affinity_group(self.affinity_group_name)
self.sms.create_hosted_service(self.hosted_service_name, 'affgrptestlabel', 'affgrptestdesc', None, self.affinity_group_name)
self.sms.create_storage_account(self.storage_account_name, self.storage_account_name + 'desc', self.storage_account_name + 'label', self.affinity_group_name)
# Act
result = self.sms.get_affinity_group_properties(self.affinity_group_name)
# Assert
self.assertIsNotNone(result)
self.assertEqual(result.name, self.affinity_group_name)
self.assertIsNotNone(result.label)
self.assertIsNotNone(result.description)
self.assertIsNotNone(result.location)
self.assertIsNotNone(result.hosted_services[0])
self.assertEqual(result.hosted_services[0].service_name, self.hosted_service_name)
self.assertEqual(result.hosted_services[0].hosted_service_properties.affinity_group, self.affinity_group_name)
# not sure why azure does not return any storage service
self.assertTrue(len(result.capabilities) > 0)
def test_create_affinity_group(self):
# Arrange
label = 'tstmgmtaffgrp'
description = 'tstmgmt affinity group'
# Act
result = self.sms.create_affinity_group(self.affinity_group_name, label, 'West US', description)
# Assert
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import create_storage_account [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: StorageManagementServiceTest
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import create_storage_account [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)
#.........这里部分代码省略.........
示例4: Deployment
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import create_storage_account [as 别名]
#.........这里部分代码省略.........
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.
"""
logger.info("Setting CORS rules.")
account_name = self.config.getServiceStorageAccountName()
示例5: name_generator
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import create_storage_account [as 别名]
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()
for hosted_service in result:
print('Service name: ' + hosted_service.service_name)
print('Management URL: ' + hosted_service.url)
print('Location: ' + hosted_service.hosted_service_properties.location)
print('')
示例6: provision
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import create_storage_account [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({})