小编Vai*_*lia的帖子

Azure SDK Python:标记特定资源

我想使用 python 在 Azure 中的每个资源上创建标签。

我在文档中看到这个模块: http //azure-sdk-for-python.readthedocs.io/en/latest/ref/azure.mgmt.resource.resources.operations.html#azure.mgmt.resource.resources。操作.标签操作

create_or_update: 创建订阅资源标签列表:获取订阅资源标签列表

似乎我只能对资源组进行标记操作,而不能对资源进行标记操作?

例子:

向资源组添加标签:Set-AzureRmResourceGroup 向资源添加标签:Set-AzureRmResource

编辑:

感谢您的 api 查找代码,非常整洁。但我相信我手动放置的旧 api 也应该有效。我几乎没有修改过你的代码(我们可能有不同的 Azure SDK,我使用的是 2.0.0rc5)。添加api函数(非常有用)后,不幸的是我仍然遇到相同的错误。

from azure.common.credentials import UserPassCredentials
from azure.mgmt.resource.resources import ResourceManagementClient

def resolve_resource_api(client, resource):
    """ This method retrieves the latest non-preview api version for
    the given resource (unless the preview version is the only available
    api version) """
    provider = client.providers.get(resource.id.split('/')[6])
    rt = next((t for t in provider.resource_types
               if t.resource_type == '/'.join(resource.type.split('/')[1:])), None)
    #print(rt)
    if rt and 'api_versions' in rt.__dict__: …
Run Code Online (Sandbox Code Playgroud)

python azure azure-sdk-python

1
推荐指数
1
解决办法
3361
查看次数

标签 统计

azure ×1

azure-sdk-python ×1

python ×1