本文整理汇总了Python中azure.servicemanagement.ServiceManagementService.get_storage_account_keys方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManagementService.get_storage_account_keys方法的具体用法?Python ServiceManagementService.get_storage_account_keys怎么用?Python ServiceManagementService.get_storage_account_keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicemanagement.ServiceManagementService
的用法示例。
在下文中一共展示了ServiceManagementService.get_storage_account_keys方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StorageManagementServiceTest
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_storage_account_keys [as 别名]
#.........这里部分代码省略.........
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)
self.assertIsNotNone(result.storage_service_properties.status_of_primary)
self.assertIsNotNone(result.storage_service_properties.status_of_secondary)
self.assertIsNotNone(result.storage_service_properties.endpoints)
self.assertTrue(len(result.storage_service_properties.endpoints) > 0)
self.assertIsNotNone(result.extended_properties)
self.assertTrue(len(result.extended_properties) > 0)
self.assertIsNotNone(result.capabilities)
self.assertTrue(len(result.capabilities) > 0)
def test_get_storage_account_keys(self):
# Arrange
self._create_storage_account(self.storage_account_name)
# Act
result = self.sms.get_storage_account_keys(self.storage_account_name)
# Assert
self.assertIsNotNone(result)
self.assertIsNotNone(result.url)
self.assertIsNotNone(result.service_name)
self.assertIsNotNone(result.storage_service_keys.primary)
self.assertIsNotNone(result.storage_service_keys.secondary)
self.assertIsNone(result.storage_service_properties)
def test_regenerate_storage_account_keys(self):
# Arrange
self._create_storage_account(self.storage_account_name)
previous = self.sms.get_storage_account_keys(self.storage_account_name)
# Act
result = self.sms.regenerate_storage_account_keys(self.storage_account_name, 'Secondary')
# Assert
self.assertIsNotNone(result)
self.assertIsNotNone(result.url)
self.assertIsNotNone(result.service_name)
self.assertIsNotNone(result.storage_service_keys.primary)
self.assertIsNotNone(result.storage_service_keys.secondary)
self.assertIsNone(result.storage_service_properties)
self.assertEqual(result.storage_service_keys.primary, previous.storage_service_keys.primary)
self.assertNotEqual(result.storage_service_keys.secondary, previous.storage_service_keys.secondary)
示例2: main
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_storage_account_keys [as 别名]
def main():
'''
new version simulate a simple bash
'''
config = __import__('config')
subscription_id = get_certificate_from_publish_settings(
publish_settings_path=config.publish_settings_path,
path_to_write_certificate=config.path_to_write_certificate,
)
cert_file = config.path_to_write_certificate
sms = ServiceManagementService(subscription_id, cert_file)
if len(sys.argv) < 2 :
print "format should be python inspector.py <url of the vhd>"
exit
url = sys.argv[1]
storage_name = url[8:url.find('.')]
storage_account_key = sms.get_storage_account_keys(storage_name).storage_service_keys.primary.encode('ascii','ignore')
nowpath = "/"
def get_sentence(s) :
st = s.find(' ')
while st < len(s) and s[st] == ' ' :
st += 1
ed = len(s)
for i in range(st, len(s)) :
if s[i] == ' ' and s[i-1] != '\\' :
ed = i
break
while ed>0 and s[ed-1] == '/' :
ed -= 1
return s[st:ed].replace("//", "/")
global last_query_files_num
while True :
cmd = raw_input(nowpath+" $ ")
if cmd.split(' ')[0] == "quit" :
break
elif cmd.split(' ')[0] == "ls" :
old_main(url=url, account_key=storage_account_key, path=nowpath, ls=True)
elif cmd.startswith("cd ") :
sentence = get_sentence(cmd)
if sentence != "" :
if sentence == ".." :
if nowpath != "/" :
nowpath = nowpath[:nowpath[:-1].rfind('/')+1]
elif sentence[0] == '/' :
old_main(url=url, account_key=storage_account_key, path=sentence, ls=True)
if last_query_files_num == 0 :
print "no such directory"
else :
nowpath = sentence + "/"
elif sentence != "" :
old_main(url=url, account_key=storage_account_key, path=(nowpath+sentence), ls=True)
if last_query_files_num == 0 :
print "no such directory"
else :
nowpath += sentence + "/"
elif cmd.startswith("download ") :
sentence = get_sentence(cmd)
tmp = sentence.rfind('/')
if sentence != "" :
old_main(url=url, account_key=storage_account_key, path=(nowpath+sentence[:tmp]), filename=sentence[(tmp+1):])
else :
print "invalid command"
示例3: print
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_storage_account_keys [as 别名]
print('Management URL: ' + hosted_service.url)
print('Location: ' + hosted_service.hosted_service_properties.location)
print('')
print "The following storage accounts are now up:"
result = sms.list_storage_accounts()
for account in result:
print('Account Service name: ' + account.service_name)
print('Storage account url: ' + account.url)
print('Location: ' + account.storage_service_properties.location)
print('Storage Account Keys:')
storageServiceObj = sms.get_storage_account_keys(account.service_name)
print storageServiceObj.storage_service_keys.primary
print storageServiceObj.storage_service_keys.secondary
print('')
if account.service_name == storage_acc_name:
storageServiceObj = sms.get_storage_account_keys(account.service_name)
storage_acc_key = storageServiceObj.storage_service_keys.primary
# cert_path = "/home/rohan/temp2/myCert.pem"
cert_path = config_params["vm_cert_path"]
with open(cert_path, "rb") as bfile:
# decode to make sure this is a str and not a bstr
cert_data = base64.b64encode(bfile.read()).decode()
示例4: Deployment
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_storage_account_keys [as 别名]
#.........这里部分代码省略.........
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()
account_key = self._getStorageAccountKey(account_name)
cors_rule = CorsRule()
cors_rule.allowed_origins = self.config.getServiceStorageCorsAllowedOrigins()
cors_rule.allowed_methods = 'PUT'
cors_rule.exposed_headers = '*'
cors_rule.allowed_headers = '*'
cors_rule.max_age_in_seconds = 1800
示例5: provision
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import get_storage_account_keys [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({})