当前位置: 首页>>代码示例>>Python>>正文


Python KaresansuiVirtConnection.get_storage_pool_targetpath方法代码示例

本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.get_storage_pool_targetpath方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.get_storage_pool_targetpath方法的具体用法?Python KaresansuiVirtConnection.get_storage_pool_targetpath怎么用?Python KaresansuiVirtConnection.get_storage_pool_targetpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karesansui.lib.virt.virt.KaresansuiVirtConnection的用法示例。


在下文中一共展示了KaresansuiVirtConnection.get_storage_pool_targetpath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        conn = KaresansuiVirtConnection(readonly=False)
        try:
            inactive_storage_pools = conn.list_inactive_storage_pool()
            active_storage_pools = conn.list_active_storage_pool()
            self.up_progress(10)

            if not (opts.pool_name in active_storage_pools or \
                   opts.pool_name in inactive_storage_pools):
                raise KssCommandException('Storage pool does not exist. - pool=%s'
                                          % opts.name)

            pool_dir = conn.get_storage_pool_targetpath(opts.pool_name)
            #image_path = os.path.realpath("%s/%s/images/%s.img" % (pool_dir, opts.name, opts.name))
            #vol = conn.get_storage_volume_symlink(image_path)
            #if not vol:
            #    raise KssCommandException("Storage volume could not be found.")
            #else:
            #    vol = vol[0]

            if conn.get_storage_volume(opts.pool_name, opts.name) is None:
                raise KssCommandException(
                    'Specified storage volume does not exist. - pool=%s, vol=%s'
                    % (opts.pool_name, opts.name))

            try:
                self.up_progress(30)
                if conn.delete_storage_volume(opts.pool_name,
                                              opts.name,
                                              opts.use,
                                              True) is False:
                    KssCommandException("Failed to destroy storage volume. (libvirt)- pool=%s, vol=%s" \
                                        % (opts.pool_name, opts.name))

                self.up_progress(30)
                self.logger.info('Deleted storage volume. - pool=%s, vol=%s' % (opts.pool_name, opts.name))
                print >>sys.stdout, _('Deleted storage volume. - pool=%s, vol=%s') % (opts.pool_name, opts.name)
                return True
            except KssCommandException, e:
                raise e
        finally:
            conn.close()
开发者ID:goura,项目名称:karesansui,代码行数:48,代码来源:delete_storage_volume.py

示例2: validates_pool_dir

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
def validates_pool_dir(obj, now_pools):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if is_param(obj.input, "pool_name"):
        check = (
            checker.check_string(_("Storage Pool Name"), obj.input.pool_name, CHECK_EMPTY | CHECK_ONLYSPACE, None)
            and check
        )
        if obj.input.pool_name in now_pools:
            check = False
            checker.add_error(_('%s "%s" already exists.') % (_("Storage Pool Name"), obj.input.pool_name))
    else:
        check = False
        checker.add_error(_('"%s" is required.') % _("Storage Pool Name"))

    if is_param(obj.input, "pool_target_path"):
        check = (
            checker.check_directory(
                _("Directory Path"), obj.input.pool_target_path, CHECK_EMPTY | CHECK_STARTROOT | CHECK_NOTROOT
            )
            and check
        )
        try:
            kvc = KaresansuiVirtConnection()

            for pool_name in now_pools:
                target_path = kvc.get_storage_pool_targetpath(pool_name)
                if obj.input.pool_target_path == target_path:
                    check = False
                    checker.add_error(
                        _('Storagepool target path "%s" is already being used.') % (obj.input.pool_target_path)
                    )
        finally:
            kvc.close()

    else:
        check = False
        checker.add_error(_('"%s" is required.') % _("Directory Path"))

    obj.view.alert = checker.errors
    return check
开发者ID:nabeken,项目名称:karesansui,代码行数:47,代码来源:hostby1storagepool.py

