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


Python KaresansuiVirtConnection.list_active_storage_pool方法代码示例

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


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

示例1: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_storage_pool [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.name in active_storage_pools or \
                   opts.name in inactive_storage_pools):
                raise KssCommandException('Storage pool does not exist. - pool=%s'
                                          % (opts.name))
            try:
                self.up_progress(30)
                if opts.force is True and opts.name in conn.list_active_storage_pool():
                    if conn.destroy_storage_pool(opts.name) is False:
                        raise KssCommandException("Failed to stop the storage pool. - pool=%s" \
                                                  % (opts.name))

                if opts.name in conn.list_active_storage_pool():
                    raise KssCommandException(
                        "Could not delete storage pool: internal error storage pool is still active' pool=%s" \
                        % opts.name)

                if conn.delete_storage_pool(opts.name, False) is False:
                    raise KssCommandException("Failed to remove the storage pool. - pool=%s" \
                                              % (opts.name))
                self.up_progress(30)

                # pool check
                inactive_storage_pools = conn.list_inactive_storage_pool()
                active_storage_pools = conn.list_active_storage_pool()
                if opts.name in active_storage_pools or \
                       opts.name in inactive_storage_pools:
                    raise KssCommandException('Could not remove a storage pool. - pool=%s' \
                                              % (opts.name))

                # .xml
                path = "%s/%s.xml" % (VIRT_STORAGE_CONFIG_DIR, opts.name)
                if os.path.isfile(path) is True:
                    raise KssCommandException(
                        "Could not delete the configuration file. - pool=%s, path=%s" \
                        % (opts.name, path))

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

示例2: _GET

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

示例3: process

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

                self.up_progress(10)

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

                if opts.name in active_storage_pools:
                    raise KssCommandException('Storage pool is already running. - pool=%s' % opts.name)

                self.up_progress(10)
                if conn.start_storage_pool(opts.name) is False:
                    raise KssCommandException(
                        'Failed to start storage pool. (libvirt) - pool=%s' % (opts.name))

                self.up_progress(40)

                inactive_storage_pools = conn.list_inactive_storage_pool()
                active_storage_pools = conn.list_active_storage_pool()
                if not (opts.name in active_storage_pools):
                    raise KssCommandException(
                        'Could not start the storage pool. - pool=%s' % (opts.name))

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

