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


Python storagepools.StoragePoolModel类代码示例

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


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

示例1: _create_volume_with_url

    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,代码行数:30,代码来源:storagevolumes.py

示例2: _create_volume_with_file

    def _create_volume_with_file(self, cb, params):
        pool_name = params.pop('pool')
        dir_path = StoragePoolModel(
            conn=self.conn, objstore=self.objstore).lookup(pool_name)['path']
        file_path = os.path.join(dir_path, params['name'])
        if os.path.exists(file_path):
            raise InvalidParameter('KCHVOL0001E', {'name': params['name']})

        upload_file = params['file']
        f_len = upload_file.fp.length
        try:
            size = 0
            with open(file_path, 'wb') as f:
                while True:
                    data = upload_file.file.read(READ_CHUNK_SIZE)
                    if not data:
                        break
                    size += len(data)
                    f.write(data)
                    cb('%s/%s' % (size, f_len))
        except Exception as e:
            raise OperationFailed('KCHVOL0007E',
                                  {'name': params['name'],
                                   'pool': pool_name,
                                   'err': e.message})

        # Refresh to make sure volume can be found in following lookup
        StoragePoolModel.get_storagepool(pool_name, self.conn).refresh(0)
        cb('OK', True)
开发者ID:Gossing,项目名称:kimchi,代码行数:29,代码来源:storagevolumes.py

示例3: StorageServerModel

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,代码行数:25,代码来源:storageservers.py

示例4: _create_volume_with_capacity

    def _create_volume_with_capacity(self, cb, params):
        pool_name = params.pop('pool')
        vol_xml = """
        <volume>
          <name>%(name)s</name>
          <allocation unit="MiB">%(allocation)s</allocation>
          <capacity unit="MiB">%(capacity)s</capacity>
          <source>
          </source>
          <target>
            <format type='%(format)s'/>
          </target>
        </volume>
        """
        params.setdefault('allocation', 0)
        params.setdefault('format', 'qcow2')

        name = params['name']
        vol_id = '%s:%s' % (pool_name, name)
        try:
            pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
            xml = vol_xml % params
        except KeyError, item:
            raise MissingParameter("KCHVOL0004E", {'item': str(item),
                                                   'volume': name})
开发者ID:Gossing,项目名称:kimchi,代码行数:25,代码来源:storagevolumes.py

示例5: StorageServersModel

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,代码行数:29,代码来源:storageservers.py

示例6: get_list

 def get_list(self, pool):
     pool = StoragePoolModel.get_storagepool(pool, self.conn)
     if not pool.isActive():
         err = "Unable to list volumes in inactive storagepool %s"
         raise InvalidOperation(err % pool.name())
     try:
         pool.refresh(0)
         return pool.listVolumes()
     except libvirt.libvirtError as e:
         raise OperationFailed(e.get_error_message())
开发者ID:mprostko,项目名称:kimchi,代码行数:10,代码来源:storagevolumes.py

示例7: get_list

 def get_list(self, pool_name):
     pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
     if not pool.isActive():
         raise InvalidOperation("KCHVOL0006E", {'pool': pool_name})
     try:
         pool.refresh(0)
         return sorted(map(lambda x: x.decode('utf-8'), pool.listVolumes()))
     except libvirt.libvirtError as e:
         raise OperationFailed("KCHVOL0008E",
                               {'pool': pool_name,
                                'err': e.get_error_message()})
开发者ID:melmorabity,项目名称:kimchi,代码行数:11,代码来源:storagevolumes.py

示例8: get_storagevolume

 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
开发者ID:melmorabity,项目名称:kimchi,代码行数:12,代码来源:storagevolumes.py

示例9: _get_storagevolume

 def _get_storagevolume(self, pool, name):
     pool = StoragePoolModel.get_storagepool(pool, self.conn)
     if not pool.isActive():
         err = "Unable to list volumes in inactive storagepool %s"
         raise InvalidOperation(err % pool.name())
     try:
         return pool.storageVolLookupByName(name)
     except libvirt.libvirtError as e:
         if e.get_error_code() == libvirt.VIR_ERR_NO_STORAGE_VOL:
             raise NotFoundError("Storage Volume '%s' not found" % name)
         else:
             raise
开发者ID:mprostko,项目名称:kimchi,代码行数:12,代码来源:storagevolumes.py

