示例#1
0
def send_alarm(msg):
    mgr = VPSMgr()
    rpc = mgr.rpc_connect()
    try:
        rpc.alarm(msg)
    finally:
        rpc.close()
示例#2
0
def reinstall_os(vps_id, os_id=None, vps_image=None):
    client = VPSMgr()
    vps = None
    try:
        vps = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state:" + type(e) + str(e)
示例#3
0
文件: send_alarm.py 项目: 42qu/vps
def send_alarm(msg):
    mgr = VPSMgr()
    rpc = mgr.rpc_connect()
    try:
        rpc.alarm(msg)
    finally:
        rpc.close()
示例#4
0
文件: reinstall_os.py 项目: 42qu/vps
def reinstall_os(vps_id, os_id=None, vps_image=None):
    client = VPSMgr()
    vps = None
    try:
        vps = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
示例#5
0
def upgrade_vps(vps_id):
    client = VPSMgr()
    vps = None
    try:
        vps = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        return
示例#6
0
文件: migrate_vps.py 项目: 42qu/vps
def migrate_vps(vps_id, dest_ip=None, speed=None, force=False):
    client = VPSMgr()
    if force:
        assert dest_ip
    if client._vps_migrate(vps_id, force=force, to_host_ip=dest_ip, speed=speed):
        print "ok"
    else:
        print "error, pls see log"
示例#7
0
def change_ip(vps_id):
    client = VPSMgr()
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        os._exit(1)
示例#8
0
def add_vif_int(vps_id):
    client = VPSMgr()
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        return
示例#9
0
文件: upgrade_vps.py 项目: 42qu/vps
def upgrade_vps(vps_id):
    client = VPSMgr()
    vps = None
    try:
        vps = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        return
示例#10
0
def add_vif_int(vps_id):
    client = VPSMgr()
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        return
示例#11
0
def create_vps (vps_id, vps_image=None, is_new=True):
    client = VPSMgr ()
    vps = None
    try:
        vps = client.query_vps (vps_id)
    except Exception, e:
        print "failed to query vps state:" + type(e) + str(e)
        return
示例#12
0
def reopen_vps(vps_id):
    client = VPSMgr()
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: %s %s " % (type(e), str(e))
        return False
示例#13
0
def create_vps(vps_id, vps_image=None, is_new=True):
    client = VPSMgr()
    vps = None
    try:
        vps = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        return
示例#14
0
def close_vps(vps_id):
    client = VPSMgr()
    vps = None
    try:
        vps = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state:" + type(e) + str(e)
        return
示例#15
0
文件: close_vps.py 项目: wwq0327/vps
def close_vps(vps_id):
    client = VPSMgr()
    vps = None
    try:
        vps = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state:" + type(e) + str(e)
        return
示例#16
0
文件: change_ip.py 项目: 42qu/vps
def change_ip(vps_id):
    client = VPSMgr()
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        os._exit(1)
示例#17
0
文件: hotsync_vps.py 项目: 42qu/vps
def hotsync_vps(vps_id, dest_ip, speed=None, force=False):
    client = VPSMgr()
    task = client.query_migrate_task(vps_id)
    if task is not None and task.state == MIGRATE_STATE.NEW:
        force = True
    if client._vps_hot_sync(vps_id, to_host_ip=dest_ip, speed=speed, force=force):
        print "%s ok" % (vps_id)
    else:
        print "error, pls see log"
示例#18
0
文件: saas_test.py 项目: wwq0327/vps
 def test_state (self):
     trans, client = get_client (saas.VPS)
     print "test state"
     trans.open ()
     try:
         vps = client.vps (65)
         print VPSMgr.dump_vps_info (vps)
     finally:
         trans.close ()
示例#19
0
文件: saas_test.py 项目: wwq0327/vps
 def test_state(self):
     trans, client = get_client(saas.VPS)
     print "test state"
     trans.open()
     try:
         vps = client.vps(65)
         print VPSMgr.dump_vps_info(vps)
     finally:
         trans.close()
示例#20
0
def delete_vps(vps_id, forced=False):
    """ interact operation """
    client = VPSMgr()
    vps = None
    try:
        vps = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (str(type(e)), str(e))
        if not forced:
            return
