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


Python KaresansuiVirtConnection.refresh_pools方法代码示例

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


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

示例1: process

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


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