def check_via_meta(client, vps_id, vps_info): meta = client.vpsops._meta_path(vps_id, is_trash=False) if os.path.exists(meta): xv = client.vpsops._load_vps_meta(meta) is_running = xv.is_running() and "(running)" or "(not running)" ip_ok = "ip %s " % (xv.ip) if vps_common.ping(xv.ip): ip_ok += "reachable " else: if scan_port_open(xv.ip): ip_ok += "filtered icmp" else: ip_ok += "timeout (filtered all port?)" print "vps %s %s %s" % (vps_id, is_running, ip_ok) return else: xv = XenVPS(vps_id) is_running = xv.is_running() and "(running)" or "(not running)" if not vps_info: print "vps %s %s has neither meta data or backend data" % ( vps_id, is_running) return else: client.setup_vps(xv, vps_info) ip_ok = "ip %s " % (xv.ip) + \ (vps_common.ping(xv.ip) and "reachable" or "timeout") print "vps %s %s %s has no meta_data" % (vps_id, is_running, ip_ok) return
def check_via_meta(client, vps_id, vps_info): meta = client.vpsops._meta_path(vps_id, is_trash=False) if os.path.exists(meta): xv = client.vpsops._load_vps_meta(meta) is_running = xv.is_running() and "(running)" or "(not running)" ip_ok = "ip %s " % (xv.ip) if vps_common.ping(xv.ip): ip_ok += "reachable " else: if scan_port_open(xv.ip): ip_ok += "filtered icmp" else: ip_ok += "timeout (filtered all port?)" print "vps %s %s %s" % (vps_id, is_running, ip_ok) return else: xv = XenVPS(vps_id) is_running = xv.is_running() and "(running)" or "(not running)" if not vps_info: print "vps %s %s has neither meta data or backend data" % (vps_id, is_running) return else: client.setup_vps(xv, vps_info) ip_ok = "ip %s " % (xv.ip) + \ (vps_common.ping(xv.ip) and "reachable" or "timeout") print "vps %s %s %s has no meta_data" % (vps_id, is_running, ip_ok) return
def set_vif_int(self, vps_id, ip, netmask): # if run again, vif's MAC is the same with previous one meta_path = self._meta_path(vps_id, is_trash=False) xv = None if os.path.exists(meta_path): xv = self._load_vps_meta(meta_path) else: raise Exception("cannot find meta data for vps %s" % (vps_id)) vifname = "%sint" % (xv.name) mac = None is_ip_available = not vps_common.ping(ip) if xv.has_netinf(vifname): mac = xv.vifs[vifname].mac if ip in xv.vifs[vifname].ip_dict.keys(): self.loginfo(xv, "no need to change vif %s, ip is the same" % (vifname)) return False if not is_ip_available: raise Exception("ip %s is in use" % (ip)) self.loginfo(xv, "removing existing vif %s" % (vifname)) vps_common.xm_network_detach(xv.name, mac) xv.del_netinf(vifname) elif not is_ip_available: raise Exception("ip %s is in use" % (ip)) vif = xv.add_netinf_int({ip: netmask}, mac) vps_common.xm_network_attach(xv.name, vifname, vif.mac, ip, vif.bridge) self.create_xen_config(xv) self.loginfo(xv, "added internal vif ip=%s" % (ip)) return True
def set_vif_int(self, vps_id, ip, netmask): # if run again, vif's MAC is the same with previous one meta_path = self._meta_path(vps_id, is_trash=False) xv = None if os.path.exists(meta_path): xv = self._load_vps_meta(meta_path) else: raise Exception("cannot find meta data for vps %s" % (vps_id)) vifname = "%sint" % (xv.name) mac = None is_ip_available = not vps_common.ping(ip) if xv.has_netinf(vifname): mac = xv.vifs[vifname].mac if ip in xv.vifs[vifname].ip_dict.keys(): self.loginfo( xv, "no need to change vif %s, ip is the same" % (vifname)) return False if not is_ip_available: raise Exception("ip %s is in use" % (ip)) self.loginfo(xv, "removing existing vif %s" % (vifname)) vps_common.xm_network_detach(xv.name, mac) xv.del_netinf(vifname) elif not is_ip_available: raise Exception("ip %s is in use" % (ip)) vif = xv.add_netinf_int({ip: netmask}, mac) vps_common.xm_network_attach(xv.name, vifname, vif.mac, ip, vif.bridge) self.create_xen_config(xv) self.loginfo(xv, "added internal vif ip=%s" % (ip)) return True