__init__.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:kcli 作者: karmab 项目源码 文件源码
def add_disk(self, name, size, pool=None, thin=True, template=None, shareable=False, existing=None):
        conn = self.conn
        # diskformat = 'qcow2'
        if size < 1:
            print("Incorrect size.Leaving...")
            return {'result': 'failure', 'reason': "Incorrect size"}
        # if not thin:
        #     diskformat = 'raw'
        try:
            vm = conn.find_machine(name)
        except:
            common.pprint("VM %s not found" % name, color='red')
            return {'result': 'failure', 'reason': "VM %s not found" % name}
        disks = []
        for index, dev in enumerate(string.lowercase[:10]):
            try:
                vm.get_medium('SATA', index, 0)
                disks.append(0)
            except:
                continue
        index = len(disks)
        if existing is None:
            storagename = "%s_%d" % (name, index)
            diskpath = self.create_disk(name=storagename, size=size, pool=pool, thin=thin, template=template)
        else:
            disks = self.list_disks()
            if existing in disks:
                diskpath = disks[existing]['path']
            else:
                diskpath = existing
        session = Session()
        vm.lock_machine(session, library.LockType.write)
        machine = session.machine
        disk = conn.open_medium(diskpath, library.DeviceType.hard_disk, library.AccessMode.read_write, True)
        machine.attach_device("SATA", index, 0, library.DeviceType.hard_disk, disk)
        machine.save_settings()
        session.unlock_machine()
        return {'result': 'success'}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号