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


Python StoragePoolModel.lookup方法代码示例

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


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

示例1: StorageServersModel

# 需要导入模块: from kimchi.model.storagepools import StoragePoolModel [as 别名]
# 或者: from kimchi.model.storagepools.StoragePoolModel import lookup [as 别名]
class StorageServersModel(object):
    def __init__(self, **kargs):
        self.conn = kargs['conn']
        self.pool = StoragePoolModel(**kargs)

    def get_list(self, _target_type=None):
        if not _target_type:
            target_type = STORAGE_SOURCES.keys()
        else:
            target_type = [_target_type]
        pools = self.pools.get_list()

        conn = self.conn.get()
        pools = conn.listStoragePools()
        pools += conn.listDefinedStoragePools()

        server_list = []
        for pool in pools:
            try:
                pool_info = self.pool.lookup(pool)
                if (pool_info['type'] in target_type and
                        pool_info['source']['addr'] not in server_list):
                    # Avoid to add same server for multiple times
                    # if it hosts more than one storage type
                    server_list.append(pool_info['source']['addr'])
            except NotFoundError:
                pass

        return server_list
开发者ID:mprostko,项目名称:kimchi,代码行数:31,代码来源:storageservers.py

示例2: StorageServerModel

# 需要导入模块: from kimchi.model.storagepools import StoragePoolModel [as 别名]
# 或者: from kimchi.model.storagepools.StoragePoolModel import lookup [as 别名]
class StorageServerModel(object):
    def __init__(self, **kargs):
        self.conn = kargs['conn']
        self.pool = StoragePoolModel(**kargs)

    def lookup(self, server):
        conn = self.conn.get()
        pools = conn.listStoragePools()
        pools += conn.listDefinedStoragePools()
        for pool in pools:
            try:
                pool_info = self.pool.lookup(pool)
                if (pool_info['type'] in STORAGE_SERVERS and
                        pool_info['source']['addr'] == server):
                    info = dict(host=server)
                    if (pool_info['type'] == "iscsi" and
                       'port' in pool_info['source']):
                        info["port"] = pool_info['source']['port']
                    return info
            except NotFoundError:
                # Avoid inconsistent pool result because of lease between list
                # lookup
                pass

        raise NotFoundError("KCHSR0001E", {'server': server})
开发者ID:EmperorBeezie,项目名称:kimchi,代码行数:27,代码来源:storageservers.py

示例3: _create_volume_with_url

# 需要导入模块: from kimchi.model.storagepools import StoragePoolModel [as 别名]
# 或者: from kimchi.model.storagepools.StoragePoolModel import lookup [as 别名]
    def _create_volume_with_url(self, cb, params):
        pool_name = params['pool']
        name = params['name']
        url = params['url']

        pool_model = StoragePoolModel(conn=self.conn,
                                      objstore=self.objstore)
        pool = pool_model.lookup(pool_name)
        file_path = os.path.join(pool['path'], name)

        with contextlib.closing(urllib2.urlopen(url)) as response:
            with open(file_path, 'w') as volume_file:
                remote_size = response.info().getheader('Content-Length', '-')
                downloaded_size = 0

                try:
                    while True:
                        chunk_data = response.read(READ_CHUNK_SIZE)
                        if not chunk_data:
                            break

                        volume_file.write(chunk_data)
                        downloaded_size += len(chunk_data)
                        cb('%s/%s' % (downloaded_size, remote_size))
                except Exception, e:
                    if os.path.isfile(file_path):
                        os.remove(file_path)
                    raise OperationFailed('KCHVOL0007E', {'name': name,
                                                          'pool': pool_name,
                                                          'err': e.message})
开发者ID:Gossing,项目名称:kimchi,代码行数:32,代码来源:storagevolumes.py

示例4: StorageServerModel

