def send_alarm(msg): mgr = VPSMgr() rpc = mgr.rpc_connect() try: rpc.alarm(msg) finally: rpc.close()
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)
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))
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
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"
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)
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
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
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
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
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
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"
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 ()
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()
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
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()
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)
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()
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()
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 ()
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
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)))
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)
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)
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)
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)
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()
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)
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 ()
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 ()
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 ()
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()
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)
#!/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 :
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))
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 test_netflow(self): m = VPSMgr() m.send_netflow()
def test_done (self): m = VPSMgr () m.done_task (CMD.OPEN, 4, True)
def test_migrate_task (self): m = VPSMgr () task = m.query_migrate_task (1030) print task
#!/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 :
def main(): client = VPSMgr() all_ids = client.vpsops.all_vpsid_from_config() for vps_id in all_ids: change_meta(client, vps_id)