def is_started(self, has_os=True, timeout=120, err=True): """ has_os: using pre-created img or not, default = True timeout: timeout for vm start up, default = 120s """ current = time.time() start = time.time() endtime = current + timeout while current < endtime: if has_os: self.ip = self.query.get_vm_ip(self.name) # IP address verification self.verify_vm_ip() if ping.ping(self.ip): return time.time() - start else: try: result = self.host.run( "ps aux|grep fronvmm | grep -v grep").stdout.strip() except error.HostRunError: pass patt = re.compile(r"-name %s\b" % self.name, re.MULTILINE) if result and patt.search(result): return True current = time.time() time.sleep(1) if err: raise error.VMStartUpTimeoutError() else: return False
def check_boot(self, timeout): time.sleep(120) current = time.time() endtime = current + timeout interval = [120, 60, 30, 15, 2] count = 0 while current < endtime: if count >= len(interval): count = len(interval) - 1 time.sleep(interval[count]) count = count + 1 if ping.ping(get_state(self.system, 'IP Address')): return True current = time.time() return False
def __add_node(self, node_id, addr): try: latency = ping(addr[0]) insort_left(self.__node_list, (latency, addr, node_id)) except Exception: raise Exception(self.__error_node_info_data)