【问题标题】:Is there a way to skip errors when doing Azure Move Resources?执行 Azure 移动资源时有没有办法跳过错误?
【发布时间】:2020-08-08 17:03:58
【问题描述】:

我正在尝试将大量 Azure 资源从 Azure 资源组移动到 Azure 资源组。

我的代码如下所示:

for i in resource_client.resources.list(filter=f"tagName eq 'run_id' and tagValue eq '{RUN_ID}'"): 
    print_item(i)
    ids.append(i.id)

targetRG = resource_client.resource_groups.get(resource_group_name=DELETE_GROUP_NAME)

for id in ids:
    try:
        poller = resource_client.resources.move_resources(source_resource_group_name=SOURCE_GROUP_NAME, target_resource_group=targetRG.id, resources=id)                           
        rg_move_result = poller.result()
    except:
        pass

我不希望有第二个循环,而是批量执行,但如果移动中有任何错误,它会失败。有没有办法做到这一切并跳过错误?

【问题讨论】:

    标签: python azure azure-sdk azure-sdk-python


    【解决方案1】:

    基本上,您可以尝试使用以下代码结构来实现您想要的:

    for xxx:
        try:
            #Move single resource in this place.
        except:
            #Use continue to out and continue the loop.
            continue
    

    顺便说一下,如果你查看源代码,'move_resources()'中'resources'的类型应该是列表类型。

    【讨论】:

    • Gotcha - 我想我一直在寻找一种方法来告诉 Azure 这样做以尝试做所有事情,而只是跳过(或报告错误)那些不起作用的。
    • @aronchick 嗨,我不确定 gotcha 的含义...我的回答是你想要的吗?
    • 我的意思是我明白了,但我的代码已经这样做了。我正在寻找的是 azure 原生的东西(不是在 python 中),它接受一组批量命令并全部执行,跳过任何错误(但在最后报告它们)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 2020-03-13
    • 2019-10-15
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    相关资源
    最近更新 更多