# 需要导入模块: from kimchi.model.storagepools import StoragePoolModel [as 别名]
# 或者: from kimchi.model.storagepools.StoragePoolModel import lookup [as 别名]
class StorageServerModel(object):
    def __init__(self, **kargs):
        self.conn = kargs["conn"]
        self.pool = StoragePoolModel(**kargs)

    def lookup(self, server):
        conn = self.conn.get()
        pools = conn.listStoragePools()
        pools += conn.listDefinedStoragePools()
        for pool in pools:
            try:
                pool_info = self.pool.lookup(pool)
                if pool_info["source"] and pool_info["source"]["addr"] == server:
                    return dict(host=server)
            except NotFoundError:
                # Avoid inconsistent pool result because of lease between list
                # lookup
                pass

        raise NotFoundError("KCHSR0001E", {"server": server})
开发者ID:jayzcode,项目名称:kimchi,代码行数:22,代码来源:storageservers.py

示例5: StorageServerModel

# 需要导入模块: from kimchi.model.storagepools import StoragePoolModel [as 别名]
# 或者: from kimchi.model.storagepools.StoragePoolModel import lookup [as 别名]
class StorageServerModel(object):
    def __init__(self, **kargs):
        self.conn = kargs['conn']
        self.pool = StoragePoolModel(**kargs)

    def lookup(self, server):
        conn = self.conn.get()
        pools = conn.listStoragePools()
        pools += conn.listDefinedStoragePools()
        for pool in pools:
            try:
                pool_info = self.pool.lookup(pool)
                if pool_info['source'] and \
                   pool_info['source']['addr'] == server:
                    return dict(host=server)
            except NotFoundError:
                # Avoid inconsistent pool result because of lease between list
                # lookup
                pass

        raise NotFoundError('server %s does not used by kimchi' % server)
开发者ID:mprostko,项目名称:kimchi,代码行数:23,代码来源:storageservers.py

示例6: StorageVolumeModel

# 需要导入模块: from kimchi.model.storagepools import StoragePoolModel [as 别名]
# 或者: from kimchi.model.storagepools.StoragePoolModel import lookup [as 别名]
class StorageVolumeModel(object):
    def __init__(self, **kargs):
        self.conn = kargs['conn']
        self.objstore = kargs['objstore']
        self.task = TaskModel(**kargs)
        self.storagevolumes = StorageVolumesModel(**kargs)
        self.storagepool = StoragePoolModel(**kargs)

    @staticmethod
    def get_storagevolume(poolname, name, conn):
        pool = StoragePoolModel.get_storagepool(poolname, conn)
        if not pool.isActive():
            raise InvalidOperation("KCHVOL0006E", {'name': pool})
        try:
            return pool.storageVolLookupByName(name.encode("utf-8"))
        except libvirt.libvirtError as e:
            if e.get_error_code() == libvirt.VIR_ERR_NO_STORAGE_VOL:
                raise NotFoundError("KCHVOL0002E", {'name': name,
                                                    'pool': poolname})
            else:
                raise

    def lookup(self, pool, name):
        vol = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
        path = vol.path()
        info = vol.info()
        xml = vol.XMLDesc(0)
        try:
            fmt = xpath_get_text(xml, "/volume/target/format/@type")[0]
        except IndexError:
            # Not all types of libvirt storage can provide volume format
            # infomation. When there is no format information, we assume
            # it's 'raw'.
            fmt = 'raw'

        iso_img = None

        # 'raw' volumes from 'logical' pools may actually be 'iso';
        # libvirt always reports them as 'raw'
        pool_info = self.storagepool.lookup(pool)
        if pool_info['type'] == 'logical' and fmt == 'raw':
            try:
                iso_img = IsoImage(path)
            except IsoFormatError:
                # not 'iso' afterall
                pass
            else:
                fmt = 'iso'

        used_by = get_disk_used_by(self.objstore, self.conn, path)
        res = dict(type=VOLUME_TYPE_MAP[info[0]],
                   capacity=info[1],
                   allocation=info[2],
                   path=path,
                   used_by=used_by,
                   format=fmt)
        if fmt == 'iso':
            if os.path.islink(path):
                path = os.path.join(os.path.dirname(path), os.readlink(path))
            os_distro = os_version = 'unknown'
            try:
                if iso_img is None:
                    iso_img = IsoImage(path)
                os_distro, os_version = iso_img.probe()
                bootable = True
            except IsoFormatError:
                bootable = False
            res.update(
                dict(os_distro=os_distro, os_version=os_version, path=path,
                     bootable=bootable))
        return res

    def wipe(self, pool, name):
        volume = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
        try:
            volume.wipePattern(libvirt.VIR_STORAGE_VOL_WIPE_ALG_ZERO, 0)
        except libvirt.libvirtError as e:
            raise OperationFailed("KCHVOL0009E",
                                  {'name': name, 'err': e.get_error_message()})

    def delete(self, pool, name):
        pool_info = StoragePoolModel(conn=self.conn,
                                     objstore=self.objstore).lookup(pool)
        if pool_info['type'] in READONLY_POOL_TYPE:
            raise InvalidParameter("KCHVOL0012E", {'type': pool_info['type']})

        volume = StorageVolumeModel.get_storagevolume(pool, name, self.conn)
        try:
            volume.delete(0)
        except libvirt.libvirtError as e:
            raise OperationFailed("KCHVOL0010E",
                                  {'name': name, 'err': e.get_error_message()})

    def resize(self, pool, name, size):
        volume = StorageVolumeModel.get_storagevolume(pool, name, self.conn)

        # When decreasing the storage volume capacity, the flag
        # VIR_STORAGE_VOL_RESIZE_SHRINK must be used
        flags = 0
        if volume.info()[1] > size:
