Beispiel #1
0
def send_alarm(msg):
    mgr = VPSMgr()
    rpc = mgr.rpc_connect()
    try:
        rpc.alarm(msg)
    finally:
        rpc.close()
Beispiel #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)
Beispiel #3
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
Beispiel #4
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)))
Beispiel #5
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
Beispiel #6
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
Beispiel #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)
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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)
Beispiel #11
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()
Beispiel #12
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
Beispiel #13
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)
Beispiel #14
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)
Beispiel #15
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)
Beispiel #16
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)
Beispiel #17
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"
Beispiel #18
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"
Beispiel #19
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()
Beispiel #20
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()
Beispiel #21
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()
Beispiel #22
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
Beispiel #23
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)
Beispiel #24
0
 def test_netflow (self):
     m = VPSMgr ()
     m.send_netflow ()
Beispiel #25
0
 def setUp (self):
     self.m = VPSMgr ()
     self.rpc = SAAS_Client (0, self.m.logger)
Beispiel #26
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))
Beispiel #27
0
 def test_done (self):
     m = VPSMgr ()
     m.done_task (CMD.OPEN, 4, True)
Beispiel #28
0
 def test_migrate_task (self):
     m = VPSMgr ()
     task = m.query_migrate_task (1030)
     print task
Beispiel #29
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 :
Beispiel #30
0
def main():
    client = VPSMgr()
    all_ids = client.vpsops.all_vpsid_from_config()
    for vps_id in all_ids:
        change_meta(client, vps_id)