Example #1
0
 def __init__(self, _id):
     assert isinstance(_id, int)
     self.vps_id = _id
     # to be compatible with current practice standard
     self.name = "vps%s" % (str(_id).zfill(2))
     self.config_path = os.path.join(conf.XEN_CONFIG_DIR, self.name)
     self.auto_config_path = os.path.join(conf.XEN_AUTO_DIR, self.name)
     self.save_path = os.path.join(conf.MOUNT_POINT_DIR,
                                   "%s.save" % self.name)
     self.xen_bridge = conf.XEN_BRIDGE
     self.has_all_attr = False
     self.xen_inf = ixen.get_xen_inf()
     self.vif_ext_name = self.name
     self.vif_int_name = self.name + "int"
     self.data_disks = {}
     self.trash_disks = {}
     self.vifs = {}
     self.root_store = None
     self.swap_store = None
     self.ip = None  # main ip
     self.netmask = None  # main ip netmask
     self.gateway = None
     self.os_id = None
     self.root_pw = None
     self.vcpu = None
     self.mem_m = None
     self.disk_g = None
     assert conf.XEN_CONFIG_DIR
     assert conf.XEN_AUTO_DIR
     assert conf.DEFAULT_FS_TYPE
     assert conf.VPS_METADATA_DIR
     assert conf.MOUNT_POINT_DIR
Example #2
0
File: vps.py Project: 42qu/vps
 def __init__(self, _id):
     assert isinstance(_id, int)
     self.vps_id = _id
     # to be compatible with current practice standard
     self.name = "vps%s" % (str(_id).zfill(2))
     self.config_path = os.path.join(conf.XEN_CONFIG_DIR, self.name)
     self.auto_config_path = os.path.join(conf.XEN_AUTO_DIR, self.name)
     self.save_path = os.path.join(
         conf.MOUNT_POINT_DIR, "%s.save" % self.name)
     self.xen_bridge = conf.XEN_BRIDGE
     self.has_all_attr = False
     self.xen_inf = ixen.get_xen_inf()
     self.vif_ext_name = self.name
     self.vif_int_name = self.name + "int"
     self.data_disks = {}
     self.trash_disks = {}
     self.vifs = {}
     self.root_store = None
     self.swap_store = None
     self.ip = None  # main ip
     self.netmask = None  # main ip netmask
     self.gateway = None
     self.os_id = None
     self.root_pw = None
     self.vcpu = None
     self.mem_m = None
     self.disk_g = None
     assert conf.XEN_CONFIG_DIR
     assert conf.XEN_AUTO_DIR
     assert conf.DEFAULT_FS_TYPE
     assert conf.VPS_METADATA_DIR
     assert conf.MOUNT_POINT_DIR
Example #3
0
File: vps_mgr.py Project: 42qu/vps
 def refresh_host_space(self):
     disk_remain = None
     mem_remain = None
     disk_total = None
     mem_total = None
     try:
         disk_remain = -1
         disk_total = -1
         if conf.USE_LVM:
             # in g
             disk_remain, disk_total = vps_common.vg_space(
                 conf.VPS_LVM_VGNAME)
             if "LVM_VG_MIN_SPACE" in dir(conf) and conf.LVM_VG_MIN_SPACE:
                 extra = int(conf.LVM_VG_MIN_SPACE)
                 disk_remain -= extra
             if disk_remain < 0:
                 disk_remain = 0
         xen_inf = get_xen_inf()
         mem_remain = xen_inf.mem_free()  # in m
         mem_total = xen_inf.mem_total()
     except Exception, e:
         self.logger.exception(e)
         return
Example #4
0
 def refresh_host_space(self):
     disk_remain = None
     mem_remain = None
     disk_total = None
     mem_total = None
     try:
         disk_remain = -1
         disk_total = -1
         if conf.USE_LVM:
             # in g
             disk_remain, disk_total = vps_common.vg_space(
                 conf.VPS_LVM_VGNAME)
             if "LVM_VG_MIN_SPACE" in dir(conf) and conf.LVM_VG_MIN_SPACE:
                 extra = int(conf.LVM_VG_MIN_SPACE)
                 disk_remain -= extra
             if disk_remain < 0:
                 disk_remain = 0
         xen_inf = get_xen_inf()
         mem_remain = xen_inf.mem_free()  # in m
         mem_total = xen_inf.mem_total()
     except Exception, e:
         self.logger.exception(e)
         return
Example #5
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))
Example #6
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))
Example #7
0
def _load(file_path):
    xen = get_xen_inf()
    client = VPSMgr()
    xen.restore(file_path)
    client.logger.info("restore %s" % (file_path))
    os.unlink(file_path)