【问题标题】:How to delete a particular resource from resource group in Azure using python如何使用 python 从 Azure 中的资源组中删除特定资源
【发布时间】:2017-12-21 11:28:13
【问题描述】:

我正在使用 azure.mgmt.resource 从 azure 中删除资源组,但我可以在不删除资源组的情况下删除特定资源吗?

【问题讨论】:

    标签: python azure azure-resource-group


    【解决方案1】:

    如果您无法按照另一个答案中的说明使用资源类型的特定客户端,则可以使用 azure-mgmt-resource 包和 ResourceManagementClient 中的两个通用删除之一:

    请注意,询问的 ApiVersion 是您要删除的资源中的版本。请查看 RestAPI 文档以根据您要删除的资源类型获取 ApiVersion。例如,您可以在该页面中获取 Storage 的 ApiVersion:

    https://docs.microsoft.com/rest/api/storagerp/

    【讨论】:

    • 你能告诉我如何使用它吗? @laurent
    • 我使用它的方式如下:- credentials = ServicePrincipalCredentials(client_id=clientid,secret=clientsecret,tenant=tenantid) client = ResourceManagementClient(credentials,subscription_id) delete_async_operation = client.resourceoperations.delete_by_id(resource_id, api)delete_async_operation.wait()但得到错误:-'ResourceManagementClient'对象没有属性'resourceoperations'
    • 从这个示例开始了解如何使用 ResourceManagementClient github.com/Azure-Samples/…
    【解决方案2】:

    例如,如果您要删除资源组中的虚拟机

    Delete VM
            print('\nDelete VM')
            async_vm_delete = compute_client.virtual_machines.delete(GROUP_NAME, VM_NAME)
            async_vm_delete.wait()

    Azure-Samples/resource-manager-python-resources-and-groups

    Manage Azure resources and resource groups with Python:

    补充资料:Click here

    【讨论】:

    • 我不想删除特定资源。我想删除任何资源。这可能吗??
    猜你喜欢
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-05
    • 1970-01-01
    相关资源
    最近更新 更多