+ def wait_for_instance_id(self, reservation):
+ if not reservation:
+ return False
+
+ self._reload_connection()
+ elapsed_time = 0
+ while elapsed_time < 30:
+ if reservation.instances:
+ instance_id = reservation.instances[0].id
+ return instance_id
+ time.sleep(5)
+ elapsed_time += 5
+ else:
+ raise vimconn.VimConnException(
+ "Failed to get instance_id for reservation",
+ http_code=vimconn.HTTP_Request_Timeout,
+ )
+
+ def wait_for_vm(self, vm_id, status):
+ """wait until vm is in the desired status and return True.
+ If the timeout is reached generate an exception"""
+
+ self._reload_connection()
+
+ elapsed_time = 0
+ while elapsed_time < self.server_timeout:
+ if self.conn.get_all_instances(vm_id):
+ reservation = self.conn.get_all_instances(vm_id)[0]
+ if hasattr(reservation, "instances"):
+ instance = reservation.instances[0]
+ if instance.state == status:
+ return True
+ time.sleep(5)
+ elapsed_time += 5
+
+ # if we exceeded the timeout
+ else:
+ raise vimconn.VimConnException(
+ "Timeout waiting for instance " + vm_id + " to get " + status,
+ http_code=vimconn.HTTP_Request_Timeout,
+ )
+