本文整理匯總了Python中azure.mgmt.storage.StorageManagementClient方法的典型用法代碼示例。如果您正苦於以下問題:Python storage.StorageManagementClient方法的具體用法?Python storage.StorageManagementClient怎麽用?Python storage.StorageManagementClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類azure.mgmt.storage
的用法示例。
在下文中一共展示了storage.StorageManagementClient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_storage_account
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def create_storage_account(credentials, subscription_id, **kwargs):
"""
Create a Storage account
:param credentials: msrestazure.azure_active_directory.AdalAuthentication
:param subscription_id: str
:param **resource_group: str
:param **storage_account: str
:param **region: str
"""
storage_management_client = StorageManagementClient(credentials, subscription_id)
storage_account = storage_management_client.storage_accounts.create(
resource_group_name=kwargs.get("resource_group", DefaultSettings.resource_group),
account_name=kwargs.get("storage_account", DefaultSettings.storage_account),
parameters=StorageAccountCreateParameters(
sku=Sku(SkuName.standard_lrs), kind=Kind.storage, location=kwargs.get('region', DefaultSettings.region)))
return storage_account.result().id
示例2: get_blob_client
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def get_blob_client() -> blob.BlockBlobService:
if not storage_resource_id:
return blob.BlockBlobService(
account_name=storage_account_name, account_key=storage_account_key, endpoint_suffix=storage_account_suffix)
else:
credentials = ServicePrincipalCredentials(
client_id=client_id, secret=credential, tenant=tenant_id, resource="https://management.core.windows.net/")
m = RESOURCE_ID_PATTERN.match(storage_resource_id)
accountname = m.group("account")
subscription = m.group("subscription")
resourcegroup = m.group("resourcegroup")
mgmt_client = StorageManagementClient(credentials, subscription)
key = (mgmt_client.storage_accounts.list_keys(resource_group_name=resourcegroup, account_name=accountname)
.keys[0].value)
storage_client = CloudStorageAccount(accountname, key)
return storage_client.create_block_blob_service()
示例3: storage_client
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def storage_client(self):
"""
Uses client from cli so that users can use az login to get their credentials
Returns:
Storage Client
"""
if not self.client:
resource_group = self.desired_state_definition.get("resource_group")
storage_account = self.desired_state_definition.get("storage_account")
if resource_group and storage_account:
client = get_client_from_cli_profile(StorageManagementClient)
storage_keys = client.storage_accounts.list_keys(resource_group, storage_account)
storage_keys = {v.key_name: v.value for v in storage_keys.keys}
self.client = CloudStorageAccount(storage_account, storage_keys['key1'])
else:
raise Exception("azure_resource.resource_group and azure_resource.storage_account must be defined")
return self.client
示例4: create_azure_session
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def create_azure_session(token, service):
assert service in ['compute', 'network', 'security', 'storage', 'resource']
assert isinstance(token, ServicePrincipalCredentials)
platform = config.profile.get('platform')
if 'subscription' in platform and platform['subscription']:
sub_id = platform['subscription']
else:
raise ValueError("Subscription ID not in Azure Platform Definition")
if service == 'compute':
from azure.mgmt.compute import ComputeManagementClient
return ComputeManagementClient(token, sub_id)
if service == 'network':
from azure.mgmt.network import NetworkManagementClient
return NetworkManagementClient(token, sub_id)
if service == 'storage':
from azure.mgmt.storage import StorageManagementClient
return StorageManagementClient(token, sub_id)
if service == 'resource':
from azure.mgmt.resource import ResourceManagementClient
return ResourceManagementClient(token, sub_id)
示例5: get_storage_account
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def get_storage_account(group_name, storage_name, credentials, subscription_id):
"""
Get the Storage Account named storage_name in group_name, if it not exists return None
"""
try:
storage_client = StorageManagementClient(credentials, subscription_id)
return storage_client.storage_accounts.get_properties(group_name, storage_name)
except CloudError as cex:
if cex.status_code == 404:
return None
else:
raise cex
示例6: get_client
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def get_client(self, subscription_id: str):
return StorageManagementClient(self.credentials.get_credentials('arm'),
subscription_id=subscription_id)
示例7: storage_client
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def storage_client(self):
"""Get storage client with subscription and credentials."""
return StorageManagementClient(self.credentials, self.subscription_id)
示例8: test_storage_client
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def test_storage_client(self, _):
"""Test the storage_client property."""
obj = AzureClientFactory(
subscription_id=FAKE.uuid4(),
tenant_id=FAKE.uuid4(),
client_id=FAKE.uuid4(),
client_secret=FAKE.word(),
cloud=random.choice(self.clouds),
)
self.assertTrue(isinstance(obj.storage_client, StorageManagementClient))
示例9: test_cloud_storage_account
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def test_cloud_storage_account(self, _):
"""Test the cloud_storage_account method."""
subscription_id = FAKE.uuid4()
resource_group_name = FAKE.word()
storage_account_name = FAKE.word()
obj = AzureClientFactory(
subscription_id=subscription_id,
tenant_id=FAKE.uuid4(),
client_id=FAKE.uuid4(),
client_secret=FAKE.word(),
cloud=random.choice(self.clouds),
)
with patch.object(StorageManagementClient, "storage_accounts", return_value=None):
cloud_account = obj.cloud_storage_account(resource_group_name, storage_account_name)
self.assertTrue(isinstance(cloud_account, BlobServiceClient))
示例10: __init__
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def __init__(self):
os.environ['AZURE_AUTH_LOCATION'] = '/root/azure_auth.json'
self.compute_client = get_client_from_auth_file(ComputeManagementClient)
self.resource_client = get_client_from_auth_file(ResourceManagementClient)
self.network_client = get_client_from_auth_file(NetworkManagementClient)
self.storage_client = get_client_from_auth_file(StorageManagementClient)
self.datalake_client = get_client_from_auth_file(DataLakeStoreAccountManagementClient)
self.authorization_client = get_client_from_auth_file(AuthorizationManagementClient)
self.sp_creds = json.loads(open(os.environ['AZURE_AUTH_LOCATION']).read())
self.dl_filesystem_creds = lib.auth(tenant_id=json.dumps(self.sp_creds['tenantId']).replace('"', ''),
client_secret=json.dumps(self.sp_creds['clientSecret']).replace('"', ''),
client_id=json.dumps(self.sp_creds['clientId']).replace('"', ''),
resource='https://datalake.azure.net/')
示例11: make_blob_client
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def make_blob_client(secrets):
"""
Creates a blob client object
:param str storage_account_key: storage account key
:param str storage_account_name: storage account name
:param str storage_account_suffix: storage account suffix
"""
if secrets.shared_key:
# Set up SharedKeyCredentials
blob_client = blob.BlockBlobService(
account_name=secrets.shared_key.storage_account_name,
account_key=secrets.shared_key.storage_account_key,
endpoint_suffix=secrets.shared_key.storage_account_suffix,
)
else:
# Set up ServicePrincipalCredentials
arm_credentials = ServicePrincipalCredentials(
client_id=secrets.service_principal.client_id,
secret=secrets.service_principal.credential,
tenant=secrets.service_principal.tenant_id,
resource="https://management.core.windows.net/",
)
match = RESOURCE_ID_PATTERN.match(secrets.service_principal.storage_account_resource_id)
accountname = match.group("account")
subscription = match.group("subscription")
resourcegroup = match.group("resourcegroup")
mgmt_client = StorageManagementClient(arm_credentials, subscription)
key = (retry_function(
mgmt_client.storage_accounts.list_keys,
10,
1,
Exception,
resource_group_name=resourcegroup,
account_name=accountname,
).keys[0].value)
storage_client = CloudStorageAccount(accountname, key)
blob_client = storage_client.create_block_blob_service()
return blob_client
示例12: make_table_service
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def make_table_service(secrets):
if secrets.shared_key:
table_service = TableService(
account_name=secrets.shared_key.storage_account_name,
account_key=secrets.shared_key.storage_account_key,
endpoint_suffix=secrets.shared_key.storage_account_suffix,
)
else:
arm_credentials = ServicePrincipalCredentials(
client_id=secrets.service_principal.client_id,
secret=secrets.service_principal.credential,
tenant=secrets.service_principal.tenant_id,
resource="https://management.core.windows.net/",
)
match = RESOURCE_ID_PATTERN.match(secrets.service_principal.storage_account_resource_id)
accountname = match.group("account")
subscription = match.group("subscription")
resourcegroup = match.group("resourcegroup")
mgmt_client = StorageManagementClient(arm_credentials, subscription)
key = (retry_function(
mgmt_client.storage_accounts.list_keys,
10,
1,
Exception,
resource_group_name=resourcegroup,
account_name=accountname,
).keys[0].value)
table_service = TableService(account_name=accountname, account_key=key)
return table_service
示例13: storage_client
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def storage_client(self):
return StorageManagementClient(self.credentials, self.subscription_id)
示例14: __init__
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def __init__(self, cred, subs_id, my_storage_rg, vmss_rg_name, vmss_name, storage, pan_handle, logger=None):
self.credentials = cred
self.subscription_id = subs_id
self.logger = logger
self.hub_name = vmss_rg_name
self.storage_name = storage
self.panorama_handler = pan_handle
self.vmss_table_name = re.sub(self.ALPHANUM, '', vmss_name + 'vmsstable')
self.vmss_rg_name = vmss_rg_name
try:
self.resource_client = ResourceManagementClient(cred, subs_id)
self.compute_client = ComputeManagementClient(cred, subs_id)
self.network_client = NetworkManagementClient(cred, subs_id)
self.store_client = StorageManagementClient(cred, subs_id)
store_keys = self.store_client.storage_accounts.list_keys(my_storage_rg, storage).keys[0].value
self.table_service = TableService(account_name=storage,
account_key=store_keys)
except Exception as e:
self.logger.error("Getting Azure Infra handlers failed %s" % str(e))
raise e
rg_list = self.resource_client.resource_groups.list()
self.managed_spokes = []
self.managed_spokes.append(vmss_rg_name)
self.new_spokes = []
示例15: generate_options_for_storage_account
# 需要導入模塊: from azure.mgmt import storage [as 別名]
# 或者: from azure.mgmt.storage import StorageManagementClient [as 別名]
def generate_options_for_storage_account(server=None, **kwargs):
discovered_az_stores = []
for handler in AzureARMHandler.objects.all():
set_progress('Connecting to Azure Storage \
for handler: {}'.format(handler))
credentials = ServicePrincipalCredentials(
client_id=handler.client_id,
secret=handler.secret,
tenant=handler.tenant_id
)
azure_client = storage.StorageManagementClient(credentials, handler.serviceaccount)
set_progress("Connection to Azure established")
for st in azure_client.storage_accounts.list():
discovered_az_stores.append(st.name)
return discovered_az_stores