當前位置: 首頁>>代碼示例>>Python>>正文


Python storage.StorageManagementClient方法代碼示例

本文整理匯總了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 
開發者ID:Azure,項目名稱:aztk,代碼行數:18,代碼來源:account_setup.py

示例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() 
開發者ID:Azure,項目名稱:aztk,代碼行數:18,代碼來源:config.py

示例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 
開發者ID:capitalone,項目名稱:Particle-Cloud-Framework,代碼行數:21,代碼來源:azure_resource.py

示例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) 
開發者ID:Chaffelson,項目名稱:whoville,代碼行數:22,代碼來源:infra.py

示例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 
開發者ID:grycap,項目名稱:im,代碼行數:14,代碼來源:Azure.py

示例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) 
開發者ID:nccgroup,項目名稱:ScoutSuite,代碼行數:5,代碼來源:storageaccounts.py

示例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) 
開發者ID:project-koku,項目名稱:koku,代碼行數:5,代碼來源:client.py

示例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)) 
開發者ID:project-koku,項目名稱:koku,代碼行數:12,代碼來源:tests_client.py

示例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)) 
開發者ID:project-koku,項目名稱:koku,代碼行數:17,代碼來源:tests_client.py

示例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/') 
開發者ID:apache,項目名稱:incubator-dlab,代碼行數:15,代碼來源:actions_lib.py

示例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 
開發者ID:Azure,項目名稱:aztk,代碼行數:42,代碼來源:azure_api.py

示例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 
開發者ID:Azure,項目名稱:aztk,代碼行數:32,代碼來源:azure_api.py

示例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) 
開發者ID:RedHatQE,項目名稱:wrapanapi,代碼行數:4,代碼來源:msazure.py

示例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 = [] 
開發者ID:PaloAltoNetworks,項目名稱:pan-fca,代碼行數:29,代碼來源:monitor.py

示例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 
開發者ID:CloudBoltSoftware,項目名稱:cloudbolt-forge,代碼行數:17,代碼來源:create.py


注:本文中的azure.mgmt.storage.StorageManagementClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。