#.........这里部分代码省略.........
开发者ID:melmorabity,项目名称:kimchi,代码行数:103,代码来源:storagevolumes.py

示例7: _create_volume_with_url

# 需要导入模块: from kimchi.model.storagepools import StoragePoolModel [as 别名]
# 或者: from kimchi.model.storagepools.StoragePoolModel import lookup [as 别名]
    def _create_volume_with_url(self, cb, params):
        pool_name = params['pool']
        name = params['name']
        url = params['url']

        pool_model = StoragePoolModel(conn=self.conn,
                                      objstore=self.objstore)
        pool = pool_model.lookup(pool_name)

        if pool['type'] in ['dir', 'netfs']:
            file_path = os.path.join(pool['path'], name)
        else:
            file_path = tempfile.mkstemp(prefix=name)[1]

        with contextlib.closing(urllib2.urlopen(url)) as response:
            with open(file_path, 'w') as volume_file:
                remote_size = response.info().getheader('Content-Length', '-')
                downloaded_size = 0

                try:
                    while True:
                        chunk_data = response.read(READ_CHUNK_SIZE)
                        if not chunk_data:
                            break

                        volume_file.write(chunk_data)
                        downloaded_size += len(chunk_data)
                        cb('%s/%s' % (downloaded_size, remote_size))
                except (IOError, libvirt.libvirtError) as e:
                    if os.path.isfile(file_path):
                        os.remove(file_path)

                    raise OperationFailed('KCHVOL0007E', {'name': name,
                                                          'pool': pool_name,
                                                          'err': e.message})

        if pool['type'] in ['dir', 'netfs']:
            virt_pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
            virt_pool.refresh(0)
        else:
            def _stream_handler(stream, nbytes, fd):
                return fd.read(nbytes)

            virt_stream = virt_vol = None

            try:
                task = self.create(pool_name, {'name': name,
                                               'format': 'raw',
                                               'capacity': downloaded_size,
                                               'allocation': downloaded_size})
                self.task.wait(task['id'])
                virt_vol = StorageVolumeModel.get_storagevolume(pool_name,
                                                                name,
                                                                self.conn)

                virt_stream = self.conn.get().newStream(0)
                virt_vol.upload(virt_stream, 0, downloaded_size, 0)

                with open(file_path) as fd:
                    virt_stream.sendAll(_stream_handler, fd)

                virt_stream.finish()
            except (IOError, libvirt.libvirtError) as e:
                try:
                    if virt_stream:
                        virt_stream.abort()
                    if virt_vol:
                        virt_vol.delete(0)
                except libvirt.libvirtError, virt_e:
                    kimchi_log.error(virt_e.message)
                finally:
                    raise OperationFailed('KCHVOL0007E', {'name': name,
                                                          'pool': pool_name,
                                                          'err': e.message})
            finally:
开发者ID:melmorabity,项目名称:kimchi,代码行数:77,代码来源:storagevolumes.py


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