示例3: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)

        self.up_progress(10)
        conn = KaresansuiVirtConnection(readonly=False)
        try:
            try:
                self.up_progress(10)
                progresscb = None
                if opts.debug is True:
                    try:
                        from karesansui.lib.progress import ProgressMeter
                        progresscb = ProgressMeter(command_object=self)
                    except:
                        pass
                else:
                    try:
                        from karesansui.lib.progress import ProgressMeter
                        progresscb = ProgressMeter(command_object=self,quiet=True)
                    except:
                        pass

                vol_obj = conn.get_storage_volume(opts.orig_pool, opts.orig_volume)
                if vol_obj is None:
                    raise KssCommandException(
                        'Specified storage volume does not exist. - pool=%s, vol=%s'
                        % (opts.orig_pool, opts.orig_volume))

                inactive_storage_pools = conn.list_inactive_storage_pool()
                active_storage_pools = conn.list_active_storage_pool()
                if not (opts.dest_pool in active_storage_pools or \
                            opts.dest_pool in inactive_storage_pools):
                    raise KssCommandException('Destination storage pool does not exist. - pool=%s'
                                              % (opts.dest_pool))

                vol_info = vol_obj.info()
                if vol_info[0] != 0:
                    raise KssCommandException(
                        'Specified storage volume does not "file" type. - pool=%s, vol=%s'
                        % (opts.orig_pool, opts.orig_volume))

                filesize = vol_info[1] / (1024 * 1024) # a unit 'MB'
                target_path = conn.get_storage_pool_targetpath(opts.dest_pool)
                if chk_create_disk(target_path, filesize) is False:
                    raise KssCommandException(
                        'Destination storage pool shortage capacity. - pool=%s'
                        % (opts.dest_pool))

                if conn.replicate_storage_volume(opts.orig_name,
                                                 opts.orig_pool,
                                                 opts.orig_volume,
                                                 opts.dest_name,
                                                 opts.dest_pool,
                                                 opts.dest_volume,
                                                 progresscb) is False:

                    raise KssCommandException(_("Failed to copy storage volume."))
                self.up_progress(40)
                self.logger.info('Replicate storage volume. - orig_pool=%s, orig_vol=%s, dest_pool=%s' % (opts.orig_pool, opts.orig_volume, opts.dest_pool))
                print >>sys.stdout, _('Replicate storage volume. - orig_pool=%s, orig_vol=%s, dest_pool=%s' % (opts.orig_pool, opts.orig_volume, opts.dest_pool))
                return True
            except Exception, e:
                raise e
        finally:
            conn.close()
开发者ID:fkei,项目名称:karesansui,代码行数:68,代码来源:replicate_storage_volume.py

