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


Python KaresansuiVirtConnection.search_kvn_storage_pools方法代码示例

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


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

示例1: _GET

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

        self.view.host_id = host_id

        # Pool
        try:
            kvc = KaresansuiVirtConnection()
            inactive_pool = kvc.list_inactive_storage_pool()
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            self.view.pools = pools
            pools_info = []
            for pool in pools:
                pool_obj = kvc.search_kvn_storage_pools(pool)[0]
                pools_info.append(pool_obj.get_info())
                if pool_obj.is_active() is True:
                    vols_obj = pool_obj.search_kvn_storage_volumes(kvc)

                    vols_info = []
                    for vol_obj in vols_obj:
                        vols_info.append(vol_obj.get_info())
        finally:
            kvc.close()

        self.view.pools_info = pools_info

        if self.is_mode_input() is True:
            # .input
            try:
                kvc = KaresansuiVirtConnection()

                already_iqn = []
                for pool in pools:
                    pool_iqn = kvc.get_storage_pool_sourcedevicepath(pool)
                    if pool_iqn:
                        already_iqn.append(pool_iqn)
            finally:
                kvc.close()

            network_storages = get_iscsi_cmd(self, host_id)
            if network_storages is False:
                self.logger.debug("Get iSCSI command failed. Return to timeout")
                return web.internalerror("Internal Server Error. (Timeout)")

            available_network_storages = []
            for i in range(len(network_storages)):
                if network_storages[i]["iqn"] not in already_iqn and network_storages[i]["activity"] == 1:
                    available_network_storages.append(network_storages[i])

            self.view.network_storages = available_network_storages
            self.view.pool_types = (STORAGE_POOL_TYPE["TYPE_DIR"], STORAGE_POOL_TYPE["TYPE_ISCSI"])

        return True
开发者ID:nabeken,项目名称:karesansui,代码行数:60,代码来源:hostby1storagepool.py

示例2: process

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

        conn = KaresansuiVirtConnection(readonly=False)
        try:
            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

            try:
                #inactive_pool = conn.list_inactive_storage_pool()
                inactive_pool = []
                active_pool = conn.list_active_storage_pool()
                pools = inactive_pool + active_pool
                if not pools:
                    raise KssCommandException("Storage pool does not exist, or has been stopped.")
                pools.sort()

                export = []
                for pool_name in pools:
                    pool = conn.search_kvn_storage_pools(pool_name)
                    path = pool[0].get_info()["target"]["path"]
                    if os.path.exists(path):
                        for _afile in glob.glob("%s/*/info.dat" % (path,)):
                            e_param = ExportConfigParam()
                            e_param.load_xml_config(_afile)

                            if e_param.get_uuid() != opts.exportuuid:
                                continue

                            export.append({"dir" : os.path.dirname(_afile),
                                           "uuid" : opts.exportuuid,
                                           })

                if len(export) != 1:
                    raise KssCommandException("There are differences in the export data and real data. - uuid=%s" % opts.exportuuid)
                else:
                    export = export[0]

                if os.path.isdir(export["dir"]) is False:
                    raise KssCommandException("There is no real data. - dir=%s" % export["dir"])

                conn.import_guest(export["dir"], uuid=opts.destuuid, progresscb=progresscb)

                self.up_progress(40)
                self.logger.info('Import guest completed. - export=%s, dest=%s' % (opts.exportuuid, opts.destuuid))
                print >>sys.stdout, _('Import guest completed. - export=%s, dest=%s' % (opts.exportuuid, opts.destuuid))
                return True

            except KaresansuiVirtException, e:
                raise KssCommandException('Failed to import guest. - [%s]' \
                                      % (''.join(str(e.args))))
        finally:
            conn.close()
开发者ID:AdUser,项目名称:karesansui,代码行数:68,代码来源:import_guest.py

