Azure:使用StorageManagementClient获取经典存储帐户密钥

时间:2018-05-25 09:22:22

标签: python azure azure-storage

我正在尝试使用StorageManagementClient自动检索经典存储帐户的密钥。

对于新的,client.storage_accounts.list_keys(resource_group_name, storage_account_name)工作得很好,但对于经典版本,我最终会遇到以下错误:

msrestazure.azure_exceptions.CloudError: Azure Error: ResourceNotFound
Message: The Resource 'Microsoft.Storage/storageAccounts/<storage_account_name>' under resource group '<resource_group_name>' was not found.

我没有找到在文档中包含经典资源的方法(参见https://github.com/Azure/azure-sdk-for-python/tree/master/azure-mgmt-storage/azure/mgmt/storage)。

我只需要使用其他API /客户端吗?

1 个答案:

答案 0 :(得分:1)

您无法使用此软件包,您需要使用名为azure-servicemanagement-legacy的ASM(Azure服务管理)软件包:https://pypi.org/project/azure-servicemanagement-legacy/

从此测试文件中查看此unittest:https://github.com/Azure/azure-sdk-for-python/blob/master/azure-servicemanagement-legacy/tests/test_legacy_mgmt_storage.py

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)

修改:您可能希望使用azure-mgmt-resource(有关详细信息,请参阅https://stackoverflow.com/a/45814624/4074838)尝试使用此网址调用ARM资源:https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys?api-version=2015-06-01

您可以创建ResourceManagementClient客户端client,并致电client.resources.get_by_id(subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys, '2015-06-01') 正如我在答案中所描述的那样,不能保证这个电话将来会继续有效(如果它现在还在工作的话)

参考:https://docs.microsoft.com/en-us/python/api/azure.mgmt.resource.resources.v2017_05_10.operations.resourcesoperations?view=azure-python#get-by-id