示例4: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        conn = KaresansuiVirtConnection(readonly=False)
        try:
            uuid = conn.domname_to_uuid(opts.name)
            try: # physical
                conn.set_domain_name(opts.name)
                conn.delete_guest(opts.name, opts.pool, opts.volume)
                self.up_progress(20)
            except Exception, e:
                print >>sys.stderr, '[Warn] Failed to delete the guest OS physical. - dom=%s - detail : %s' \
                      % (opts.name, str(e.args))
                self.logger.warn('Failed to delete the guest OS physical. - dom=%s - detail : %s' \
                                 % (opts.name, str(e.args)))

            # Check the presence of residual files
            try:
                self.up_progress(10)
                # /etc
                config = ""
                hypervisor = conn.get_hypervisor_type()
                if hypervisor == "XEN":
                    config = "%s/%s" % (XEN_VIRT_CONFIG_DIR, opts.name,)
                elif hypervisor == "KVM" or hypervisor == "QEMU":
                    config = "%s/%s" % (KVM_VIRT_CONFIG_DIR, opts.name,)
                if os.path.isfile(config) is True:
                    os.remove(config)
                    self.logger.info("physical config remove. - path=%s" % config)

                self.up_progress(5)

                xml_config = '%s/%s.xml' % (VIRT_XML_CONFIG_DIR, opts.name)
                if os.path.isfile(xml_config) is True:
                    os.remove(xml_config)
                    self.logger.info("physical xml config remove. - path=%s" % xml_config)

                self.up_progress(5)

                self.logger.info('To remove the storage volume even more.')

                tmp_pool = conn.get_storage_pool_name_bydomain(opts.name, 'os')
                if tmp_pool:
                    domains_dir = conn.get_storage_pool_targetpath(tmp_pool[0])
                else:
                    domains_dir = conn.get_storage_pool_targetpath(opts.pool)

                disk_image = '%s/%s/images/%s.img' % (domains_dir, opts.name, opts.name,)
                if os.path.isfile(disk_image) is True or os.path.islink(disk_image) is True:
                    os.remove(disk_image)
                    self.logger.info("physical disk image remove. - path=%s" % disk_image)

                self.up_progress(5)
                if 0 < len(opts.name.split()): # double check
                    snapshot_dir = '%s/%s/snapshot' % (domains_dir, opts.name,)
                    if os.path.isdir(snapshot_dir) is True:

                        for root, dirs, files in os.walk(snapshot_dir):
                            for fname in files:
                                file_path = os.path.join(root, fname)
                                os.remove(file_path)
                                self.logger.info("physical snapshots file remove. - file=%s" % file_path)

                        os.removedirs(snapshot_dir)
                        self.logger.info("physical snapshots directory remove. - dir=%s" % snapshot_dir)

                self.up_progress(5)
                if 0 < len(opts.name.split()): # double check
                    disk_dir = '%s/%s/disk' % (domains_dir, opts.name,)
                    if os.path.isdir(disk_dir) is True:

                        for root, dirs, files in os.walk(disk_dir):
                            for fname in files:
                                file_path = os.path.join(root, fname)
                                os.remove(file_path)
                                self.logger.info("physical disk file remove. - file=%s" % file_path)

                        os.removedirs(disk_dir)
                        self.logger.info("physical disk directory remove. - dir=%s" % disk_dir)
                self.up_progress(5)

                # Delete GuestOS directory
                domain_dir = "%s/%s" % (domains_dir, opts.name)
                if os.path.isdir(domain_dir) is True:
                    shutil.rmtree(domain_dir)

                self.up_progress(5)

            except Exception, e:
                print >>sys.stderr, '[Warn] Failed to remove the residual file.. - dom=%s - detail : %s' \
                      % (opts.name, str(e.args))
                self.logger.warn('Failed to remove the residual file.. - dom=%s - detail : %s' \
                                 % (opts.name, str(e.args)))
开发者ID:fkei,项目名称:karesansui,代码行数:97,代码来源:delete_guest.py

示例5: Guest

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]

