在执行Azure移动资源时是否有跳过错误的方法?

2024-10-01 00:31:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将大量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

我不希望使用第二个循环,而是批量执行,但是如果在移动过程中出现任何错误,它就会失败。有没有办法做到这一点,跳过错误


Tags: nameinclientididsforgroup资源
1条回答
网友
1楼 · 发布于 2024-10-01 00:31:57

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

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

顺便说一下,如果您检查源代码,“move_resources()”中的“resources”类型应该是列表类型

相关问题 更多 >