[英]Azure : Get classic storage account key using StorageManagementClient
I am trying to automatically retrieve the key of a classic Storage Account using StorageManagementClient. 我正在尝试使用StorageManagementClient自动检索经典存储帐户的密钥。
For new ones, this worked fine client.storage_accounts.list_keys(resource_group_name, storage_account_name)
but for classic ones I end up with the following error : 对于新的,这很好用
client.storage_accounts.list_keys(resource_group_name, storage_account_name)
但是对于经典的,我会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.
I did not find a way to also include classic resources in the documentation (see https://github.com/Azure/azure-sdk-for-python/tree/master/azure-mgmt-storage/azure/mgmt/storage ). 我没有找到在文档中也包含经典资源的方法(请参阅https://github.com/Azure/azure-sdk-for-python/tree/master/azure-mgmt-storage/azure/mgmt/storage ) 。
Do I simply have to use another API / client ? 我是否只需要使用另一个API /客户端?
You can't with this package, you need to use the ASM (Azure Service Management) package called azure-servicemanagement-legacy
: https://pypi.org/project/azure-servicemanagement-legacy/ 您无法使用此软件包,需要使用称为
azure-servicemanagement-legacy
的ASM(Azure服务管理)软件包: https : //pypi.org/project/azure-servicemanagement-legacy/
See this unittest from this testfile: https://github.com/Azure/azure-sdk-for-python/blob/master/azure-servicemanagement-legacy/tests/test_legacy_mgmt_storage.py 从以下测试文件中查看此单元测试: 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)
Edit : You might want to try a ARM resource call using azure-mgmt-resource
(see https://stackoverflow.com/a/45814624/4074838 for details) to this URL: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys?api-version=2015-06-01
编辑 :您可能想尝试使用
azure-mgmt-resource
(有关详细信息,请参阅https://stackoverflow.com/a/45814624/4074838 )到此URL的ARM资源调用: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys?api-version=2015-06-01
: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys?api-version=2015-06-01
You can create a ResourceManagementClient client client
, and call client.resources.get_by_id(subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys, '2015-06-01')
As described in the answer I mention however, there is no guarantee this call will continue to work in the future (if it's even still working now) 您可以创建ResourceManagementClient客户
client
客户client
,然后调用client.resources.get_by_id(subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys, '2015-06-01')
但是,正如我提到的答案中所描述的那样,不能保证此调用将来会继续有效(如果现在仍在起作用)
Ref: https://docs.microsoft.com/en-us/python/api/azure.mgmt.resource.resources.v2017_05_10.operations.resourcesoperations?view=azure-python#get-by-id 参考: https : //docs.microsoft.com/zh-cn/python/api/azure.mgmt.resource.resources.v2017_05_10.operations.resourcesoperations? view = azure-python#get-by- id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.