示例10: _clone_task

    def _clone_task(self, cb, params):
        """Asynchronous function which performs the clone operation.

        This function copies all the data inside the original volume into the
        new one.

        Arguments:
        cb -- A callback function to signal the Task's progress.
        params -- A dict with the following values:
            "pool": The name of the original pool.
            "name": The name of the original volume.
            "new_pool": The name of the destination pool.
            "new_name": The name of the new volume.
        """
        orig_pool_name = params['pool']
        orig_vol_name = params['name']
        new_pool_name = params['new_pool']
        new_vol_name = params['new_name']

        try:
            cb('setting up volume cloning')
            orig_vir_vol = StorageVolumeModel.get_storagevolume(orig_pool_name,
                                                                orig_vol_name,
                                                                self.conn)
            orig_vol = self.lookup(orig_pool_name, orig_vol_name)
            new_vir_pool = StoragePoolModel.get_storagepool(new_pool_name,
                                                            self.conn)

            cb('building volume XML')
            root_elem = E.volume()
            root_elem.append(E.name(new_vol_name))
            root_elem.append(E.capacity(unicode(orig_vol['capacity']),
                                        unit='bytes'))
            target_elem = E.target()
            target_elem.append(E.format(type=orig_vol['format']))
            root_elem.append(target_elem)
            new_vol_xml = ET.tostring(root_elem, encoding='utf-8',
                                      pretty_print=True)

            cb('cloning volume')
            new_vir_pool.createXMLFrom(new_vol_xml, orig_vir_vol, 0)
        except (InvalidOperation, NotFoundError, libvirt.libvirtError), e:
            raise OperationFailed('KCHVOL0023E',
                                  {'name': orig_vol_name,
                                   'pool': orig_pool_name,
                                   'err': e.get_error_message()})
开发者ID:melmorabity,项目名称:kimchi,代码行数:46,代码来源:storagevolumes.py

示例11: StorageServerModel

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,代码行数:20,代码来源:storageservers.py

示例12: StorageServerModel

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,代码行数:21,代码来源:storageservers.py

示例13: get_list

    def get_list(self):
        iso_volumes = []
        conn = self.conn.get()
        pools = conn.listStoragePools()
        pools += conn.listDefinedStoragePools()

        for pool_name in pools:
            try:
                pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
                pool.refresh(0)
                volumes = pool.listVolumes()
            except InvalidOperation:
                # Skip inactive pools
                continue

            for volume in volumes:
                res = self.storagevolume.lookup(pool_name, volume)
                if res['format'] == 'iso':
                    res['name'] = '%s' % volume
                    iso_volumes.append(res)
        return iso_volumes
开发者ID:jayzcode,项目名称:kimchi,代码行数:21,代码来源:storagevolumes.py

示例14: create

    def create(self, pool, params):
        vol_xml = """
        <volume>
          <name>%(name)s</name>
          <allocation unit="MiB">%(allocation)s</allocation>
          <capacity unit="MiB">%(capacity)s</capacity>
          <source>
          </source>
          <target>
            <format type='%(format)s'/>
          </target>
        </volume>
        """
        params.setdefault('allocation', 0)
        params.setdefault('format', 'qcow2')

        try:
            pool = StoragePoolModel.get_storagepool(pool, self.conn)
            name = params['name']
            xml = vol_xml % params
        except KeyError, key:
            raise MissingParameter(key)
开发者ID:mprostko,项目名称:kimchi,代码行数:22,代码来源:storagevolumes.py

示例15: get_list

    def get_list(self):
        iso_volumes = []
        conn = self.conn.get()
        pools = conn.listStoragePools()
        pools += conn.listDefinedStoragePools()

        for pool_name in pools:
            try:
                pool = StoragePoolModel.get_storagepool(pool_name, self.conn)
                pool.refresh(0)
                volumes = pool.listVolumes()
            except Exception, e:
                # Skip inactive pools
                kimchi_log.debug("Shallow scan: skipping pool %s because of "
                                 "error: %s", (pool_name, e.message))
                continue

            for volume in volumes:
                res = self.storagevolume.lookup(pool_name, volume)
                if res['format'] == 'iso':
                    res['name'] = '%s' % volume
                    iso_volumes.append(res)
开发者ID:bdacode,项目名称:kimchi,代码行数:22,代码来源:storagevolumes.py


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