add docs
This commit is contained in:
@ -162,16 +162,16 @@ class DeviceConfig:
|
||||
|
||||
|
||||
class Instance:
|
||||
"""Class for manipulating compute instance."""
|
||||
"""Manage compute instances."""
|
||||
|
||||
def __init__(self, domain: libvirt.virDomain):
|
||||
"""
|
||||
Initialise Instance.
|
||||
|
||||
:prop domain libvirt.virDomain:
|
||||
:prop connection libvirt.virConnect:
|
||||
:prop name str:
|
||||
:prop guest_agent GuestAgent:
|
||||
:ivar libvirt.virDomain domain: domain object
|
||||
:ivar libvirt.virConnect connection: connection object
|
||||
:ivar str name: domain name
|
||||
:ivar GuestAgent guest_agent: :class:`GuestAgent` object
|
||||
|
||||
:param domain: libvirt domain object
|
||||
"""
|
||||
|
@ -44,27 +44,27 @@ class CPUSchema(BaseModel):
|
||||
features: CPUFeaturesSchema
|
||||
|
||||
|
||||
class StorageVolumeType(StrEnum):
|
||||
class VolumeType(StrEnum):
|
||||
"""Storage volume types enumeration."""
|
||||
|
||||
FILE = 'file'
|
||||
NETWORK = 'network'
|
||||
|
||||
|
||||
class StorageVolumeCapacitySchema(BaseModel):
|
||||
class VolumeCapacitySchema(BaseModel):
|
||||
"""Storage volume capacity field model."""
|
||||
|
||||
value: int
|
||||
unit: DataUnit
|
||||
|
||||
|
||||
class StorageVolumeSchema(BaseModel):
|
||||
class VolumeSchema(BaseModel):
|
||||
"""Storage volume model."""
|
||||
|
||||
type: StorageVolumeType # noqa: A003
|
||||
type: VolumeType # noqa: A003
|
||||
source: Path
|
||||
target: str
|
||||
capacity: StorageVolumeCapacitySchema
|
||||
capacity: VolumeCapacitySchema
|
||||
readonly: bool = False
|
||||
is_system: bool = False
|
||||
|
||||
@ -98,7 +98,7 @@ class InstanceSchema(BaseModel):
|
||||
arch: str
|
||||
image: str
|
||||
boot: BootOptionsSchema
|
||||
volumes: list[StorageVolumeSchema]
|
||||
volumes: list[VolumeSchema]
|
||||
network_interfaces: list[NetworkInterfaceSchema]
|
||||
|
||||
@validator('name')
|
||||
|
@ -29,16 +29,25 @@ class Capabilities(NamedTuple):
|
||||
|
||||
|
||||
class Session(AbstractContextManager):
|
||||
"""Hypervisor session manager."""
|
||||
"""
|
||||
Hypervisor session context manager.
|
||||
|
||||
:cvar IMAGES_POOL: images storage pool name taken from env
|
||||
:cvar VOLUMES_POOL: volumes storage pool name taken from env
|
||||
"""
|
||||
|
||||
IMAGES_POOL = os.getenv('CMP_IMAGES_POOL')
|
||||
VOLUMES_POOL = os.getenv('CMP_VOLUMES_POOL')
|
||||
|
||||
def __init__(self, uri: str | None = None):
|
||||
"""
|
||||
Initialise session with hypervisor.
|
||||
|
||||
:ivar str uri: libvirt connection URI.
|
||||
:ivar libvirt.virConnect connection: libvirt connection object.
|
||||
|
||||
:param uri: libvirt connection URI.
|
||||
"""
|
||||
self.IMAGES_POOL = os.getenv('CMP_IMAGES_POOL')
|
||||
self.VOLUMES_POOL = os.getenv('CMP_VOLUMES_POOL')
|
||||
self.uri = uri or 'qemu:///system'
|
||||
self.connection = libvirt.open(self.uri)
|
||||
|
||||
@ -74,11 +83,16 @@ class Session(AbstractContextManager):
|
||||
"""
|
||||
Create and return new compute instance.
|
||||
|
||||
:param name str: Instance name.
|
||||
:param title str: Instance title for humans.
|
||||
:param description str: Some information about instance
|
||||
:param memory int: Memory in MiB.
|
||||
:param max_memory int: Maximum memory in MiB.
|
||||
:param name: Instance name.
|
||||
:type name: str
|
||||
:param title: Instance title for humans.
|
||||
:type title: str
|
||||
:param description: Some information about instance
|
||||
:type description: str
|
||||
:param memory: Memory in MiB.
|
||||
:type memory: int
|
||||
:param max_memory: Maximum memory in MiB.
|
||||
:type max_memory: int
|
||||
"""
|
||||
# TODO @ge: create instances in transaction
|
||||
data = InstanceSchema(**kwargs)
|
||||
|
@ -24,7 +24,7 @@ class InvalidDataUnitError(ValueError):
|
||||
|
||||
|
||||
def to_bytes(value: int, unit: DataUnit = DataUnit.BYTES) -> int:
|
||||
"""Convert value to bytes. See `DataUnit`."""
|
||||
"""Convert value to bytes. See :class:`DataUnit`."""
|
||||
try:
|
||||
_ = DataUnit(unit)
|
||||
except ValueError as e:
|
||||
|
Reference in New Issue
Block a user