示例3: process

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

        kvc = KaresansuiVirtConnection()
        # #1 libvirt process
        try:
            # inactive_pool = kvc.list_inactive_storage_pool()
            inactive_pool = []
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            export = []
            for pool_name in pools:
                pool = kvc.search_kvn_storage_pools(pool_name)
                path = pool[0].get_info()["target"]["path"]
                if os.path.exists(path):
                    for _afile in glob.glob("%s/*/info.dat" % (path,)):
                        e_param = ExportConfigParam()
                        e_param.load_xml_config(_afile)

                        if e_param.get_uuid() != opts.uuid:
                            continue

                        e_name = e_param.get_domain()
                        _dir = os.path.dirname(_afile)

                        param = ConfigParam(e_name)

                        path = "%s/%s.xml" % (_dir, e_name)
                        if os.path.isfile(path) is False:
                            raise KssCommandException("Export corrupt data.(file not found) - path=%s" % path)

                        param.load_xml_config(path)

                        if e_name != param.get_domain_name():
                            raise KssCommandException(
                                "Export corrupt data.(The name does not match) - info=%s, xml=%s"
                                % (e_name, param.get_name())
                            )

                        _dir = os.path.dirname(_afile)

                        export.append({"dir": _dir, "pool": pool_name, "uuid": e_param.get_uuid(), "name": e_name})

            if len(export) < 1:
                # refresh pool.
                conn = KaresansuiVirtConnection(readonly=False)
                try:
                    conn.refresh_pools()
                finally:
                    conn.close()
                raise KssCommandException("libvirt data did not exist. - uuid=%s" % opts.uuid)
            else:
                export = export[0]

        finally:
            kvc.close()

        self.up_progress(30)
        # #2 physical process
        if os.path.isdir(export["dir"]) is False:
            raise KssCommandException(
                _("Failed to delete export data. - %s") % (_("Export data directory not found. [%s]") % (export["dir"]))
            )

        uuid = os.path.basename(export["dir"])
        pool_dir = os.path.dirname(export["dir"])

        if not is_uuid(export["uuid"]):
            raise KssCommandException(
                _("Failed to delete export data. - %s")
                % (_("'%s' is not valid export data directory.") % (export["dir"]))
            )

        shutil.rmtree(export["dir"])

        for _afile in glob.glob("%s*img" % (export["dir"])):
            os.remove(_afile)

        self.up_progress(30)
        # refresh pool.
        conn = KaresansuiVirtConnection(readonly=False)
        try:
            try:
                conn.refresh_pools()
            finally:
                conn.close()
        except:
            pass

        self.logger.info("Deleted export data. - uuid=%s" % (opts.uuid))
        print >>sys.stdout, _("Deleted export data. - uuid=%s") % (opts.uuid)
        return True
开发者ID:fkei,项目名称:karesansui,代码行数:98,代码来源:delete_export_data.py

示例4: _GET

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

        # valid
        self.view.uuid = param[1]

        kvc = KaresansuiVirtConnection()
        try: # libvirt connection scope -->
            # Storage Pool
            #inactive_pool = kvc.list_inactive_storage_pool()
            inactive_pool = []
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            export = []
            for pool_name in pools:
                pool = kvc.search_kvn_storage_pools(pool_name)
                path = pool[0].get_info()["target"]["path"]
                if os.path.exists(path):
                    for _afile in glob.glob("%s/*/info.dat" % (path,)):
                        e_param = ExportConfigParam()
                        e_param.load_xml_config(_afile)

                        if e_param.get_uuid() != self.view.uuid:
                            continue

                        e_name = e_param.get_domain()
                        _dir = os.path.dirname(_afile)

                        param = ConfigParam(e_name)

                        path = "%s/%s.xml" % (_dir, e_name)
                        if os.path.isfile(path) is False:
                            self.logger.error('Export corrupt data.(file not found) - path=%s' % path)
                            return web.internalerror()

                        param.load_xml_config(path)

                        if e_name != param.get_domain_name():
                            self.logger.error('Export corrupt data.(The name does not match) - info=%s, xml=%s' \
                                              % (e_name, param.get_name()))
                            return web.internalerror()

                        _dir = os.path.dirname(_afile)

                        title = e_param.get_title()
                        if title != "":
                            title = re.sub("[\r\n]","",title)
                        if title == "":
                            title = _('untitled')

                        created = e_param.get_created()
                        if created != "":
                            created_str = time.strftime("%Y/%m/%d %H:%M:%S", \
                                                        time.localtime(float(created)))
                        else:
                            created_str = _("N/A")

                        export.append({"info" : {"dir" : _dir,
                                                 "pool" : pool_name,
                                                 "uuid" : e_param.get_uuid(),
                                                 "name" : e_name,
                                                 "created" : int(created),
                                                 "created_str" : created_str,
                                                 "title" : title,
                                                  },
                                       "xml" : {"on_reboot" : param.get_behavior('on_reboot'),
                                                "on_poweroff" : param.get_behavior('on_poweroff'),
                                                "on_crash" : param.get_behavior('on_crash'),
                                                "boot_dev" : param.get_boot_dev(),
                                                #"bootloader" : param.get_bootloader(),
                                                #"commandline" : param.get_commandline(),
                                                #"current_snapshot" : param.get_current_snapshot(),
                                                'disk' : param.get_disk(),
                                                "domain_name" : param.get_domain_name(),
                                                "domain_type" : param.get_domain_type(),
                                                "features_acpi" : param.get_features_acpi(),
                                                "features_apic" : param.get_features_apic(),
                                                "features_pae" : param.get_features_pae(),
                                                #"initrd" : param.get_initrd(),
                                                "interface" : param.get_interface(),
                                                #"kernel" : param.get_kernel(),
                                                "max_memory" : param.get_max_memory(),
                                                'max_vcpus' : param.get_max_vcpus(),
                                                "max_vcpus_limit" : param.get_max_vcpus_limit(),
                                                "memory" : param.get_memory(),
                                                "uuid" : param.get_uuid(),
                                                "vcpus" : param.get_vcpus(),
                                                "vcpus_limit" : param.get_vcpus_limit(),
                                                "vnc_autoport" : param.get_vnc_autoport(),
                                                "keymap" : param.get_vnc_keymap(),
                                                "vnc_listen" : param.get_vnc_listen(),
                                                "vnc_passwd" : param.get_vnc_passwd(),
                                                "vnc_port" : param.get_vnc_port(),
                                                },
                                       "pool" : pool[0].get_info(),
                                       })

