various improvemets
This commit is contained in:
		@@ -49,12 +49,12 @@ class StoragePool:
 | 
			
		||||
 | 
			
		||||
    def _get_path(self) -> Path:
 | 
			
		||||
        """Return storage pool path."""
 | 
			
		||||
        xml = etree.fromstring(self.pool.XMLDesc())  # noqa: S320
 | 
			
		||||
        xml = etree.fromstring(self.pool.XMLDesc())
 | 
			
		||||
        return Path(xml.xpath('/pool/target/path/text()')[0])
 | 
			
		||||
 | 
			
		||||
    def get_usage_info(self) -> StoragePoolUsageInfo:
 | 
			
		||||
        """Return info about storage pool usage."""
 | 
			
		||||
        xml = etree.fromstring(self.pool.XMLDesc())  # noqa: S320
 | 
			
		||||
        xml = etree.fromstring(self.pool.XMLDesc())
 | 
			
		||||
        return StoragePoolUsageInfo(
 | 
			
		||||
            capacity=int(xml.xpath('/pool/capacity/text()')[0]),
 | 
			
		||||
            allocation=int(xml.xpath('/pool/allocation/text()')[0]),
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@
 | 
			
		||||
from dataclasses import dataclass
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
from time import time
 | 
			
		||||
from typing import Union
 | 
			
		||||
 | 
			
		||||
import libvirt
 | 
			
		||||
from lxml import etree
 | 
			
		||||
@@ -88,6 +89,28 @@ class DiskConfig(DeviceConfig):
 | 
			
		||||
            xml.append(E.readonly())
 | 
			
		||||
        return etree.tostring(xml, encoding='unicode', pretty_print=True)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def from_xml(cls, xml: Union[str, etree.Element]) -> 'DiskConfig':  # noqa: UP007
 | 
			
		||||
        """
 | 
			
		||||
        Return :class:`DiskConfig` instance using existing XML config.
 | 
			
		||||
 | 
			
		||||
        :param xml: Disk device XML configuration as :class:`str` or lxml
 | 
			
		||||
            :class:`etree.Element` object.
 | 
			
		||||
        """
 | 
			
		||||
        if isinstance(xml, str):
 | 
			
		||||
            xml = etree.fromstring(xml)
 | 
			
		||||
        disk_params = {
 | 
			
		||||
            'disk_type': xml.get('type'),
 | 
			
		||||
            'source': xml.find('source').get('file'),
 | 
			
		||||
            'target': xml.find('target').get('dev'),
 | 
			
		||||
            'readonly': False if xml.find('readonly') is None else True,  # noqa: SIM211
 | 
			
		||||
        }
 | 
			
		||||
        for param in disk_params:
 | 
			
		||||
            if disk_params[param] is None:
 | 
			
		||||
                msg = f"Bad XML config: parameter '{param}' is not defined"
 | 
			
		||||
                raise ValueError(msg)
 | 
			
		||||
        return cls(**disk_params)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Volume:
 | 
			
		||||
    """Storage volume manipulating class."""
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user