I am getting below error when trying to get the status of the VM inside while loop:
File "C:\Users\RohitMishra\Documents\cost-controller-engine\services\service.py", line 533, in schedule
compute_client.virtual_machines.get(resrc, vm, expand="instanceView")
IndexError: list index out of range
Below is my code:
Status_vm = (
compute_client.virtual_machines.get(resrc, vm, expand="instanceView").instance_view.statuses[1].display_status)
print("STATUS VMMMM---",Status_vm)
if Status_vm =="VM deallocated":
compute_client.virtual_machines.begin_start(resrc, vm)
while True:
logger.info("enterd into while loop for starting VM..")
print("STATATAus >>>>>: ",Status_vm)
Status_vm = (
compute_client.virtual_machines.get(resrc, vm, expand="instanceView")
.instance_view.statuses[1]
.display_status
)
logger.info(f"Status.. @: {Status_vm}")
if Status_vm =="VM running":
break
else:
time.sleep(constants.SLEEP_TIME)
return "Successfully running your VM"
Could you guys help me with any code or logic in python to resolve this issue...
Like Laurent Mazuel said it would be great to have an issue with a full stack trace in https://github.com/Azure/azure-sdk-for-python/issues. I'm also wondering if it could be
.instance_view.statuses[1]that you're calling on the returned object fromcompute_client.virtual_machines.get, are you sure there are at least 2 statuses on the instance view?