#.........这里部分代码省略.........
开发者ID:goura,项目名称:karesansui,代码行数:103,代码来源:guestexportby1.py

示例5: _DELETE

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

        # valid
        self.view.uuid = param[1]

        kvc = KaresansuiVirtConnection()
        try:
            # Storage Pool
            #inactive_pool = kvc.list_inactive_storage_pool()
            inactive_pool = []
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            export = []
            for pool_name in pools:
                pool = kvc.search_kvn_storage_pools(pool_name)
                path = pool[0].get_info()["target"]["path"]
                if os.path.exists(path):
                    for _afile in glob.glob("%s/*/info.dat" % (path,)):
                        e_param = ExportConfigParam()
                        e_param.load_xml_config(_afile)

                        if e_param.get_uuid() != self.view.uuid:
                            continue

                        e_name = e_param.get_domain()
                        _dir = os.path.dirname(_afile)

                        param = ConfigParam(e_name)

                        path = "%s/%s.xml" % (_dir, e_name)
                        if os.path.isfile(path) is False:
                            self.logger.error('Export corrupt data.(file not found) - path=%s' % path)
                            return web.internalerror()

                        param.load_xml_config(path)

                        if e_name != param.get_domain_name():
                            self.logger.error('Export corrupt data.(The name does not match) - info=%s, xml=%s' \
                                              % (e_name, param.get_name()))
                            return web.internalerror()

                        _dir = os.path.dirname(_afile)

                        export.append({"dir" : _dir,
                                       "pool" : pool_name,
                                       "uuid" : e_param.get_uuid(),
                                       "name" : e_name,
                                       })

            if len(export) != 1:
                self.logger.info("Export does not exist. - uuid=%s" % self.view.uuid)
                return web.badrequest()
        finally:
            kvc.close()

        export = export[0]
        if os.path.exists(export['dir']) is False or os.path.isdir(export['dir']) is False:
            self.logger.error('Export data is not valid. [%s]' % export_dir)
            return web.badrequest('Export data is not valid.')

        host = findbyhost1(self.orm, host_id)

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

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

        # Job Registration
        _jobgroup = JobGroup('Delete Export Data', karesansui.sheconf['env.uniqkey'])

        _jobgroup.jobs.append(Job('Delete Export Data', 0, _cmd))

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

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

        self.logger.debug('(Delete export data) Job group id==%s', _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,代码行数:97,代码来源:guestexportby1.py

示例6: _POST

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_kvn_storage_pools [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)

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

        uuid = self.input.uuid
        kvc = KaresansuiVirtConnection()
        try:
            # Storage Pool
            #inactive_pool = kvc.list_inactive_storage_pool()
            inactive_pool = []
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            export = []
            for pool_name in pools:
                pool = kvc.search_kvn_storage_pools(pool_name)
                path = pool[0].get_info()["target"]["path"]
                if os.path.exists(path):
                    for _afile in glob.glob("%s/*/info.dat" % (path,)):
                        e_param = ExportConfigParam()
                        e_param.load_xml_config(_afile)

                        if e_param.get_uuid() != uuid:
                            continue

                        e_name = e_param.get_domain()
                        _dir = os.path.dirname(_afile)

                        param = ConfigParam(e_name)

                        path = "%s/%s.xml" % (_dir, e_name)
                        if os.path.isfile(path) is False:
                            self.logger.error('Export corrupt data.(file not found) - path=%s' % path)
                            return web.internalerror()

                        param.load_xml_config(path)

                        if e_name != param.get_domain_name():
                            self.logger.error('Export corrupt data.(The name does not match) - info=%s, xml=%s' \
                                              % (e_name, param.get_name()))
                            return web.internalerror()

                        _dir = os.path.dirname(_afile)

                        title = e_param.get_title()
                        if title != "":
                            title = re.sub("[\r\n]","",title)
                        if title == "":
                            title = _('untitled')

                        created = e_param.get_created()
                        if created != "":
                            created_str = time.strftime("%Y/%m/%d %H:%M:%S", \
                                                        time.localtime(float(created)))
                        else:
                            created_str = _("N/A")

                        export.append({"info" : {"dir" : _dir,
                                                 "pool" : pool_name,
                                                 "uuid" : e_param.get_uuid(),
                                                 "name" : e_param.get_domain(),
                                                 "created" : int(created),
                                                 "created_str" : created_str,
                                                 "title" : title,
                                                 "database" : {"name" : e_param.database["name"],
                                                               "tags" : e_param.database["tags"],
                                                               "attribute" : e_param.database["attribute"],
                                                               "notebook" : {"title" : e_param.database["notebook"]["title"],
                                                                             "value" : e_param.database["notebook"]["value"],
                                                                             },
                                                               "uniq_key" : e_param.database["uniq_key"],
                                                               "hypervisor" : e_param.database["hypervisor"],
                                                               "icon" : e_param.database["icon"],
                                                               },
                                                  },
                                       "xml" : {"on_reboot" : param.get_behavior('on_reboot'),
                                                "on_poweroff" : param.get_behavior('on_poweroff'),
                                                "on_crash" : param.get_behavior('on_crash'),
                                                "boot_dev" : param.get_boot_dev(),
                                                #"bootloader" : param.get_bootloader(),
                                                #"commandline" : param.get_commandline(),
                                                #"current_snapshot" : param.get_current_snapshot(),
                                                'disk' : param.get_disk(),
                                                "domain_name" : param.get_domain_name(),
                                                "domain_type" : param.get_domain_type(),
                                                "features_acpi" : param.get_features_acpi(),
                                                "features_apic" : param.get_features_apic(),
                                                "features_pae" : param.get_features_pae(),
                                                #"initrd" : param.get_initrd(),
                                                "interface" : param.get_interface(),
                                                #"kernel" : param.get_kernel(),
                                                "max_memory" : param.get_max_memory(),
                                                'max_vcpus' : param.get_max_vcpus(),
                                                "max_vcpus_limit" : param.get_max_vcpus_limit(),
#.........这里部分代码省略.........
开发者ID:goura,项目名称:karesansui,代码行数:103,代码来源:guestimport.py

示例7: _DELETE

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

        host = findbyhost1(self.orm, host_id)

        if is_param(self.input, "iqn"):
            iqn = self.input.iqn
        else:
            self.logger.debug("Network storage delete failed. Target IQN not found.")
            return web.badrequest()

        options = {'iqn' : iqn}
        job_order = 0
        cmd_name = u'Delete iSCSI'
        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])

        if is_param(self.input, "host") and is_param(self.input, "port"):
            host = self.input.host
            port = self.input.port
            used_pool = []
            active_used_pool = []

            kvc = KaresansuiVirtConnection()
            try:
                dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
                dev_symlink_list.sort()
                symlink_regexp = re.compile("^%s/%s" % (re.escape(ISCSI_DEVICE_DIR), re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))

                pools = kvc.list_active_storage_pool() + kvc.list_inactive_storage_pool()
                for pool in pools:
                    pool_type = kvc.get_storage_pool_type(pool)
                    if pool_type == "iscsi":
                        if iqn == kvc.get_storage_pool_sourcedevicepath(pool):
                            used_pool.append(pool)
                            pool_objs = kvc.search_kvn_storage_pools(pool)
                            if pool_objs[0].is_active():
                                active_used_pool.append(pool)

                    elif pool_type == "fs":
                        if symlink_regexp.match(kvc.get_storage_pool_sourcedevicepath(pool)):
                            used_pool.append(pool)
                            pool_objs = kvc.search_kvn_storage_pools(pool)
                            if pool_objs[0].is_active():
                                active_used_pool.append(pool)

            finally:
                kvc.close()

            for pool in active_used_pool:
                stop_pool_cmd = dict2command(
                    "%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_DESTROY_STORAGE_POOL),
                    {"name" : pool})
                stop_pool_cmdname = "Stop Storage Pool"
                jobgroup.jobs.append(Job('%s command' % stop_pool_cmdname, 0, stop_pool_cmd))
                job_order = 1

            for pool in used_pool:
                delete_pool_cmd = dict2command(
                    "%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_DELETE_STORAGE_POOL),
                    {"name" : pool})
                delete_pool_cmdname = "Delete Storage Pool"
                jobgroup.jobs.append(Job('%s command' % delete_pool_cmdname, job_order, delete_pool_cmd))
                job_order = 2

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

        jobgroup.jobs.append(Job('%s command' % cmd_name, job_order, _cmd))

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

        save_job_collaboration(self.orm,
                               self.pysilhouette.orm,
                               _machine2jobgroup,
                               jobgroup,
                               )

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

示例8: Guest

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_kvn_storage_pools [as 别名]
class Guest(Rest):

    def _post(self, f):
        ret = Rest._post(self, f)
        if hasattr(self, "kvc") is True:
            self.kvc.close()
        return ret

    @auth
    def _GET(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()

        self.kvc = KaresansuiVirtConnection()
        try: # libvirt connection scope -->
            # Storage Pool
            #inactive_pool = self.kvc.list_inactive_storage_pool()
            inactive_pool = []
            active_pool = self.kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            if not pools:
                return web.badrequest('One can not start a storage pool.')

            # Output .input
            if self.is_mode_input() is True:
                self.view.pools = pools
                pools_info = {}
                pools_vols_info = {}
                pools_iscsi_blocks = {}
                already_vols = []
                guests = []

                guests += self.kvc.list_inactive_guest()
                guests += self.kvc.list_active_guest()
                for guest in guests:
                    already_vol = self.kvc.get_storage_volume_bydomain(domain=guest,
                                                                       image_type=None,
                                                                       attr='path')
                    if already_vol:
                        already_vols += already_vol.keys()

                for pool in pools:
                    pool_obj = self.kvc.search_kvn_storage_pools(pool)[0]
                    if pool_obj.is_active() is True:
                        pools_info[pool] = pool_obj.get_info()

                        blocks = None
                        if pools_info[pool]['type'] == 'iscsi':
                            blocks = self.kvc.get_storage_volume_iscsi_block_bypool(pool)
                            if blocks:
                                pools_iscsi_blocks[pool] = []
                        vols_obj = pool_obj.search_kvn_storage_volumes(self.kvc)
                        vols_info = {}

                        for vol_obj in vols_obj:
                            vol_name = vol_obj.get_storage_volume_name()
                            vols_info[vol_name] = vol_obj.get_info()
                            if blocks:
                                if vol_name in blocks and vol_name not in already_vols:
                                    pools_iscsi_blocks[pool].append(vol_obj.get_info())

                        pools_vols_info[pool] = vols_info

                self.view.pools_info = pools_info
                self.view.pools_vols_info = pools_vols_info
                self.view.pools_iscsi_blocks = pools_iscsi_blocks

                bridge_prefix = {
                    "XEN":"xenbr",
                    "KVM":KVM_BRIDGE_PREFIX,
                    }
                self.view.host_id = host_id
                self.view.DEFAULT_KEYMAP = DEFAULT_KEYMAP
                self.view.DISK_NON_QEMU_FORMAT = DISK_NON_QEMU_FORMAT
                self.view.DISK_QEMU_FORMAT = DISK_QEMU_FORMAT

                self.view.hypervisors = {}
                self.view.mac_address = {}
                self.view.keymaps = {}
                self.view.phydev = {}
                self.view.virnet = {}

                used_ports = {}

                for k,v in MACHINE_HYPERVISOR.iteritems():
                    if k in available_virt_mechs():
                        self.view.hypervisors[k] = v
                        uri = uris[k]
                        mem_info = self.kvc.get_mem_info()
                        active_networks = self.kvc.list_active_network()
                        used_graphics_ports = self.kvc.list_used_graphics_port()
                        bus_types = self.kvc.bus_types
                        self.view.bus_types = bus_types
                        self.view.max_mem = mem_info['host_max_mem']
                        self.view.free_mem = mem_info['host_free_mem']
#.........这里部分代码省略.........
开发者ID:fkei,项目名称:karesansui,代码行数:103,代码来源:guest.py

示例9: process

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

        self.up_progress(10)
        conn = KaresansuiVirtConnection(readonly=False)

        try:
            try:
                #inactive_storage_pools = conn.list_inactive_storage_pool()
                inactive_storage_pools = []
                active_storage_pools = conn.list_active_storage_pool()
                if not (opts.pool_name in active_storage_pools or \
                        opts.pool_name in inactive_storage_pools):
                    raise KssCommandException('Storage pool does not exist. Alternatively, the storage pool is not started. - pool=%s'
                                              % opts.pool_name)

                if conn.get_storage_volume(opts.pool_name, opts.volume_name) is not None:
                    raise KssCommandException(
                        'We already have a storage volume. - pool=%s, vol=%s'
                        % (opts.pool_name, opts.volume_name))

                pool_obj = conn.search_kvn_storage_pools(opts.pool_name)[0]
                pool_info = pool_obj.get_info()
                if not pool_info['allocation'] or pool_info['allocation'] == 0:
                    storage_volume_allocation_max_size = STORAGE_VOLUME_SIZE_MAX_LENGTH
                else:
                    storage_volume_allocation_max_size = long(pool_info['allocation']) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)
                    if pool_info['type'] == 'dir' or pool_info['type'] == 'fs':
                        storage_volume_allocation_max_size = long(pool_info["available"]) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)
                if not pool_info['capacity'] or pool_info['capacity'] == 0:
                    storage_volume_capacity_max_size = STORAGE_VOLUME_SIZE_MAX_LENGTH
                else:
                    storage_volume_capacity_max_size = long(pool_info['capacity']) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)

                if opts.allocation < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_allocation_max_size < opts.allocation:
                    raise KssCommandException('Allocation "%s%s" is out of available range. available=%s-%s%s'
                                              % (opts.allocation, opts.unit, STORAGE_VOLUME_SIZE_MIN_LENGTH, storage_volume_allocation_max_size, opts.unit))
                if opts.capacity < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_capacity_max_size < opts.capacity:
                    raise KssCommandException('Capacity "%s%s" is out of available range. available=%s-%s%s'
                                              % (opts.capacity, opts.unit, STORAGE_VOLUME_SIZE_MIN_LENGTH, storage_volume_capacity_max_size, opts.unit))

                if conn.create_storage_volume(opts.name,
                                              opts.pool_name,
                                              opts.format,
                                              use=opts.use,
                                              volume_name=opts.volume_name,
                                              capacity=opts.capacity,
                                              allocation=opts.allocation,
                                              c_unit=opts.unit,
                                              t_p_owner=opts.permission_owner,
                                              t_p_group=opts.permission_group,
                                              t_p_mode=opts.permission_mode,
                                           ) is False:
                    raise KssCommandException('Failed to create storage volume. (libvirt) - pool=%s, vol=%s'
                                              % (opts.pool_name, opts.volume_name))

                self.up_progress(40)

                vol_path = conn.get_storage_volume_path(opts.pool_name, opts.volume_name)
                if vol_path is None:
                    raise KssCommandException(
                        'Could not get the normal storage pool or storage volume. - pool=%s, vol=%s' \
                        % (opts.pool, opts.volume_name))

                if os.path.isfile(vol_path) is False:
                    raise KssCommandException(
                        'File does not exist in the path of a storage volume. - pool=%s, vol=%s' \
                        % (opts.pool, opts.volume_name))

                vol_obj = conn.get_storage_volume(opts.pool_name, opts.volume_name)
                if vol_obj is None:
                    raise KssCommandException(
                        'Could not get the normal storage pool or storage volume. - pool=%s, vol=%s' \
                        % (opts.pool, opts.volume_name))

                vol_link = "%s/%s" % (pool_info['target']['path'], vol_obj.name())
                if os.path.islink(vol_link) is False:
                    raise KssCommandException(
                        'Symbolic link does not exist in the path of a storage volume. - pool=%s, vol=%s' \
                        % (opts.pool, opts.volume_name))

                self.logger.info('Created storage volume. - vol=%s' % (opts.volume_name))
                print >>sys.stdout, _('Created storage volume. - vol=%s') % (opts.volume_name)
                return True
            except KssCommandException, e:
                raise e
        finally:
            conn.close()
