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...