def storage_pools(node): """Get 'protocol.Data_Pool' instance for all pools.""" if node.conn is None: raise StorageError(_('Error listing pools at "%(uri)s": %(error)s'), uri=node.pd.uri, error='no connection') try: pools = [] for name in timeout(node.conn.listStoragePools)() + timeout(node.conn.listDefinedStoragePools)(): pool = __get_storage_pool_info(node.conn, name) pools.append( pool ) return pools except TimeoutError, e: logger.warning('libvirt connection "%s" timeout: %s', node.pd.uri, e) node.pd.last_try = time.time() return pools
def storage_pools(node): """ Get 'protocol.Data_Pool' instance for all (active) pools. """ if node.conn is None: raise StorageError(_('Error listing pools at "%(uri)s": %(error)s'), uri=node.pd.uri, error='no connection') try: pools = [] for name in timeout(node.conn.listStoragePools)(): pool = get_pool_info(node, name) pools.append(pool) return pools except TimeoutError as ex: logger.warning( 'libvirt connection "%s" timeout: %s', node.pd.uri, ex, ) node.pd.last_try = time.time() return pools except libvirt.libvirtError as ex: logger.error(ex) raise StorageError( _('Error listing pools at "%(uri)s": %(error)s'), uri=node.uri, error=ex.get_error_message(), )
def storage_pools(node): """Get 'protocol.Data_Pool' instance for all pools.""" if node.conn is None: raise StorageError(_('Error listing pools at "%(uri)s": %(error)s'), uri=node.pd.uri, error='no connection') try: pools = [] for name in timeout(node.conn.listStoragePools)() + timeout( node.conn.listDefinedStoragePools)(): pool = __get_storage_pool_info(node.conn, name) pools.append(pool) return pools except TimeoutError, e: logger.warning('libvirt connection "%s" timeout: %s', node.pd.uri, e) node.pd.last_try = time.time() return pools
def get_storage_volumes(node, pool_name, type=None): """Get 'protocol.Disk' instance for all Storage Volumes in named pool of given type.""" if node.conn is None: raise StorageError(_('Error listing volumes at "%(uri)s": %(error)s'), uri=node.uri, error='no connection') volumes = [] try: pool = timeout(node.conn.storagePoolLookupByName)(pool_name) pool.refresh(0) except TimeoutError, e: logger.warning('libvirt connection "%s" timeout: %s', node.pd.uri, e) node.pd.last_try = time.time() return volumes
def get_storage_volumes(node, pool_name, type=None): """ Get 'protocol.Disk' instance for all Storage Volumes in named pool of given type. """ if node.conn is None: raise StorageError(_('Error listing volumes at "%(uri)s": %(error)s'), uri=node.uri, error='no connection') volumes = [] try: pool = timeout(node.conn.storagePoolLookupByName)(pool_name) xml = pool.XMLDesc(0) pool_tree = ET.fromstring(xml) pool_type = pool_tree.attrib['type'] if pool_type in ('dir', 'fs', 'netfs'): pool.refresh(0) except TimeoutError as ex: logger.warning('libvirt connection "%s" timeout: %s', node.pd.uri, ex) node.pd.last_try = time.time() return volumes except libvirt.libvirtError as ex: logger.error(ex) raise StorageError( _('Error listing volumes at "%(uri)s": %(error)s'), uri=node.pd.uri, error=ex.get_error_message(), ) xml = pool.XMLDesc(0) pool_tree = ET.fromstring(xml) pool_type = pool_tree.attrib['type'] for name in pool.listVolumes(): vol = pool.storageVolLookupByName(name) xml = vol.XMLDesc(0) try: volume_tree = ET.fromstring(xml) except ET.XMLSyntaxError: continue disk = Disk() disk.pool = pool_name disk.size = int(volume_tree.findtext('capacity')) target = volume_tree.find('target') disk.source = target.findtext('path') disk.type = POOLS_TYPE.get(pool_type) if disk.type == Disk.TYPE_FILE: disk.driver_type = target.find('format').attrib['type'] if disk.driver_type == 'iso': disk.device = Disk.DEVICE_CDROM else: disk.device = Disk.DEVICE_DISK elif disk.type == Disk.TYPE_BLOCK: disk.device = Disk.DEVICE_DISK disk.driver_type = None # raw elif disk.source.startswith('/dev/'): disk.type = Disk.TYPE_BLOCK disk.device = Disk.DEVICE_DISK disk.driver_type = None # raw else: logger.info('Unsupported storage pool type: %s', pool_type) continue if not type or disk.device == type: volumes.append(disk) return volumes