def wait(self, status): """Waiting for status. @param status: status. @return: always True. """ log.debug("%s: waiting for status 0x%.04x", self.id, status) end = time.time() + self.timeout self.server._set_timeout(self.timeout) while db.guest_get_status(self.task_id) == "starting": # Check if we've passed the timeout. if time.time() > end: raise CuckooGuestCriticalTimeout( "Machine %s: the guest initialization hit the " "critical timeout, analysis aborted." % self.id) try: # If the server returns the given status, break the loop # and return. if self.server.get_status() == status: log.debug("%s: status ready", self.id) break except: pass log.debug("%s: not ready yet", self.id) time.sleep(1) self.server._set_timeout(None) return True
def wait_available(self): """Wait until the Virtual Machine is available for usage.""" end = time.time() + self.timeout while db.guest_get_status(self.task_id) == "starting": try: socket.create_connection((self.ipaddr, self.port), 1).close() break except socket.timeout: log.debug("%s: not ready yet", self.vmid) except socket.error: log.debug("%s: not ready yet", self.vmid) time.sleep(1) if time.time() > end: raise CuckooGuestCriticalTimeout( "Machine %s: the guest initialization hit the critical " "timeout, analysis aborted." % self.vmid)