gpt4 book ai didi

python - 如何在Azure Python SDK中检查资源创建成功

转载 作者:行者123 更新时间:2023-12-02 07:32:51 25 4
gpt4 key购买 nike

我正在使用 python SDK 在 Azure 中创建多个资源,但我很困惑如何检查资源是否已成功创建?

Documentation说轮询器有多种方法 - did()、wait()、result() 等来检查资源的状态,但是创建资源的安全方法是什么?

例如:

try:
resource = client.virual_machines.begin_create_or_update(...)

# option 1
count = 1
while not resource.done(): #done() returns true or false
time.sleep(timeout)
if count > 10:
raise
count += 1

# option 2
response = resource.result() # result() returns the object of the corresponding resource
if not isinstance(response, VirtualMachine):
raise


# option 3
resource.wait(timeout)
# check the status() function and based on the status of
# ('inprogress', 'done', 'provisioning', 'succedded')
# add a manual check and raise exception

except Exception as e:

处理/检查资源创建的最佳选项/方法是什么?或者有什么办法可以妥善处理吗?

提前致谢!

最佳答案

按照您所说的方式配置资源后,我们将使用轮询器以及相应的方法来检查正在创建的资源的状态/结果。

要配置资源并检查状态,您可以检查此 Example .

关于python - 如何在Azure Python SDK中检查资源创建成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69204422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com