def wait_for_shutdown(self, count=60): """ Return True on successful domain shutdown. Wait for a domain to shutdown, libvirt does not block on domain shutdown so we need to watch for successful completion. @param name: VM name @param name: Optional timeout value """ timeout = count while count > 0: # check every 5 seconds if count % 5 == 0: if virsh.is_dead(self.name, uri=self.connect_uri): logging.debug("Shutdown took %d seconds", timeout - count) return True count -= 1 time.sleep(1) logging.debug("Waiting for guest to shutdown %d", count) return False
def is_dead(self): """ Return True if VM is dead. """ return virsh.is_dead(self.name, uri=self.connect_uri)