Exemple #1
0
 def vps_open(self, vps_info, vps_image=None, is_new=True):
     vps_id = vps_info.id
     self.logger.info("to open vps %s" % (vps_id))
     if vps_info.host_id != self.host_id:
         msg = "vpsopen : vps %s host_id=%s != current host %s , abort" % (
             vps_id, vps_info.host_id, self.host_id)
         self.logger.error(msg)
         self.done_task(CMD.OPEN, vps_id, False, msg)
         return
     if not self.vpsinfo_check_ip(vps_info):
         msg = "no ip with vps %s" % (vps_id)
         self.logger.error(msg)
         self.done_task(CMD.OPEN, vps_id, False, msg)
         return
     xv = XenVPS(vps_id)
     try:
         domain_dict = XenStore.domain_name_id_map()
         limit = None
         if 'VPS_NUM_LIMIT' in dir(conf):
             limit = conf.VPS_NUM_LIMIT
         if limit and len(domain_dict.keys()) >= limit + 1:
             msg = "vps open: cannot open more than %d vps" % (limit)
             self.logger.error(msg)
             self.done_task(CMD.OPEN, vps_id, False, msg)
             return
         self.setup_vps(xv, vps_info)
         if xv.is_running():
             msg = "vps %s is running" % (vps_id)
             self.logger.error(msg)
             self.done_task(CMD.OPEN, vps_id, True, msg)
             return
         if vps_info.state in [VM_STATE.PAY, VM_STATE.OPEN, VM_STATE.CLOSE]:
             if self.vpsops.is_normal_exists(vps_id):
                 xv.check_storage_integrity()
                 xv.check_xen_config()
                 if not xv.is_running():
                     self.logger.info(
                         "seems vps %s was not closed, try to boot" %
                         (vps_id))
                     self.vpsops._boot_and_test(xv, is_new=False)
             elif self.vpsops.is_trash_exists(vps_id):
                 self.vpsops.reopen_vps(vps_id, xv)
             else:
                 self.vpsops.create_vps(xv, vps_image, is_new)
         else:
             msg = "vps%s state is %s(%s)" % (str(vps_id), vps_info.state,
                                              VM_STATE_CN[vps_info.state])
             self.logger.error(msg)
             self.done_task(CMD.OPEN, vps_id, False, msg)
             return
     except Exception, e:
         self.logger.exception("vps %s: %s" % (str(vps_id), str(e)))
         self.done_task(CMD.OPEN, vps_id, False, "error, " + str(e))
         return
Exemple #2
0
 def vps_open(self, vps_info, vps_image=None, is_new=True):
     vps_id = vps_info.id
     self.logger.info("to open vps %s" % (vps_id))
     if vps_info.host_id != self.host_id:
         msg = "vpsopen : vps %s host_id=%s != current host %s , abort" % (
             vps_id, vps_info.host_id, self.host_id)
         self.logger.error(msg)
         self.done_task(CMD.OPEN, vps_id, False, msg)
         return
     if not self.vpsinfo_check_ip(vps_info):
         msg = "no ip with vps %s" % (vps_id)
         self.logger.error(msg)
         self.done_task(CMD.OPEN, vps_id, False, msg)
         return
     xv = XenVPS(vps_id)
     try:
         domain_dict = XenStore.domain_name_id_map()
         limit = None
         if 'VPS_NUM_LIMIT' in dir(conf):
             limit = conf.VPS_NUM_LIMIT
         if limit and len(domain_dict.keys()) >= limit + 1:
             msg = "vps open: cannot open more than %d vps" % (limit)
             self.logger.error(msg)
             self.done_task(CMD.OPEN, vps_id, False, msg)
             return
         self.setup_vps(xv, vps_info)
         if xv.is_running():
             msg = "vps %s is running" % (vps_id)
             self.logger.error(msg)
             self.done_task(CMD.OPEN, vps_id, True, msg)
             return
         if vps_info.state in [VM_STATE.PAY, VM_STATE.OPEN, VM_STATE.CLOSE]:
             if self.vpsops.is_normal_exists(vps_id):
                 xv.check_storage_integrity()
                 xv.check_xen_config()
                 if not xv.is_running():
                     self.logger.info(
                         "seems vps %s was not closed, try to boot" % (vps_id))
                     self.vpsops._boot_and_test(xv, is_new=False)
             elif self.vpsops.is_trash_exists(vps_id):
                 self.vpsops.reopen_vps(vps_id, xv)
             else:
                 self.vpsops.create_vps(xv, vps_image, is_new)
         else:
             msg = "vps%s state is %s(%s)" % (
                 str(vps_id), vps_info.state, VM_STATE_CN[vps_info.state])
             self.logger.error(msg)
             self.done_task(CMD.OPEN, vps_id, False, msg)
             return
     except Exception, e:
         self.logger.exception("vps %s: %s" % (str(vps_id), str(e)))
         self.done_task(CMD.OPEN, vps_id, False, "error, " + str(e))
         return