示例#21
0
def check_all(dry=True):
    assert conf.XEN_CONFIG_DIR and os.path.isdir(conf.XEN_CONFIG_DIR)
    assert conf.VPS_METADATA_DIR and os.path.isdir(conf.VPS_METADATA_DIR)
    client = VPSMgr()
    all_ids = client.vpsops.all_vpsid_from_config()
    print "meta %d" % (len(all_ids))
    client.logger.info("----check expired images---")
    for vps_id in all_ids:
        _check_disk(client, vps_id, dry=dry)
    client.refresh_host_space()
示例#22
0
def move_closed_vps(vps_id, dest_ip, speed=None, force=False):
    logger = Log("vps_mgr", config=conf)
    client = VPSMgr()
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        if not force:
            os._exit(1)
示例#23
0
def move_closed_vps(vps_id, dest_ip, speed=None, force=False):
    logger = Log("vps_mgr", config=conf)
    client = VPSMgr()
    vps_info = None
    try:
        vps_info = client.query_vps(vps_id)
    except Exception, e:
        print "failed to query vps state: [%s] %s" % (type(e), str(e))
        if not force:
            os._exit(1)
示例#24
0
文件: clean_disk.py 项目: 42qu/vps
def check_all(dry=True):
    assert conf.XEN_CONFIG_DIR and os.path.isdir(conf.XEN_CONFIG_DIR)
    assert conf.VPS_METADATA_DIR and os.path.isdir(conf.VPS_METADATA_DIR)
    client = VPSMgr()
    all_ids = client.vpsops.all_vpsid_from_config()
    print "meta %d" % (len(all_ids))
    client.logger.info("----check expired images---")
    for vps_id in all_ids:
        _check_disk(client, vps_id, dry=dry)
    client.refresh_host_space()
示例#25
0
def migrate_vps(vps_id, dest_ip=None, speed=None, force=False):
    client = VPSMgr()
    if force:
        assert dest_ip
    if client._vps_migrate(vps_id,
                           force=force,
                           to_host_ip=dest_ip,
                           speed=speed):
        print "ok"
    else:
        print "error, pls see log"
示例#26
0
def hotsync_vps(vps_id, dest_ip, speed=None, force=False):
    client = VPSMgr()
    task = client.query_migrate_task(vps_id)
    if task is not None and task.state == MIGRATE_STATE.NEW:
        force = True
    if client._vps_hot_sync(vps_id,
                            to_host_ip=dest_ip,
                            speed=speed,
                            force=force):
        print "%s ok" % (vps_id)
    else:
        print "error, pls see log"
示例#27
0
def main():
    if len(sys.argv) <= 1:
        usage()
        return
    vps_id = sys.argv[1]
    mgr = VPSMgr()
    rpc = mgr.rpc_connect()
    try:
        vps = rpc.vps(vps_id)
        print mgr.dump_vps_info(vps)
    finally:
        rpc.close()
示例#28
0
def main():
    if len(sys.argv) <= 1:
        usage()
        return
    vps_id = int(sys.argv[1])
    mgr = VPSMgr()
    trans, client = mgr.get_client()
    trans.open()
    try:
        vps = client.vps(vps_id)
        print mgr.dump_vps_info(vps)
    finally:
        trans.close()
示例#29
0
def main ():
    if len (sys.argv) <= 1:
        usage ()
        return
    vps_id = int(sys.argv[1])
    mgr = VPSMgr ()
    trans, client = mgr.get_client ()
    trans.open ()
    try:
        vps = client.vps (vps_id)
        print mgr.dump_vps_info (vps)
    finally:
        trans.close ()
示例#30
0
def main():
    logger = Log("vps_mgr", config=conf)
    mgr = VPSMgr()
    host_list = None
    try:
        rpc = mgr.rpc_connect()
        try:
            host_list = rpc.host_list()
        finally:
            rpc.close()
        update_iplist(host_list)
    except Exception, e:
        print e
        logger.exception(e)
        return
示例#31
0
def main():
    logger = Log("vps_mgr", config=conf)
    mgr = VPSMgr()
    host_list = None
    try:
        rpc = mgr.rpc_connect()
        try:
            host_list = rpc.host_list()
        finally:
            rpc.close()
        update_iplist(host_list)
    except Exception, e:
        print e
        logger.exception(e)
        return
示例#32
0
def main():
    vps_mgr = VPSMgr()
    domain_dict = XenStore.domain_name_id_map()
    for k, v in domain_dict.iteritems():
        om = re.match(r'^vps(\d+)$', k)
        if om:
            print int(om.group(1))
            gen_meta(vps_mgr, domain_dict, int(om.group(1)))