#.........这里部分代码省略.........
    def _POST(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        model = findbyhost1(self.orm, host_id)

        uris = available_virt_uris()
        if model.attribute == 0 and model.hypervisor == 1:
            uri = uris["XEN"]
        elif model.attribute == 0 and model.hypervisor == 2:
            uri = uris["KVM"]
        else:
            uri = None

        if not validates_guest_add(self):
            return web.badrequest(self.view.alert)

        try:
            try:
                self.kvc = KaresansuiVirtConnection(uri)
                active_guests = self.kvc.list_active_guest()
                inactive_guests = self.kvc.list_inactive_guest()
                used_graphics_ports = self.kvc.list_used_graphics_port()
                used_mac_addrs = self.kvc.list_used_mac_addr()
                mem_info = self.kvc.get_mem_info()

                if is_param(self.input, "vm_mem_size"):
                    if mem_info['host_free_mem'] < int(self.input.vm_mem_size):
                        return web.badrequest(_("Space not enough to allocate guest memory."))

                if is_param(self.input, "pool_type") and \
                       self.input.pool_type != "block" and \
                       is_param(self.input, "pool_dir"):
                    target_path = self.kvc.get_storage_pool_targetpath(self.input.pool_dir)
                    if target_path: # disk
                        if not chk_create_disk(target_path, self.input.vm_disk_size):
                            partition = get_partition_info(target_path, header=False)
                            return web.badrequest(_("No space available to create disk image in '%s' partition.") % partition[5][0])
            except:
                raise
        finally:
            del self.kvc

        # Check on whether value has already been used
        # Guest OS
        if (self.input.domain_name in active_guests) \
               or (self.input.domain_name in inactive_guests):
            return web.conflict(web.ctx.path, "Guest OS is already there.")
        # Graphics Port Number
        if(int(self.input.vm_graphics_port) in used_graphics_ports):
            return web.conflict(web.ctx.path, "Graphics Port is already there.")
        # MAC Address
        if(self.input.vm_mac in used_mac_addrs):
            return web.conflict(web.ctx.path, "MAC Address is already there.")

        uuid = string_from_uuid(generate_uuid())

        options = {}
        options['uuid'] = uuid

        if is_param(self.input, "domain_name"):
            options['name'] = self.input.domain_name
        if is_param(self.input, "vm_mem_size"):
            options['mem-size'] = self.input.vm_mem_size
        if is_param(self.input, "vm_kernel"):
            options['kernel'] = self.input.vm_kernel
开发者ID:fkei,项目名称:karesansui,代码行数:70,代码来源:guest.py

示例6: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        conn = KaresansuiVirtConnection(readonly=False)
        try:
            # dest storage pool
            dest_target_path = conn.get_storage_pool_targetpath(opts.pool)
            if not dest_target_path:
                raise KssCommandException(
                    "Could not get the target path of the storage pool. - path=%s" % dest_target_path)

            self.dest_disk = "%s/%s/images/%s.img" \
                             % (dest_target_path, opts.name,opts.name,)

            # source storage pool
            src_pool = conn.get_storage_pool_name_bydomain(opts.src_name, "os")
            if not src_pool:
                raise KssCommandException("Source storage pool is not found.")
            src_pool_type = conn.get_storage_pool_type(src_pool)
            if src_pool_type == 'dir':
                raise KssCommandException(
                    "Storage pool type 'dir' is not. - type=%s" % src_pool_type)

            src_target_path = conn.get_storage_pool_targetpath(src_pool[0])
            self.src_disk  = "%s/%s/images/%s.img" \
                             % (src_target_path, opts.src_name,opts.src_name,)

            if os.path.isfile(self.src_disk) is False:
                raise KssCommandException(
                    'source disk image is not found. - src=%s' % (self.src_disk))

            if os.path.isfile(self.dest_disk) is True:
                raise KssCommandException(
                    'destination disk image already exists. - dest=%s' % (self.dest_disk))

            self.up_progress(10)

            active_storage_pools = conn.list_active_storage_pool()
            self.up_progress(10)
            if not (opts.pool in active_storage_pools):
                raise KssCommandException('Storage pool does not exist. - pool=%s'
                                          % (opts.pool))

            try:
                active_guests = conn.list_active_guest()
                inactive_guests = conn.list_inactive_guest()
                # source guestos
                if not (opts.src_name in active_guests or opts.src_name in inactive_guests):
                    raise KssCommandException(
                        "Unable to get the source guest OS. - src_name=%s" % opts.src_name)

                if (opts.name in active_guests or opts.name in inactive_guests):
                    raise KssCommandException(
                        "Destination Guest OS is already there. - dest_name=%s" % opts.name)

                self.up_progress(10)

                conn.replicate_guest(opts.name,
                                     opts.src_name,
                                     opts.pool,
                                     opts.mac,
                                     opts.uuid,
                                     opts.vnc_port)
                self.up_progress(40)
            except:
                self.logger.error('Failed to replicate guest. - src=%s dom=%s' % (opts.src_name,opts.name))
                raise
        finally:
            conn.close()

        conn1 = KaresansuiVirtConnection(readonly=False)
        try:
            self.up_progress(10)
            active_guests = conn1.list_active_guest()
            inactive_guests = conn1.list_inactive_guest()
            if opts.name in active_guests or opts.name in inactive_guests:
                self.logger.info('Replicated guest. - src=%s dom=%s' % (opts.src_name,opts.name))
                print >>sys.stdout, _('Replicated guest. - src=%s dom=%s') % (opts.src_name,opts.name)
                return True
            else:
                raise KssCommandException(
                    'Replicate guest not found. - src=%s dom=%s' % (opts.src_name,opts.name))
        finally:
            conn1.close()

        return True
开发者ID:goura,项目名称:karesansui,代码行数:90,代码来源:replicate_guest.py

示例7: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)

        self.up_progress(10)
        conn = KaresansuiVirtConnection(readonly=False)
        try:
            conn.set_domain_name(opts.name)
            self.up_progress(10)

            active_storage_pools = conn.list_active_storage_pool()
            if opts.pool not in active_storage_pools:
                raise KssCommandException('Storage pool does not exist. - pool=%s' % opts.name)

            if not conn.get_storage_volume(opts.pool, opts.volume):
                raise KssCommandException('Storage volume does not exist. - pool=%s, volume=%s' % (opts.name, opts.volume))

            self.up_progress(10)
            if opts.type.lower() == 'iscsi':
                real_volume_path = conn.get_storage_volume_iscsi_rpath_bystorage(opts.pool, opts.volume)
                if not real_volume_path:
                    raise KssCommandException('Failure get iSCSI volume real path. - pool=%s, volume=%s' % (opts.name, opts.volume))

                format = None
                disk_type = 'block'

            elif opts.type.lower() == 'file':
                real_volume_path = "%s/%s/%s/%s.img" % \
                                   (conn.get_storage_pool_targetpath(opts.pool),
                                    opts.name,
                                    DISK_USES["DISK"],
                                    opts.volume)
                format = opts.format
                disk_type = 'file'
            else:
                raise KssCommandException('Unknown Storage Type. type=%s' % opts.type)

            if opts.target:
                target = opts.target
            else:
                target = conn.guest.next_disk_target(opts.bus)

            self.up_progress(10)
            already_disks = conn.guest.get_disk_info()
            for already_disk in already_disks:
                if already_disk['type'] == 'file':
                    already_path = already_disk['source']['file']
                elif already_disk['type'] == 'block':
                    already_path = already_disk['source']['dev']
                else:
                    already_path = ''

                if already_path == real_volume_path:
                    raise KssCommandException('Source disk is already used. path=%s' % real_volume_path)

            if opts.format is None:
                format = get_disk_img_info(real_volume_path)['file_format']

            conn.guest.append_disk(real_volume_path,
                                   target,
                                   bus=opts.bus,
                                   disk_type=disk_type,
                                   driver_name=None,
                                   driver_type=format,
                                   )

            self.up_progress(30)
        finally:
            conn.close()

        self.logger.info('Added disk device. - dom=%s target=%s path=%s' \
                         % (opts.name, target, real_volume_path))
        print >>sys.stdout, 'Added disk device. - dom=%s target=%s path=%s' \
              % (opts.name, target, real_volume_path)

        return True