Exemple #3
0
 def vps_open (self, vps, vps_image=None, is_new=True): 
     self.logger.info ("to open vps %s" % (vps.id))
     if vps.host_id != self.host_id:
         msg = "vpsopen : vps %s host_id=%s != current host %s , abort" % (vps.id, vps.host_id, self.host_id)
         self.logger.error (msg)
         self.done_task (Cmd.OPEN, vps.id, False, msg)
         return
     if not vps.ipv4 or not vps.ipv4_gateway or vps.cpu <= 0 or vps.ram <= 0 or vps.hd <= 0 or not vps.password:
         self.logger.error ("vps open: invalid vps data received: %s" % (self.dump_vps_info (vps)))
         self.done_task (Cmd.OPEN, vps.id, False, "invalid vps data")
         return
     xv = XenVPS (vps.id)
     vpsops = VPSOps (self.logger)
     try:
         self.setup_vps (xv, vps)
         if xv.is_running ():
             msg = "vps %s is running" % (vps.id)
             self.logger_err.error (msg)
             self.done_task (Cmd.OPEN, vps.id, False, msg)
             return
         if vps.state in [vps_const.VPS_STATE_PAY, vps_const.VPS_STATE_RUN]:
             vpsops.create_vps (xv, vps_image, is_new)
         elif vps.state == vps_const.VPS_STATE_CLOSE:
             vpsops.reopen_vps (vps.id, xv)
         else:
             msg = "vps%s state is %s(%s)" % (str(vps.id), vps.state, vps_const.VPS_STATE2CN[vps.state])
             self.logger_err.error (msg)
             self.done_task (Cmd.OPEN, vps.id, False, msg)
             return
     except Exception, e:
         self.logger_err.exception ("for %s: %s" % (str(vps.id), str(e)))
         self.done_task (Cmd.OPEN, vps.id, False, "error, " + str(e))
         return
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
 def vps_open(self, vps, vps_image=None, is_new=True):
     self.logger.info("to open vps %s" % (vps.id))
     if vps.host_id != self.host_id:
         msg = "vpsopen : vps %s host_id=%s != current host %s , abort" % (
             vps.id, vps.host_id, self.host_id)
         self.logger.error(msg)
         self.done_task(Cmd.OPEN, vps.id, False, msg)
         return
     if not vps.ipv4 or not vps.ipv4_gateway or vps.cpu <= 0 or vps.ram <= 0 or vps.hd <= 0 or not vps.password:
         self.logger.error("vps open: invalid vps data received: %s" %
                           (self.dump_vps_info(vps)))
         self.done_task(Cmd.OPEN, vps.id, False, "invalid vps data")
         return
     xv = XenVPS(vps.id)
     vpsops = VPSOps(self.logger)
     try:
         self.setup_vps(xv, vps)
         if xv.is_running():
             msg = "vps %s is running" % (vps.id)
             self.logger_err.error(msg)
             self.done_task(Cmd.OPEN, vps.id, False, msg)
             return
         if vps.state in [vps_const.VPS_STATE_PAY, vps_const.VPS_STATE_RUN]:
             vpsops.create_vps(xv, vps_image, is_new)
         elif vps.state == vps_const.VPS_STATE_CLOSE:
             vpsops.reopen_vps(vps.id, xv)
         else:
             msg = "vps%s state is %s(%s)" % (str(
                 vps.id), vps.state, vps_const.VPS_STATE2CN[vps.state])
             self.logger_err.error(msg)
             self.done_task(Cmd.OPEN, vps.id, False, msg)
             return
     except Exception, e:
         self.logger_err.exception("for %s: %s" % (str(vps.id), str(e)))
         self.done_task(Cmd.OPEN, vps.id, False, "error, " + str(e))
         return
Exemple #7
0
                 and "reachable" or "timeout")
            print "vps %s %s %s has no meta_data" % (vps_id, is_running, ip_ok)
            return


def check_via_backend(client, vps_id):
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
        if not vps_info:
            return False, None
    except Exception, e:
        raise e
    xv = XenVPS(vps_id)
    if vps_info.host_id != conf.HOST_ID:
        is_running = xv.is_running() and "(running)" or "(not running)"
        print "vps %s %s host_id=%s not on this host" % (vps_id, is_running,
                                                         vps_info.host_id)
        return True, None
    elif vps_info.state != VM_STATE.OPEN:
        is_running = xv.is_running() and "(running)" or "(not running)"
        print "vps %s %s backend state=%s " % (vps_id, is_running,
                                               VM_STATE_CN[vps_info.state])
        return True, None
    return False, vps_info


def check_all_vps():
    client = VPSMgr()
    all_ids = client.vpsops.all_vpsid_from_config()
    print "xen_config: %d, running: %d" % (len(all_ids),
Exemple #8
0
                 and "reachable" or "timeout")
            print "vps %s %s %s has no meta_data" % (vps_id, is_running, ip_ok)
            return


def check_via_backend(client, vps_id):
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
        if not vps_info:
            return False, None
    except Exception, e:
        raise e
    xv = XenVPS(vps_id)
    if vps_info.host_id != conf.HOST_ID:
        is_running = xv.is_running() and "(running)" or "(not running)"
        print "vps %s %s host_id=%s not on this host" % (vps_id, is_running, vps_info.host_id)
        return True, None
    elif vps_info.state != VM_STATE.OPEN:
        is_running = xv.is_running() and "(running)" or "(not running)"
        print "vps %s %s backend state=%s " % (vps_id, is_running, VM_STATE_CN[vps_info.state])
        return True, None
    return False, vps_info


def check_all_vps():
    client = VPSMgr()
    all_ids = client.vpsops.all_vpsid_from_config()
    print "xen_config: %d, running: %d" % (len(all_ids), client.vpsops.running_count)
    for vps_id in all_ids:
        checked, vps_info = check_via_backend(client, vps_id)