question

ArigatoManga-1224 avatar image
0 Votes"
ArigatoManga-1224 asked karishmatiwari-msft edited

How to check resource creation success in Azure Python SDK

I'm creating several resources in Azure using python SDK but i'm confused how to check whether the resource is successfully created or not ?

Documentation says the poller has multiple methods - done(), wait(), result() etc to check status of the resource but what is the safe way to check status on creation of a resource ?

I have checked samples from here but they only have wait() and do not check on the status

ex:

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:


what is the best option/way to handle/check resource creation ?
or is there any way to handle it properly ?

Thanks in advance !


not-supported-azure
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers