Exemple #1
0
    def extend_lvm(self, lvm_name, extend_size):
        ""

        # 1 ²éѯ
        infos = self.info_lvm(lvm_name)
        if infos is None:
            raise CustomException("lvm is not exist.")

        vg_name = infos['vg_name']
        lvm_size = infos['lvm_size']

        # 2 À©Õ¹lvm
        lvm = LvmDriver(vg_name)
        lvm.extend_volume(lvm_name, "+" + str(lvm_size) + "M")

        cmd = Command()
        lvm_path = self.get_lvm_path(lvm_name, vg_name)

        # 3 ɨÃè
        cmd.execute("e2fsck -f -y %s" % lvm_path)

        # 4 ÖØÖÃ
        cmd.execute("resize2fs %s" % lvm_path)

        lvm_new_size = int(infos['lvm_size']) + int(extend_size)
        # 5 ¸üÐÂÊý¾Ý¿â
        update_sql = 'UPDATE lvm SET lvmSize = ? WHERE lvmName = ? '
        data = [(lvm_new_size, lvm_name)]

        storage_conf = self.conf.get_storage_conf()
        storage_db = storage_conf['db_path']
        sql_tools = SqliteTools(storage_db)
        sql_tools.update(update_sql, data)
Exemple #2
0
    def set_vm_cpu(self, vm_name, vcpus):
        ""

        # 1 检测
        self.check(vm_name)

        # 2 设置cpu
        self.vm_tools.set_vcpus(vm_name=vm_name, vcpus=vcpus)

        # 3 修改数据库
        virtual_conf = self.conf.get_virtual_conf()
        virtual_db = virtual_conf['db_path']
        sql_tools = SqliteTools(virtual_db)
        update_sql = 'UPDATE %s SET vcpus = ? WHERE vmName = ? ' % VMTABLE
        data = [(vcpus, vm_name)]
        sql_tools.update(update_sql, data)
Exemple #3
0
    def set_vm_mem(self, vm_name, size):
        ""

        # 1 检测
        self.check(vm_name)

        # 2 设置内存
        self.vm_tools.set_mem(vm_name=vm_name, memory=size)

        # 3 修改数据库
        virtual_conf = self.conf.get_virtual_conf()
        virtual_db = virtual_conf['db_path']
        sql_tools = SqliteTools(virtual_db)
        update_sql = 'UPDATE %s SET memSize = ? WHERE vmName = ? ' % VMTABLE
        data = [(size, vm_name)]
        sql_tools.update(update_sql, data)
Exemple #4
0
 def drop_image(self,image_name):
     ""
     
     image_conf = self.conf.get_image_conf()
     image_path = image_conf['path']
     
     image_file = os.path.join(image_path,image_name)
     if os.path.isfile(image_file): 
         os.remove(image_file)
     
     update_sql = 'UPDATE images SET status = ? WHERE name = ? '
     data = [(9, image_name)]
     
     images_db = image_conf['db_path']
     sql_tools = SqliteTools(images_db)
     sql_tools.update(update_sql,data)
Exemple #5
0
            return

        extend_size = int(total_size) - int(disk_size)
        # 4 扩展磁盘
        try:
            self.storageManage.extend_lvm(disk_name, extend_size)
        except Exception, e:
            raise CustomException("Error: extend lvm failed!")

        # 5 修改数据库
        virtual_conf = self.conf.get_virtual_conf()
        virtual_db = virtual_conf['db_path']
        sql_tools = SqliteTools(virtual_db)
        update_sql = 'UPDATE %s SET diskSize = ? WHERE vmName = ? and diskName = ?' % DISKTABLE
        data = [(total_size, vm_name, disk_name)]
        sql_tools.update(update_sql, data)

    # 得到vnc端口
    def get_vnc_port(self):
        ""

        virtual_conf = self.conf.get_virtual_conf()
        vnc_port_range = virtual_conf['vnc_port_range']
        min_port, max_port = vnc_port_range.split('-')

        #查询当前vnc端口
        virtual_db = virtual_conf['db_path']
        sql_tools = SqliteTools(virtual_db)
        fetchall_sql = '''SELECT vncPort FROM %s order by vncPort''' % VMTABLE
        ports = sql_tools.fetchall(fetchall_sql)