示例4: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_storage_pool [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()
                active_storage_pools = conn.list_active_storage_pool()
                self.up_progress(10)
                if not (opts.name in active_storage_pools or \
                        opts.name in inactive_storage_pools):
                    raise KssCommandException('Storage pool does not exist. - pool=%s'
                                          % (opts.name))
                self.up_progress(30)

                if opts.name in conn.list_active_storage_pool():
                    if conn.destroy_storage_pool(opts.name) is False:
                        KssCommandException("Failed to stop the storage pool. - pool=%s"
                                            % (opts.name))
                else:
                    raise KssCommandException('Storage pool is not active. - pool=%s'
                                          % (opts.name))

                self.up_progress(30)

                # check
                if not (opts.name in conn.list_inactive_storage_pool()):
                    KssCommandException("Failed to stop the storage pool. - pool=%s"
                                        % (opts.name))

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

示例5: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_storage_pool [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.name in active_storage_pools or \
                    opts.name in inactive_storage_pools):
                raise KssCommandOptException('Storage pool does not exist. - pool=%s'
                                          % opts.name)

            conn.storage_pool.set_storage_name(opts.name)

            self.up_progress(10)
            flag = None
            if opts.enable:
                flag = True
            elif opts.disable:
                flag = False
            else:
                raise KssCommandException(
                    'ERROR: Execution status information does not exist. enable,disable=%s,%s' \
                    % (str(opts.enable), str(opts.disable)))

            self.up_progress(10)
            if conn.autostart_storage_pool(flag) is False:
                raise KssCommandException(
                    'Failed to autostart storage pool(libvirt). - pool=%s'
                    % (opts.name))

            ret = conn.is_autostart_storage_pool()
            if not (ret is flag):
                raise KssCommandException(
                    'Auto-start failed to set the storage pool. - pool=%s, autostart=%s' \
                    % (opts.name, str(ret)))

            self.up_progress(40)
            if opts.enable:
                self.logger.info('Set autostart storage pool. - pool=%s' % (opts.name))
                print >>sys.stdout, _('Set autostart storage pool. - pool=%s') % (opts.name)
            elif opts.disable:
                self.logger.info('Unset autostart storage pool. - pool=%s' % (opts.name))
                print >>sys.stdout, _('Unset autostart storage pool. - pool=%s') % (opts.name)

            return True
        finally:
            conn.close()
开发者ID:AdUser,项目名称:karesansui,代码行数:53,代码来源:autostart_storage_pool.py

示例6: process

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

示例7: _PUT

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

        self.view.host_id = host_id
        uuid = param[1]

        if not validates_storage_pool(self, uuid):
            self.logger.debug("Set storage pool status failed. Did not validate.")
            return web.badrequest(self.view.alert)

        model = findbyhost1(self.orm, 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_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
            if len(pools_obj) <= 0:
                self.logger.debug("Set storage pool status failed. Target storage pool not found.")
                return web.notfound()

            status = int(self.input.status)
            if status == STORAGE_POOL_START:
                storagepool_start_stop_job(self, model, pools_obj[0], 'start')
            elif status == STORAGE_POOL_STOP:
                if kvc.is_used_storage_pool(name=pools_obj[0].get_storage_name(),
                                            active_only=True) is True:
                    self.logger.debug("Stop storage pool failed. Target storage pool is used by guest.")
                    return web.badrequest("Target storage pool is used by guest.")
                else:
                    storagepool_start_stop_job(self, model, pools_obj[0], 'stop')
            else:
                self.logger.debug("Set storage pool status failed. Unknown status type.")
                return web.badrequest()

            return web.accepted()
        finally:
            kvc.close()
开发者ID:goura,项目名称:karesansui,代码行数:47,代码来源:hostby1storagepoolby1status.py

示例8: _DELETE

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

        self.view.host_id = host_id
        uuid = param[1]

        if not validates_storage_pool(self, uuid):
            self.logger.debug("Delete storage pool failed. Did not validate.")
            return web.badrequest(self.view.alert)

        # 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_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
            if len(pools_obj) <= 0:
                return web.notfound()

            if kvc.is_used_storage_pool(pools_obj[0].get_storage_name()) is True:
                self.logger.debug("Delete storage pool failed. Target storage pool is used by guest.")
                return web.badrequest("Target storage pool is used by guest.")
        finally:
            kvc.close()

        model = findbyhost1(self.orm, host_id)

        if delete_storage_pool_job(self,model,pools_obj[0].get_storage_name()) is True:
            self.logger.debug("Delete storage pool success. name=%s" % (pools_obj[0].get_storage_name()))
            return web.accepted()
        else:
            self.logger.debug("Failed delete storage pool. name=%s" % (pools_obj[0].get_storage_name()))
            return False
开发者ID:goura,项目名称:karesansui,代码行数:41,代码来源:hostby1storagepoolby1.py

示例9: _GET

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

        if not validates_storage_pool(self, uuid):
            self.logger.debug("Get storage pool status failed. Did not validate.")
            return web.badrequest(self.view.alert)

        # 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_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
            if len(pools_obj) <= 0:
                self.logger.debug("Get storage pool status failed. Target storage pool not found.")
                return web.notfound()

            status = STORAGE_POOL_STOP
            if pools_obj[0].is_active() is True:
                status = STORAGE_POOL_START

            if self.__template__["media"] == 'json':
                self.view.status = json_dumps(status)
            else:
                self.view.status = status

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

示例10: _GET

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

        if not validates_storage_pool(self, uuid):
            self.logger.debug("Get storage pool info failed. Did not validate.")
            return web.badrequest(self.view.alert)

        try:
            kvc = KaresansuiVirtConnection()
            inactive_pool = kvc.list_inactive_storage_pool()
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            self.view.pools = pools
            pools_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
            if len(pools_obj) <= 0:
                self.logger.debug("Get storage pool info failed. Target storage pool not found.")
                return web.notfound()

            pool_obj = pools_obj[0]
            pool_info = pool_obj.get_info()
            vols_info = []
            if pool_obj.is_active() is True:
                vols_obj = pool_obj.search_kvn_storage_volumes(kvc)
                for vol_obj in vols_obj:
                    vols_info.append(vol_obj.get_info())

        finally:
            kvc.close()

        self.view.pool_info = pool_info
        self.view.vols_info = vols_info

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

示例11: _GET

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

示例12: _DELETE

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

示例13: _POST

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

        self.view.host_id = host_id

        model = findbyhost1(self.orm, host_id)

        # virt
        kvc = KaresansuiVirtConnection()
        try:
            inactive_pool = kvc.list_inactive_storage_pool()
            active_pool = kvc.list_active_storage_pool()
        finally:
            kvc.close()

        now_pools = inactive_pool + active_pool
        if self.input.pool_type == STORAGE_POOL_TYPE["TYPE_DIR"]:
            if not validates_pool_dir(self, now_pools):
                return web.badrequest(self.view.alert)

            extra_opts = {}
            if (
                create_pool_dir_job(
                    self, model, self.input.pool_name, self.input.pool_type, self.input.pool_target_path, extra_opts
                )
                is True
            ):
                self.logger.debug("Create dir storage pool success.")
                return web.accepted()
            else:
                self.logger.debug("Failed create DIR storage pool job.")
                return False
        elif self.input.pool_type == STORAGE_POOL_TYPE["TYPE_ISCSI"]:
            if not validates_pool_iscsi(self, now_pools):
                return web.badrequest(self.view.alert)
            extra_opts = {}
            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)")

            pool_host_name = None
            pool_device_path = None
            for iscsi in network_storages:
                if self.input.pool_target_iscsi == iscsi["iqn"]:
                    pool_host_name = iscsi["hostname"]
                    pool_device_path = iscsi["iqn"]
                    disk_list = iscsi["disk_list"]
                    break

            if pool_host_name is None or pool_device_path is None:
                self.logger.debug("Failed create iSCSI storage pool. Target iSCSI device not found.")
                return web.badrequest()

            automount_list = []
            for disk in disk_list:
                if is_param(self.input, "iscsi-disk-use-type-%s" % (disk["symlink_name"])):
                    if (
                        self.input["iscsi-disk-use-type-%s" % (disk["symlink_name"])] == "mount"
                        and disk["is_partitionable"] is False
                    ):
                        if is_param(self.input, "iscsi-disk-format-%s" % (disk["symlink_name"])):
                            if self.input["iscsi-disk-format-%s" % (disk["symlink_name"])] == "true":
                                disk["is_format"] = True
                        automount_list.append(disk)

            if (
                create_pool_iscsi_job(
                    self,
                    model,
                    self.input.pool_name,
                    self.input.pool_type,
                    pool_host_name,
                    pool_device_path,
                    automount_list,
                    extra_opts,
                )
                is True
            ):
                self.logger.debug("Create iSCSI storage pool success. name=%s" % (self.input.pool_name))
                return web.accepted()
            else:
                self.logger.debug("Failed create iSCSI storage pool job. name=%s" % (self.input.pool_name))
                return False
        else:
            self.logger.debug("Non-existent type. type=%s" % self.input.pool_type)
            return web.badrequest("Non-existent type. type=%s" % self.input.pool_type)
开发者ID:nabeken,项目名称:karesansui,代码行数:91,代码来源:hostby1storagepool.py

示例14: process

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

示例15: _PUT

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

        if not validates_network_storage(self):
            self.logger.debug("Network storage change status failed. Did not validate.")
            return web.badrequest(self.view.alert)

        host = findbyhost1(self.orm, host_id)

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

        options = {'iqn' : iqn}
        job_order = 0

        if is_param(self.input, "status"):
            status = self.input.status
        else:
            self.logger.debug("Network storage change status failed. Status type not found.")
            return web.badrequest()

        if is_param(self.input, "host") and is_param(self.input, "port"):
            host = self.input.host
            port = self.input.port
        else:
            self.logger.debug("Network storage change status failed. Target host and port not found.")
            return web.badrequest()

        active_used_pool = []
        inactive_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))))

            active_pools = kvc.list_active_storage_pool()
            inactive_pools = kvc.list_inactive_storage_pool()
            now_pools = active_pools + inactive_pools
            for pool in now_pools:
                pool_type = kvc.get_storage_pool_type(pool)
                if pool_type == "iscsi":
                    if iqn == kvc.get_storage_pool_sourcedevicepath(pool):
                        if pool in active_pools:
                            active_used_pool.append(pool)
                        if pool in inactive_pools:
                            inactive_used_pool.append(pool)
                elif pool_type == "fs":
                    if symlink_regexp.match(kvc.get_storage_pool_sourcedevicepath(pool)):
                        if pool in active_pools:
                            active_used_pool.append(pool)
                        if pool in inactive_pools:
                            inactive_used_pool.append(pool)

            if status == NETWORK_STORAGE_STOP:
                for pool in active_used_pool:
                    if kvc.is_used_storage_pool(name=pool, active_only=True) is True:
                        self.logger.debug("Stop iSCSI failed. Target iSCSI is used by guest.")
                        return web.badrequest("Target iSCSI is used by guest.")
        finally:
            kvc.close()

        if status == NETWORK_STORAGE_START:
            network_storage_cmd = ISCSI_COMMAND_START
            cmd_name = u'Start iSCSI'
            jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])

            for pool in inactive_used_pool:
                pool_cmd = dict2command(
                    "%s/%s" % (karesansui.config['application.bin.dir'], VIRT_COMMAND_START_STORAGE_POOL),
                    {"name" : pool})
                pool_cmdname = "Start Storage Pool"
                jobgroup.jobs.append(Job('%s command' % pool_cmdname, 1, pool_cmd))
                job_order = 0

        elif status == NETWORK_STORAGE_STOP:
            network_storage_cmd = ISCSI_COMMAND_STOP
            cmd_name = u'Stop iSCSI'
            jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])

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

        else:
            return web.internalerror('Internal Server Error. (Param)')

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

        jobgroup.jobs.append(Job('%s command' % cmd_name, job_order, _cmd))
#.........这里部分代码省略.........
开发者ID:goura,项目名称:karesansui,代码行数:103,代码来源:hostby1networkstorageby1status.py


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