开发者ID:fkei,项目名称:karesansui,代码行数:91,代码来源:create_storage_volume.py

示例10: GuestBy1Device

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_kvn_storage_pools [as 别名]
class GuestBy1Device(Rest):

    @auth
    def _GET(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        bridge_prefix = {
                          "XEN":"xenbr",
                          "KVM":"br|bondbr",
                          #"KVM":"eth|bondbr",
                        }

        model = findbyguest1(self.orm, guest_id)

        # virt
        self.kvc = KaresansuiVirtConnection()
        try:
            domname = self.kvc.uuid_to_domname(model.uniq_key)
            if not domname:
                return web.notfound()
            virt = self.kvc.search_kvg_guests(domname)[0]
            guest = MergeGuest(model, virt)
            self.view.guest = guest

            # Output .input
            if self.is_mode_input() is True:
                try:
                    VMType = guest.info["virt"].get_info()["VMType"].upper()
                except:
                    VMType = "KVM"

                self.view.VMType = VMType

                # Network
                phydev = []
                phydev_regex = re.compile(r"%s" % bridge_prefix[VMType])

                for dev,dev_info in get_ifconfig_info().iteritems():
                    try:
                        if phydev_regex.match(dev):
                            phydev.append(dev)
                    except:
                        pass
                if len(phydev) == 0:
                    phydev.append("%s0" % bridge_prefix[VMType])

                phydev.sort()
                self.view.phydev = phydev # Physical device
                self.view.virnet = sorted(self.kvc.list_active_network()) # Virtual device
                self.view.mac_address = generate_mac_address() # new mac address

                # Disk
                inactive_pool = []
                active_pool = self.kvc.list_active_storage_pool()
                pools = inactive_pool + active_pool
                pools.sort()

                if not pools:
                    return web.badrequest('One can not start a storage pool.')

                pools_info = {}
                pools_vols_info = {}
                pools_iscsi_blocks = {}
                already_vols = []
                guests = []

                guests += self.kvc.list_inactive_guest()
                guests += self.kvc.list_active_guest()
                for guest in guests:
                    already_vol = self.kvc.get_storage_volume_bydomain(domain=guest,
                                                                       image_type=None,
                                                                       attr='path')
                    if already_vol:
                        already_vols += already_vol.keys()

                for pool in pools:
                    pool_obj = self.kvc.search_kvn_storage_pools(pool)[0]
                    if pool_obj.is_active() is True:
                        pools_info[pool] = pool_obj.get_info()

                        blocks = None
                        if pools_info[pool]['type'] == 'iscsi':
                            blocks = self.kvc.get_storage_volume_iscsi_block_bypool(pool)
                            if blocks:
                                pools_iscsi_blocks[pool] = []
                        vols_obj = pool_obj.search_kvn_storage_volumes(self.kvc)
                        vols_info = {}

                        for vol_obj in vols_obj:
                            vol_name = vol_obj.get_storage_volume_name()
                            vols_info[vol_name] = vol_obj.get_info()
                            if blocks:
                                if vol_name in blocks and vol_name not in already_vols:
                                    pools_iscsi_blocks[pool].append(vol_obj.get_info())

                        pools_vols_info[pool] = vols_info

                self.view.pools = pools
                self.view.pools_info = pools_info
#.........这里部分代码省略.........
开发者ID:AdUser,项目名称:karesansui,代码行数:103,代码来源:guestby1device.py

示例11: GuestBy1

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_kvn_storage_pools [as 别名]
class GuestBy1(Rest):

    def _post(self, f):
        ret = Rest._post(self, f)
        if hasattr(self, "kvc") is True:
            self.kvc.close()
        return ret

    @auth
    def _GET(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)

        if self.input.has_key('job_id') is True:
            self.view.job_id = self.input.job_id
        else:
            self.view.job_id = None

        if guest_id is None:
            return web.notfound()

        model = findbyguest1(self.orm, guest_id)

        self.kvc = KaresansuiVirtConnection()
        if self.is_mode_input() is True:
            try:
                domname = self.kvc.uuid_to_domname(model.uniq_key)
                if not domname:
                    return web.notfound()

                virt = self.kvc.search_kvg_guests(domname)[0]
                guest = MergeGuest(model, virt)
                self.view.model = guest.info["model"]
                return True
            except:
                self.kvc.close()
                raise
        else:
            try:
                domname = self.kvc.uuid_to_domname(model.uniq_key)
                if not domname:
                    return web.notfound()

                virt = self.kvc.search_kvg_guests(domname)[0]

                guest = MergeGuest(model, virt)

                guest_info = guest.info["virt"].get_info()
                info = {}
                info['memory'] = guest_info["memory"]
                info['cpu'] = guest_info["cpuTime"]
                info['os'] = guest_info["OSType"]
                info['hypervisor'] = guest_info["hypervisor"]
                info['type'] = guest_info["VMType"]
                info['hv_version'] = guest_info["hv_version"]

                disk_info = guest.info["virt"].get_disk_info()
                interface_info = guest.info["virt"].get_interface_info()
                net_info = guest.info["virt"].get_netinfo()
                graphics_info = guest.info["virt"].get_graphics_info()
                vcpu_info = guest.info["virt"].get_vcpus_info()

                pool_info = []
                pool_vols_info = []
                already_vols = []
                pools = self.kvc.get_storage_pool_name_bydomain(domname)
                if len(pools) > 0:
                    for pool in pools:
                        pool_obj = self.kvc.search_kvn_storage_pools(pool)[0]
                        if pool_obj.is_active() is True:
                            pool_info = pool_obj.get_info()

                            vols_obj = pool_obj.search_kvn_storage_volumes(self.kvc)
                            vols_info = {}

                            for vol_obj in vols_obj:
                                vol_name = vol_obj.get_storage_volume_name()
                                vols_info[vol_name] = vol_obj.get_info()

                            pool_vols_info = vols_info

                if self.__template__["media"] == 'json':
                    json_guest = guest.get_json(self.me.languages)
                    self.view.data = json_dumps(
                        {
                            "model": json_guest["model"],
                            "virt": json_guest["virt"],
                            "autostart": guest.info["virt"].autostart(),
                            "info": info,
                            "disk_info": disk_info,
                            "net_info": net_info,
                            "interface_info": interface_info,
                            "pool_info": pool_info,
                            "pool_vols_info": pool_vols_info,
                            "graphics_info": graphics_info,
                            "vcpu_info": vcpu_info,
                        }
                    )
                else:
                    self.view.model = guest.info["model"]
                    self.view.virt = guest.info["virt"]
#.........这里部分代码省略.........
开发者ID:AdUser,项目名称:karesansui,代码行数:103,代码来源:guestby1.py

示例12: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_kvn_storage_pools [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

示例13: _GET

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

        kvc = KaresansuiVirtConnection()
        try:
            # Storage Pool
            #inactive_pool = kvc.list_inactive_storage_pool()
            inactive_pool = []
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            if self.is_mode_input() is True: # (*.input)
                if not validates_sid(self):
                    return web.badrequest(self.view.alert)

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

                domname = kvc.uuid_to_domname(model.uniq_key)

                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]

                if virt.is_active() is True:
                    return web.badrequest(_("Guest is running. Please stop and try again. name=%s" % domname))

                self.view.domname = virt.get_domain_name()

                non_iscsi_pool = []
                for pool in pools:
                    if kvc.get_storage_pool_type(pool) != 'iscsi':
                        non_iscsi_pool.append(pool)
                self.view.pools = non_iscsi_pool
                self.view.sid = sid
                return True

            # Exported Guest Info (*.json)
            exports = {}
            for pool_name in pools:
                files = []
                pool = kvc.search_kvn_storage_pools(pool_name)
                path = pool[0].get_info()["target"]["path"]

                if os.path.exists(path):
                    for _afile in glob.glob("%s/*/info.dat" % (path,)):
                        param = ExportConfigParam()
                        param.load_xml_config(_afile)

                        _dir = os.path.dirname(_afile)

                        uuid = param.get_uuid()
                        name = param.get_domain()
                        created = param.get_created()
                        title = param.get_title()
                        if title != "":
                            title = re.sub("[\r\n]","",title)
                        if title == "":
                            title = _('untitled')

                        if created != "":
                            created_str = time.strftime("%Y/%m/%d %H:%M:%S", \
                                                        time.localtime(float(created)))
                        else:
                            created_str = _("N/A")

                        files.append({"dir": _dir,
                                      "pool" : pool_name,
                                      #"b64dir" : base64_encode(_dir),
                                      "uuid" : uuid,
                                      "name" : name,
                                      "created" : int(created),
                                      "created_str" : created_str,
                                      "title" : title,
                                      })

                exports[pool_name] = files

                # .json
                if self.is_json() is True:
                    self.view.exports = json_dumps(exports)
                else:
                    self.view.exports = exports

            return True

        finally:
            kvc.close()
开发者ID:goura,项目名称:karesansui,代码行数:101,代码来源:guestexport.py


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