示例#33
0
def check_all_vps ():
    assert conf.XEN_CONFIG_DIR and os.path.isdir (conf.XEN_CONFIG_DIR)
    assert conf.VPS_METADATA_DIR and os.path.isdir (conf.VPS_METADATA_DIR)
    client = VPSMgr ()
    all_ids = client.vpsops.all_vpsid_from_config()
    print ""
    print "xen_config: %d, running: %d"  % (len(all_ids), client.vpsops.running_count)
    for vps_id in all_ids:
        add_vif_int (vps_id)
示例#34
0
def main():
    if len(sys.argv) < 2:
        usage()
        os._exit(0)
    vps_id = int(sys.argv[1])

    client = VPSMgr()
    vpsops = client.vpsops
    xv = vpsops.load_vps_meta(vps_id)
    vpsops.create_xen_config(xv)
示例#35
0
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)
        if checked:
            continue
        check_via_meta(client, vps_id, vps_info)
示例#36
0
def check_all():
    assert conf.XEN_CONFIG_DIR and os.path.isdir(conf.XEN_CONFIG_DIR)
    assert conf.VPS_METADATA_DIR and os.path.isdir(conf.VPS_METADATA_DIR)
    client = VPSMgr()
    ovsops = OVSOps()
    all_ids = client.vpsops.all_vpsid_from_config()
    print ""
    print "xen_config: %d, running: %d" % (len(all_ids), client.vpsops.running_count)
    for vps_id in all_ids:
        print "vps", vps_id
        _clear_filter(client, ovsops, vps_id)
示例#37
0
def main():
    log_dir = conf.log_dir
    if not os.path.exists(log_dir):
        os.makedirs(log_dir, 0700)
    run_dir = conf.run_dir
    if not os.path.exists(run_dir):
        os.makedirs(run_dir, 0700)
    os.chdir(run_dir)
    vps = VPSMgr()
    vps.handlers = dict()
    vps.handlers[Cmd.OPEN] = vps_open_mock
    vps.start()
    vps.loop()
示例#38
0
文件: raid_mon.py 项目: hackudown/vps
class RaidMonitor(object):
    def __init__(self):
        self.logger = Log("raid_mon", config=conf)
        self.is_running = False
        self.last_state = True
        self.vps_mgr = VPSMgr()
        self.hostname = socket.gethostname()

    def start(self):
        if self.is_running:
            return
        self.is_running = True
        self.logger.info("started")

    def stop(self):
        if not self.is_running:
            return
        self.is_running = False

    def send_alarm(self, msg):
        rpc = self.vps_mgr.rpc_connect()
        try:
            rpc.alarm("%s: raid_mon: %s" % (self.hostname, msg))
        finally:
            rpc.close()

    def check(self):
        cmd = """MegaCli64 -pdlist -aall | grep -i 'firmware state:' | grep -P -v -i "online|Unconfigured\(good\)" """
        try:
            out, err = subprocess.Popen(cmd,
                                        shell=True,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE).communicate()
            msg = out + err
            if msg:
                self.logger.error(msg)
                if self.last_state:
                    self.last_state = False
                    self.send_alarm("error, %s" % (out))
                    self.logger.error("alarm sent")
            else:
                self.logger.info("ok")
                if not self.last_state:
                    self.send_alarm("ok")
                    self.last_state = True
        except Exception, e:
            self.logger.exception(e)
示例#39
0
 def test_invalid (self):
     self.rpc.connect ()
     print "connected"
     try:
         vps = self.rpc.vps (0)
         print VPSMgr.dump_vps_info (vps)
         self.assert_ (not VPSMgr.vps_is_valid (vps))
         vps = self.rpc.vps (100000000)
         print VPSMgr.dump_vps_info (vps)
         self.assert_ (not VPSMgr.vps_is_valid (vps))
     finally:
         self.rpc.close ()
示例#40
0
文件: raid_mon.py 项目: 42qu/vps
class RaidMonitor(object):

    def __init__(self):
        self.logger = Log("raid_mon", config=conf)
        self.is_running = False
        self.last_state = True
        self.vps_mgr = VPSMgr()
        self.hostname = socket.gethostname()

    def start(self):
        if self.is_running:
            return
        self.is_running = True
        self.logger.info("started")

    def stop(self):
        if not self.is_running:
            return
        self.is_running = False

    def send_alarm(self, msg):
        rpc = self.vps_mgr.rpc_connect()
        try:
            rpc.alarm("%s: raid_mon: %s" % (self.hostname, msg))
        finally:
            rpc.close()

    def check(self):
        cmd = """MegaCli64 -pdlist -aall | grep -i 'firmware state:' | grep -P -v -i "online|Unconfigured\(good\)" """
        try:
            out, err = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
            msg = out + err
            if msg:
                self.logger.error(msg)
                if self.last_state:
                    self.last_state = False
                    self.send_alarm("error, %s" % (out))
                    self.logger.error("alarm sent")
            else:
                self.logger.info("ok")
                if not self.last_state:
                    self.send_alarm("ok")
                    self.last_state = True
        except Exception, e:
            self.logger.exception(e)