开发者ID:fkei,项目名称:karesansui,代码行数:78,代码来源:add_disk.py

示例8: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        conn = KaresansuiVirtConnection(readonly=False)
        try:
            try:
                src_pool = conn.get_storage_pool_name_bydomain(opts.name, "os")
                if not src_pool:
                    raise KssCommandException("Source storage pool not found. domain=%s" % (opts.name))
                if conn.get_storage_pool_type(src_pool) == 'dir':
                    raise KssCommandException("Storage pool type 'dir' is not. domain=%s" % (opts.name))

                src_path = conn.get_storage_pool_targetpath(src_pool[0])
                self.domain_dir  = "%s/%s" % (src_path, opts.name,)

                if os.path.isdir(self.domain_dir) is False:
                    raise KssCommandException(
                        'domain directory is not found or not directory. - %s' % (self.domain_dir))

                # Model
                virt_uuid = conn.domname_to_uuid(opts.name)
                model = findby1uniquekey(self.kss_session, virt_uuid)
                if not model:
                    raise KssCommandException("Export data does not exist in the database.")

                database = {}
                database['attribute'] = model.attribute
                database['hypervisor'] = model.hypervisor
                database['icon'] = model.icon
                database['name'] = model.name
                database['notebook'] = {"title" : model.notebook.title,
                                        "value" : model.notebook.value,
                                        }
                tags = []
                for _tag in model.tags:
                    tags.append(_tag.name)

                database['tags'] = ",".join(tags)
                database['uniq_key'] = model.uniq_key

                # Snapshot
                snapshots = []
                kvs = KaresansuiVirtSnapshot(readonly=False)
                try:
                    guest_id = model.id
                    snapshot_list = kvs.listNames(opts.name)[opts.name]
                    if len(snapshot_list) > 0:
                        for snapshot in snapshot_list:
                            s_model = s_findbyname_guestby1(self.kss_session, snapshot, guest_id)
                            if s_model is not None:
                                name  = s_model.name
                                title = s_model.notebook.title
                                value = s_model.notebook.value
                                snapshots.append({"name":name, "title":title, "value":value,})
                except:
                    raise KssCommandException("Cannot fetch the information of snapshots correctly.")
                kvs.finish()

                # Pool
                target_dir = ""
                if opts.pool:
                    inactive_storage_pools = conn.list_inactive_storage_pool()
                    active_storage_pools = conn.list_active_storage_pool()
                    if not (opts.pool in active_storage_pools or opts.pool in inactive_storage_pools):
                        raise KssCommandException('Target storage pool does not exist. - pool=%s' % (opts.pool))

                    pool = conn.search_kvn_storage_pools(opts.pool)
                    storage_info = pool[0].get_info()
                    if storage_info["type"] == "dir" and storage_info["target"]["path"] != "":
                        target_dir = storage_info["target"]["path"]
                    else:
                        raise KssCommandException("Target storage pool type is not 'dir'. pool=%s" % (opts.pool))
                elif opts.dir:
                    target_dir = opts.dir

                self.up_progress(10)
                progresscb = None
                if opts.verbose:
                    try:
                        from karesansui.lib.progress import ProgressMeter
                        progresscb = ProgressMeter(command_object=self)
                    except:
                        pass
                else:
                    try:
                        from karesansui.lib.progress import ProgressMeter
                        progresscb = ProgressMeter(command_object=self,quiet=True)
                    except:
                        pass

                if opts.title[0:4] == "b64:":
                    title = base64_decode(opts.title[4:])
                else:
                    title = opts.title

                uuid = StrFromUUID(GenUUID())
                conn.export_guest(uuid=uuid,
                                  name=opts.name,
#.........这里部分代码省略.........
开发者ID:fkei,项目名称:karesansui,代码行数:103,代码来源:export_guest.py

示例9: _POST

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
    def _POST(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        if not validates_guest_export(self):
            return web.badrequest(self.view.alert)

        if not validates_sid(self):
            return web.badrequest(self.view.alert)

        model = findbyguest1(self.orm, self.input.sid)
        if not model:
            return web.badrequest()

        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.conflict(web.ctx.path)

            src_pools = kvc.get_storage_pool_name_bydomain(domname)
            if not src_pools:
                return web.badrequest(_("Source storage pool is not found."))

            for src_pool in  src_pools :
                src_pool_type = kvc.get_storage_pool_type(src_pool)
                if src_pool_type != 'dir':
                    return web.badrequest(_("'%s' disk contains the image.") % src_pool_type)

            virt = kvc.search_kvg_guests(domname)[0]
            options = {}
            options["name"] = virt.get_domain_name()
            if is_param(self.input, "pool"):
                # disk check
                src_pool = kvc.get_storage_pool_name_bydomain(domname, 'os')[0]
                src_path = kvc.get_storage_pool_targetpath(src_pool)
                src_disk = "%s/%s/images/%s.img" \
                           % (src_path, options["name"], options["name"])

                dest_path = kvc.get_storage_pool_targetpath(self.input.pool)
                s_size = os.path.getsize(src_disk) / (1024 * 1024) # a unit 'MB'

                if os.access(dest_path, os.F_OK):
                    if chk_create_disk(dest_path, s_size) is False:
                        partition = get_partition_info(dest_path, header=False)
                        return web.badrequest(
                            _("No space available to create disk image in '%s' partition.") \
                                % partition[5][0])

                #else: # Permission denied
                    #TODO:check disk space for root

                options["pool"] = self.input.pool

            if is_param(self.input, "export_title"):
                #options["title"] = self.input.export_title
                options["title"] = "b64:" + base64_encode(self.input.export_title)
            options["quiet"] = None

        finally:
            kvc.close()

        _cmd = dict2command(
            "%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_EXPORT_GUEST), options)

        # Job Register
        cmdname = ["Export Guest", "export guest"]
        _jobgroup = JobGroup(cmdname[0], karesansui.sheconf['env.uniqkey'])
        _jobgroup.jobs.append(Job('%s command' % cmdname[1], 0, _cmd))

        _machine2jobgroup = m2j_new(machine=model,
                                    jobgroup_id=-1,
                                    uniq_key=karesansui.sheconf['env.uniqkey'],
                                    created_user=self.me,
                                    modified_user=self.me,
                                    )

        # INSERT
        save_job_collaboration(self.orm,
                               self.pysilhouette.orm,
                               _machine2jobgroup,
                               _jobgroup,
                               )

        self.logger.debug("(%s) Job group id==%s" % (cmdname[0],_jobgroup.id))
        url = '%s/job/%s.part' % (web.ctx.home, _jobgroup.id)
        self.logger.debug('Returning Location: %s' % url)

        return web.accepted()
开发者ID:goura,项目名称:karesansui,代码行数:90,代码来源:guestexport.py

示例10: _POST

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_storage_pool_targetpath [as 别名]
    def _POST(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        if not validates_guest_replicate(self):
            self.logger.debug(self.view.alert)
            return web.badrequest(self.view.alert)

        uuid = string_from_uuid(generate_uuid())

        # TODO dest_pool valid
        if not validates_src_id(self):
            self.logger.debug(self.view.alert)
            return web.badrequest(self.view.alert)

        src_guest = findbyguest1(self.orm, self.input.src_id)
        if not src_guest:
            self.view.alert = "Failed to get the data of source domain."
            self.logger.debug(self.view.alert)
            return web.badrequest(self.view.alert)

        # Note
        note_title = None
        if is_param(self.input, "note_title"):
            note_title = self.input.note_title

        note_value = None
        if is_param(self.input, "note_value"):
            note_value = self.input.note_value

        _notebook = n_new(note_title, note_value)

        # Tag
        _tags = None
        if is_param(self.input, "tags"):
            _tags = []
            for x in comma_split(self.input.tags):
                _tags.append(t_new(x))

        # Icon
        icon_filename = None
        if is_param(self.input, "icon_filename", empty=True):
            icon_filename = self.input.icon_filename

        dest_guest = m_new(created_user=self.me,
                           modified_user=self.me,
                           uniq_key=uni_force(uuid),
                           name=self.input.m_name,
                           attribute=MACHINE_ATTRIBUTE['GUEST'],
                           hypervisor=src_guest.hypervisor,
                           notebook=_notebook,
                           tags=_tags,
                           icon=icon_filename,
                           is_deleted=False,
                           parent=src_guest.parent,
                           )


        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(src_guest.uniq_key)
            if not domname: return web.conflict(web.ctx.path)
            virt = kvc.search_kvg_guests(domname)[0]
            options = {}
            options["src-name"] = virt.get_domain_name()
            if is_param(self.input, "dest_pool"):
                options["pool"] = self.input.dest_pool
            if is_param(self.input, "domain_dest_name"):
                options["dest-name"] = self.input.domain_dest_name
            if is_param(self.input, "vm_vncport"):
                options["vnc-port"] = self.input.vm_vncport
            if is_param(self.input, "vm_mac"):
                options["mac"] = self.input.vm_mac

            options["uuid"] = uuid

            src_pools = kvc.get_storage_pool_name_bydomain(domname)
            if not src_pools:
                self.view.alert = _("Source storage pool is not found.")
                self.logger.debug(self.view.alert)
                return web.badrequest(self.view.alert)

            for src_pool in  src_pools :
                src_pool_type = kvc.get_storage_pool_type(src_pool)
                if src_pool_type != 'dir':
                    self.view.alert = _("'%s' disk contains the image.") % src_pool_type
                    self.logger.debug(self.view.alert)
                    return web.badrequest(self.view.alert)

            # disk check
            target_pool = kvc.get_storage_pool_name_bydomain(domname, 'os')[0]
            target_path = kvc.get_storage_pool_targetpath(target_pool)
            src_disk = "%s/%s/images/%s.img" % \
                                      (target_path, options["src-name"], options["src-name"])

            s_size = os.path.getsize(src_disk) / (1024 * 1024) # a unit 'MB'

            if os.access(target_path, os.F_OK):
                if chk_create_disk(target_path, s_size) is False:
                    partition = get_partition_info(target_path, header=False)
#.........这里部分代码省略.........
开发者ID:goura,项目名称:karesansui,代码行数:103,代码来源:guestreplicate.py


注:本文中的karesansui.lib.virt.virt.KaresansuiVirtConnection.get_storage_pool_targetpath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。