Ejemplo n.º 1
0
    def setup(self,
              os_id,
              vcpu,
              mem_m,
              disk_g,
              root_pw=None,
              gateway=None,
              ip=None,
              netmask=None,
              swp_g=None):
        """ on error will raise Exception """
        assert mem_m > 0 and disk_g > 0 and vcpu > 0
        self.has_all_attr = True
        self.os_id = os_id
        self.vcpu = vcpu
        self.mem_m = mem_m
        if swp_g is not None:
            swp_g = swp_g
        else:
            if self.mem_m >= 2000:
                swp_g = 2
            else:
                swp_g = 1

        if conf.USE_LVM:
            assert conf.VPS_LVM_VGNAME
            self.root_store = VPSStoreLV("xvda1", conf.VPS_LVM_VGNAME,
                                         "%s_root" % self.name, None, '/',
                                         disk_g)
            self.swap_store = VPSStoreLV("xvda2", conf.VPS_LVM_VGNAME,
                                         "%s_swap" % self.name, 'swap', 'none',
                                         swp_g)
        else:
            self.root_store = VPSStoreImage("xvda1", conf.VPS_IMAGE_DIR,
                                            conf.VPS_TRASH_DIR,
                                            "%s.img" % self.name, None, '/',
                                            disk_g)
            self.swap_store = VPSStoreImage("xvda2", conf.VPS_SWAP_DIR,
                                            conf.VPS_TRASH_DIR,
                                            "%s.swp" % self.name, 'swap',
                                            'none', swp_g)

        self.data_disks[self.root_store.xen_dev] = self.root_store
        self.root_pw = root_pw
        self.gateway = gateway
        if ip:
            assert ip and netmask is not None and gateway and isinstance(
                netmask, basestring)
            self.ip = ip
            self.netmask = netmask
            self.add_netinf(self.name,
                            ip,
                            netmask,
                            bridge=self.xen_bridge,
                            mac=None)
Ejemplo n.º 2
0
 def renew_root_storage(self, expire_days=5):
     old_root = self.root_store
     old_root.dump_trash(expire_days)
     self.trash_disks[old_root.xen_dev] = old_root
     if conf.USE_LVM:
         assert conf.VPS_LVM_VGNAME
         self.root_store = VPSStoreLV("xvda1", conf.VPS_LVM_VGNAME,
                                      "%s_root" % self.name, None, '/',
                                      old_root.size_g)
     else:
         self.root_store = VPSStoreImage("xvda1", conf.VPS_IMAGE_DIR,
                                         conf.VPS_TRASH_DIR,
                                         "%s.img" % self.name, None, '/',
                                         old_root.size_g)
     self.data_disks[self.root_store.xen_dev] = self.root_store
Ejemplo n.º 3
0
 def add_extra_storage(self, disk_id, size_g, fs_type=conf.DEFAULT_FS_TYPE):
     assert disk_id > 0
     assert size_g > 0
     xen_dev = self.get_xendev_by_id(disk_id)
     mount_point = '/mnt/data%d' % (disk_id)
     if conf.USE_LVM:
         assert conf.VPS_LVM_VGNAME
         lv_name = "%s_data%s" % (self.name, disk_id)
         self.data_disks[xen_dev] = VPSStoreLV(xen_dev, conf.VPS_LVM_VGNAME,
                                               lv_name, fs_type,
                                               mount_point, size_g)
     else:
         filename = "%s_data%s.img" % (self.name, disk_id)
         self.data_disks[xen_dev] = VPSStoreImage(xen_dev,
                                                  conf.VPS_IMAGE_DIR,
                                                  conf.VPS_TRASH_DIR,
                                                  filename, fs_type,
                                                  mount_point, size_g)