示例#41
0
def main ():
    log_dir = conf.log_dir
    if not os.path.exists (log_dir):
        os.makedirs (log_dir, 0700)
    run_dir = conf.run_dir
    if not os.path.exists (run_dir):
        os.makedirs (run_dir, 0700)
    os.chdir (run_dir)
    vps = VPSMgr ()
    vps.handlers = dict ()
    vps.handlers[Cmd.OPEN] = vps_open_mock
    vps.start ()
    vps.loop ()
示例#42
0
文件: saas_test.py 项目: wwq0327/vps
 def test_invalid (self):
     trans, client = get_client (saas.VPS)
     trans.open ()
     print "connected"
     try:
         vps = client.vps (0)
         print VPSMgr.dump_vps_info (vps)
         self.assert_ (not VPSMgr.vps_is_valid (vps))
         vps = client.vps (100000000)
         print VPSMgr.dump_vps_info (vps)
         self.assert_ (not VPSMgr.vps_is_valid (vps))
     finally:
         trans.close ()
示例#43
0
文件: saas_test.py 项目: wwq0327/vps
 def test_invalid(self):
     trans, client = get_client(saas.VPS)
     trans.open()
     print "connected"
     try:
         vps = client.vps(0)
         print VPSMgr.dump_vps_info(vps)
         self.assert_(not VPSMgr.vps_is_valid(vps))
         vps = client.vps(100000000)
         print VPSMgr.dump_vps_info(vps)
         self.assert_(not VPSMgr.vps_is_valid(vps))
     finally:
         trans.close()
示例#44
0
def check_all():
    import getopt
    mode = None
    pretend = False
    opt_list, args = getopt.gnu_getopt(sys.argv, "", ["down", "reset", "help"])
    for opt, v in opt_list:
        if opt == '--help':
            usage()
            return
        elif opt == '--down':
            mode = 'down'
        elif opt == '--reset':
            mode = 'reset'

    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:
        print "vps", vps_id
        _set_cgroup(client, vps_id, mode)
示例#45
0
文件: host_refresh.py 项目: 42qu/vps
#!/usr/bin/env python

import _env
import conf
#from ops.vps_common import vg_free_space
from vps_mgr import VPSMgr

if __name__ == '__main__':
    client = VPSMgr ()
    client.refresh_host_space ()

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 :
示例#46
0
def save(name):
    xen = get_xen_inf()
    client = VPSMgr()
    save_file = os.path.join(conf.SAVE_PATH, name)
    xen.save(name, save_file)
    client.logger.info("saved %s to %s" % (name, save_file))
示例#47
0
文件: raid_mon.py 项目: 42qu/vps
 def __init__(self):
     self.logger = Log("raid_mon", config=conf)
     self.is_running = False
     self.last_state = True
     self.vps_mgr = VPSMgr()
     self.hostname = socket.gethostname()
示例#48
0
文件: saas_test.py 项目: wwq0327/vps
 def test_netflow(self):
     m = VPSMgr()
     m.send_netflow()
示例#49
0
文件: saas_test.py 项目: 42qu/vps
 def test_done (self):
     m = VPSMgr ()
     m.done_task (CMD.OPEN, 4, True)
示例#50
0
文件: saas_test.py 项目: 42qu/vps
 def test_migrate_task (self):
     m = VPSMgr ()
     task = m.query_migrate_task (1030)
     print task
示例#51
0
#!/usr/bin/env python

import _env
import conf
from ops.vps_common import vg_free_space
from vps_mgr import VPSMgr

if __name__ == '__main__':
    disk_free = vg_free_space(conf.VPS_LVM_VGNAME)
    print disk_free
    client = VPSMgr()
    client.refresh_host_space()

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 :
示例#52
0
def main():
    client = VPSMgr()
    all_ids = client.vpsops.all_vpsid_from_config()
    for vps_id in all_ids:
        change_meta(client, vps_id)