move schema in new repo

This commit is contained in:
Mickael BOURNEUF 2024-10-08 19:09:39 +02:00
parent f56d1be2cc
commit fcd33f4372
3 changed files with 958 additions and 0 deletions

255
api/vm.py Normal file
View File

@ -0,0 +1,255 @@
from typing import List, Tuple, Optional
from enum import Enum, IntEnum
from uuid import UUID, uuid4
from pydantic_xml import element, attr, wrapped
from pydantic import UUID4, Field, field_serializer, ConfigDict, ValidationInfo, field_validator
from pydantic import BaseModel as _BaseModel
from pydantic_core import core_schema as cs
import libvirt
from pydantic_core import core_schema
from pydantic.json_schema import GetJsonSchemaHandler, JsonSchemaValue
from deevirt_common.lib.virt import vm as domain
from deevirt_common.schemas import datacenter_schema, storage_schema, network_schema, libvirt
class BaseModel(_BaseModel):
class Config:
@staticmethod
def json_schema_extra(schema: dict, _):
props = {}
for k, v in schema.get('properties', {}).items():
if not v.get("hidden", False):
props[k] = v
schema["properties"] = props
""" Common """
class VMResource(BaseModel):
"""Experimental"""
name:Optional[str] = Field(default=None, description="Nom du pool")
class VMVCPU(BaseModel):
value:int = Field(description="Nombre de VCPU")
dedicated:Optional[bool] = Field(default=False, description="VCPU dédié")
hotplug:Optional[bool] = Field(default=False, description="Ajout de VCPU à chaud.")
class VMMemory(BaseModel):
unit:Optional[libvirt.UnitEnum] = Field(default=libvirt.UnitEnum.GiB, description="Unité de mesure.")
value:int = Field(description="Taille de la mémoire.")
hotplug:Optional[bool] = Field(default=False,description="Ajout à chaud de la mémoire.")
class VMOSBootMenu(BaseModel):
enable:Optional[bool] = Field(default=False,description="Activation du menu de démarrage.")
delay:Optional[int] = Field(default=0, description="Delai maximal pour entrer dans le menu démarrage en millisecondes")
class VMOSBootOrder(BaseModel):
dev:Optional[libvirt.OSBoot.bootEnum] = Field(default=None, description="Périphérique.")
class VMOSInfo(BaseModel):
model_config = ConfigDict(from_attributes=True)
name:str = Field(alias="os.name", serialization_alias="name")
version:str = Field(alias="os.version-id", serialization_alias="version")
machine:str = Field(alias="os.machine", serialization_alias="architecture")
kernel:str = Field(alias="os.kernel-release", serialization_alias="kernel")
class VMOS(BaseModel):
firmware:libvirt.OS.firmwareEnum = Field(default=libvirt.OS.firmwareEnum.bios, description="Microprogramme")
enrolled_keys:Optional[bool] = Field(default=None, description="Vérification de la signature du chargeur de démarrage")
secure_boot:Optional[bool] = Field(default=None, description="Démarrage sécurisé")
boot_order:Optional[List[libvirt.OSBoot.bootEnum]] = Field(default=None, description="Ordre de démarrage des périphériques")
boot_menu:VMOSBootMenu = Field(default=VMOSBootMenu(), description="Menu de démarrage")
class VMClock(BaseModel):
class offsetEnum(str, Enum):
utc = "utc"
localtime = "localtime"
timezone = "timezone"
variable = "variable"
absolute = "absolute"
offset:offsetEnum = Field(default=offsetEnum.utc, description="Sélection de l'offset ?")
class VMEvent(BaseModel):
class on_poweroffEnum(str, Enum):
destroy = "destroy"
restart = "restart"
preserve = "preverse"
class on_rebootEnum(str, Enum):
restart = "restart"
preserve = "preverse"
class on_crashEnum(str, Enum):
destroy = "destroy"
restart = "restart"
preserve = "preverse"
class on_failurelockEnum(str, Enum):
poweroff = "poweroff"
restart = "restart"
pause = "pause"
ignore = "ignore"
on_poweroff:on_poweroffEnum = Field(default=on_poweroffEnum.destroy, description="Action lors d'un poweroff")
on_reboot:on_rebootEnum = Field(default=on_rebootEnum.restart, description="Action lors d'un redémarrage")
on_crash:on_crashEnum = Field(default=on_crashEnum.restart, description="Action lors d'un crash de la VM")
on_failurelock:on_failurelockEnum = element(default=on_failurelockEnum.ignore, description="A tester")
class VMDevicesDisk(BaseModel):
model_config = ConfigDict(from_attributes=True)
pool_id:UUID4 = Field()
id:UUID4 = Field()
size:int = Field()
unit:libvirt.UnitEnum = Field(default=libvirt.UnitEnum.GiB)
bus:libvirt.DevicesDiskTarget.busEnum = Field(default=libvirt.DevicesDiskTarget.busEnum.scsi)
class VMDevicesCDROMSource(BaseModel):
class protocolEnum(str, Enum):
http = "http"
https = "https"
ftp = "ftp"
ftps = "ftps"
protocol:protocolEnum = attr(default=protocolEnum.https)
name:str = attr()
class VMDevicesCDROM(BaseModel):
model_config = ConfigDict(from_attributes=True)
device:libvirt.DevicesDisk.deviceEnum = Field(default=libvirt.DevicesDisk.deviceEnum.cdrom, json_schema_extra={"hidden": True})
source:VMDevicesCDROMSource = element(default=None)
class VMDevicesInterfaceGuest(BaseModel):
model_config = ConfigDict(from_attributes=True)
addr:str = Field()
class VMDevicesInterface(BaseModel):
model_config = ConfigDict(from_attributes=True)
switch_id:UUID4
id:UUID4
mac_addr:str = Field()
class VMGraphics(BaseModel):
port:int = Field(default=-1)
autoport:bool = Field(default=False)
websocket:int = Field(default=-1)
password:Optional[str] = Field(default=None)
keymap:libvirt.Graphics.keymapEnum = Field(default=libvirt.Graphics.keymapEnum.fr)
power_control:bool = Field(default=False)
class VMAudio(BaseModel):
pass
class VMVideoModel(BaseModel):
type:libvirt.VideoModel.typeEnum = Field(default=libvirt.VideoModel.typeEnum.cirrus)
vram:int = Field(default=16384)
primary:libvirt.YesNoEnum = Field(default=libvirt.YesNoEnum.YES)
class VMVideo(BaseModel):
model:VMVideoModel = element()
class VMWatchdog(BaseModel):
model:libvirt.Watchdog.modelEnum = Field(default=libvirt.Watchdog.modelEnum.itco)
action:libvirt.Watchdog.actionEnum = Field(default=libvirt.Watchdog.actionEnum.reset)
class VMTPM(BaseModel):
model:libvirt.TPM.modelEnum = attr(default=libvirt.TPM.modelEnum.tpm_tis)
version:libvirt.TPMBackend.versionEnum = Field(default=libvirt.TPMBackend.versionEnum.v20)
class VMDevices(BaseModel):
disks:Optional[List[VMDevicesDisk]] = Field(default=None, description="Disques virtuel")
cdrom:VMDevicesCDROM = Field(default=None, description="CDROM virtuel")
interfaces:Optional[List[VMDevicesInterface]] = Field(default=None, description="Interfaces réseau")
graphics:Optional[VMGraphics] = Field(default=None, description="Console VNC")
audio:VMAudio = Field(default=None, description="Carte Audio")
video:VMVideo = Field(default=None, description="Carte Vidéo")
watchdog:VMWatchdog = Field(default=None, description="Chien de garde")
tpm:VMTPM = Field(default=None, description="Puce de sécurité")
class VM(BaseModel):
model_config = ConfigDict(from_attributes=True)
# General metadata
id:UUID4 = Field()
datacenter_id:Optional[UUID4] = Field(default=None)
name:str = Field()
description:Optional[str] = Field(default=None)
# CPU Allocation
vcpu:VMVCPU = Field()
# Memory Allocation
memory:VMMemory = Field()
# Pool of resource (Experimental)
resource:VMResource = Field(default=VMResource(), description="Pool de resources")
# BIOS BootLoader
os:VMOS = Field(default=VMOS(), description="Options VM: Options de démarrage.")
# Clock configuration
clock:VMClock = Field(default=VMClock(), description="Options VM: Gestion de l'horloge")
# Event configuration
event:VMEvent = Field(default=VMEvent(), description="Options VM: Gestion des évènements")
# Devices
devices:VMDevices = Field(default=VMDevices(), description="Matériel virtuel: Périphériques")
"""VM LIST GET"""
class VMs(BaseModel):
model_config = ConfigDict(from_attributes=True)
class Datacenter(BaseModel):
model_config = ConfigDict(from_attributes=True)
id:UUID4
name:str
id:UUID4
name:str
state:int
datacenter:Optional[Datacenter] = Field(default=[])
"""VM GET"""
class VMGetVCPU(VMVCPU):
max:Optional[int] = Field(default=None, description="Maximum de VCPUs")
class VMGetOS(VMOS):
guest_info:Optional[VMOSInfo] = Field(default=None, description="Information de l'OS client")
class VMGetDevicesDisk(VMDevicesDisk):
allocated:float = Field(default=None)
class VMGetDevicesInterface(VMDevicesInterface):
guest_info:Optional[List[VMDevicesInterfaceGuest]] = Field(default=None, description="Information de configuration de la carte réseau.")
class VMGetDevices(VMDevices):
disks:Optional[List[VMGetDevicesDisk]] = Field(default=None, description="Disques virtuel")
interfaces:Optional[List[VMGetDevicesInterface]] = Field(default=None, description="Interfaces réseau")
class VMGet(VM):
vcpu:VMGetVCPU = Field()
gen_id:Optional[UUID4] = Field(default=None)
os:VMGetOS = Field(default=VMGetOS(), description="Options VM: Options de démarrage.")
devices:VMGetDevices = Field(default=VMGetDevices(), description="Matériel virtuel: Périphériques")
"""VM POST"""
class VMCreate(VM):
id:UUID4 = Field(default_factory=uuid4)
datacenter_id:UUID4 = Field()
"""VM DELETE"""
class VMDelete(BaseModel):
id:UUID4 = Field()
class VMHardDisk(BaseModel):
pass
class VMNetInterfaceCreate(BaseModel):
pass

688
libvirt/dom/config.py Normal file
View File

@ -0,0 +1,688 @@
from enum import Enum
from typing import List, Optional
from uuid import uuid4
from pydantic import UUID4
from pydantic_xml import BaseXmlModel, attr, element, wrapped
from deevirt_schema.libvirt.enum import YesNoEnum, OnOffEnum, UnitEnum
class Metadata(BaseXmlModel, search_mode='ordered'):
# wrapped("metadata", element(default=None, ns="deevirt", nsmap={'deevirt': 'https://deevirt.com/'}))
pass
class OSType(BaseXmlModel, search_mode='ordered'):
class archEnum(str, Enum):
x86 = "x86"
x86_64 = "x86_64"
arch:archEnum = attr(default=archEnum.x86_64)
machine:Optional[str] = attr(default="q35")
class OSFirmwareFeature(BaseXmlModel, search_mode='ordered'):
class nameEnum(str, Enum):
enrolled_keys = "enrolled-keys"
secure_boot = "secure-boot"
enabled:YesNoEnum = attr(default=YesNoEnum.YES)
name:nameEnum = attr()
class OSFirmware(BaseXmlModel, search_mode='ordered'):
feature:List[OSFirmwareFeature] = element(default=[
OSFirmwareFeature(
name=OSFirmwareFeature.nameEnum.enrolled_keys
),
OSFirmwareFeature(
name=OSFirmwareFeature.nameEnum.secure_boot
)
]
)
class OSLoader(BaseXmlModel, search_mode='ordered'):
class typeEnum(str, Enum):
nvram = "nvram"
pflash = "pflash"
readonly:YesNoEnum = attr(default=YesNoEnum.YES)
secure:YesNoEnum = attr(default=YesNoEnum.YES)
type:typeEnum = attr(default=typeEnum.pflash)
path:Optional[str] = ""
class OSBoot(BaseXmlModel, search_mode='ordered'):
class bootEnum(str, Enum):
hd = "hd",
network = "network",
cdrom = "cdrom"
dev:bootEnum = attr()
class OSBootMenu(BaseXmlModel, search_mode='ordered'):
enable:YesNoEnum = attr(default=YesNoEnum.NO)
timeout:int = attr(default=0)
class OSSmbios(BaseXmlModel, search_mode='ordered'):
class modeEnum(str, Enum):
sysinfo = "sysinfo"
mode:modeEnum = attr(default=modeEnum.sysinfo)
class OS(BaseXmlModel, search_mode='ordered'):
class firmwareEnum(str, Enum):
bios = "bios"
efi = "efi"
firmware:Optional[firmwareEnum] = attr(default=firmwareEnum.efi)
type:OSType = element(default=OSType())
firmware_options:OSFirmware = element(tag="firmware", default=OSFirmware())
loader:OSLoader = element(default=OSLoader())
nvram:Optional[str] = element(default="")
boot:List[OSBoot] = element(default=[
OSBoot(dev="hd"),
OSBoot(dev="cdrom"),
OSBoot(dev="network")
])
bootmenu:OSBootMenu = element(default=OSBootMenu())
smbios:OSSmbios = element(default=OSSmbios())
class SysinfoEntry(BaseXmlModel, search_mode='ordered'):
name:str = attr()
value:str
class SysinfoBIOS(BaseXmlModel, search_mode='ordered'):
entry:SysinfoEntry = element(default=None)
class SysinfoSystem(BaseXmlModel, search_mode='ordered'):
entry:List[SysinfoEntry] = element(default=[
SysinfoEntry(
name="manufacturer",
value="Celeonet"
),
SysinfoEntry(
name="product",
value="Celeonet Compute"
),
SysinfoEntry(
name="version",
value="1.0"
),
SysinfoEntry(
name="family",
value="Virtual Machine"
)
])
class SysinfoBaseBoard(BaseXmlModel, search_mode='ordered'):
entry:List[SysinfoEntry] = element(default=None)
class SysinfoChassis(BaseXmlModel, search_mode='ordered'):
entry:List[SysinfoEntry] = element(default=None)
class SysinfoOEMStrings(BaseXmlModel, search_mode='ordered'):
entry:List[SysinfoEntry] = element(default=None)
class Sysinfo(BaseXmlModel, search_mode='ordered'):
bios:SysinfoBIOS = element(default=SysinfoBIOS())
system:Optional[SysinfoSystem] = element(default=SysinfoSystem())
baseBoard:Optional[SysinfoBaseBoard] = element(default=SysinfoBaseBoard())
chassis:Optional[SysinfoChassis] = element(default=SysinfoChassis())
oemStrings:Optional[SysinfoOEMStrings] = element(default=SysinfoOEMStrings())
class VCPU(BaseXmlModel, search_mode='ordered'):
class placementEnum(str, Enum):
static = "static"
auto = "auto"
placement:placementEnum = attr(default=placementEnum.auto)
cpuset:str = attr(default=None)
current:int = attr()
max:int = None
class VCPUS(BaseXmlModel, search_mode='ordered'):
id:int = attr()
enabled:YesNoEnum = attr(default=YesNoEnum.YES)
hotpluggable:YesNoEnum = attr(default=YesNoEnum.YES)
order:int = attr()
class CPUTune(BaseXmlModel, search_mode='ordered'):
"""Not implemented"""
pass
class MaxMemory(BaseXmlModel, search_mode='ordered'):
slots:int = attr()
unit:UnitEnum = attr(default=UnitEnum.MiB)
value:int
class Memory(BaseXmlModel, search_mode='ordered'):
unit:UnitEnum = attr(default=UnitEnum.MiB)
value:int
class CurrentMemory(BaseXmlModel, search_mode='ordered'):
unit:UnitEnum = attr(default=UnitEnum.MiB)
value:int
class MemoryBacking(BaseXmlModel, search_mode='ordered'):
"""Not implemented"""
pass
class MemTune(BaseXmlModel, search_mode='ordered'):
"""Not implemented"""
pass
class NumaTuneMemory(BaseXmlModel, search_mode='ordered'):
class modeEnum(str, Enum):
interleave = "interleave"
strict = "strict"
preferred = "preferred"
restrictive = "restrictive"
mode:modeEnum = attr()
modeset:str = attr()
class NumaMemnode(BaseXmlModel, search_mode='ordered'):
cellid:int = attr()
mode:NumaTuneMemory.modeEnum = attr()
nodeset:str = attr()
class NumaTune(BaseXmlModel, search_mode='ordered'):
memory:NumaTuneMemory = element()
memnode:NumaMemnode = element()
class ResourcePartition(BaseXmlModel, search_mode='ordered'):
value:str
class Resource(BaseXmlModel, search_mode='ordered'):
partition:ResourcePartition = element()
class CPUModel(BaseXmlModel, search_mode='ordered'):
class fallbackEnum(str, Enum):
force = "force"
require = "require"
optional = "optional"
disable = "disable"
forbird = "forbid"
fallback:fallbackEnum = attr()
value:str
class CPUTopology(BaseXmlModel, search_mode='ordered'):
sockets:int = attr()
dies:Optional[int] = attr(default=None)
clusters:Optional[int] = attr(default=None)
cores:int = attr()
threads:int = attr()
class CPUCache(BaseXmlModel, search_mode='ordered'):
class modeEnum(str, Enum):
emulate = "emulate"
passthrough = "passthrough"
disable = "disable"
level:int = attr()
mode:modeEnum = attr()
class CPUMaxphysaddr(BaseXmlModel, search_mode='ordered'):
class modeEnum(str, Enum):
emulate = "emulate"
passthrough = "passthrough"
mode:modeEnum = attr()
bits:int = attr()
class CPUFeature(BaseXmlModel, search_mode='ordered'):
class policyEnum(str, Enum):
force = "force"
require = "require"
optional = "optional"
disable = "disable"
forbid = "forbid"
policy:policyEnum = attr()
name:str = attr()
class CPUDistancesSibling(BaseXmlModel, search_mode='ordered'):
id:int = attr()
value:int = attr()
class CPUDistances(BaseXmlModel, search_mode='ordered'):
sibling:Optional[List[CPUDistancesSibling]] = element(default=None)
class CPUNumaCell(BaseXmlModel, search_mode='ordered'):
class memaccessEnum(str, Enum):
shared = "shared"
private = "private"
id:Optional[int] = attr()
cpus:Optional[str] = attr()
memory:Optional[int] = attr()
unit:Optional[UnitEnum] = attr(default=UnitEnum.KiB)
discard:Optional[YesNoEnum] = attr(default=None)
memaccess:Optional[memaccessEnum] = attr(default=None)
distances:Optional[CPUDistances] = element()
class CPUNuma(BaseXmlModel, search_mode='ordered'):
cell:Optional[List[CPUNumaCell]] = element(default=[])
class CPU(BaseXmlModel, search_mode='ordered'):
class matchEnum(str, Enum):
minimum = "minimum"
exact = "exact"
strict = "strict"
class modeEnum(str, Enum):
custom = "custom"
host_model = "host-model"
class checkEnum(str, Enum):
none = "none"
partial = "partial"
full = "full"
match:Optional[matchEnum] = attr(default=None)
mode:modeEnum = attr(default=modeEnum.host_model)
check:Optional[checkEnum] = attr(default=None)
model:Optional[CPUModel] = element(default=None)
vendor:Optional[str] = element(default=None)
topology:Optional[CPUTopology] = element(default=None)
cache:Optional[CPUCache] = element(default=None)
maxphysaddr:Optional[CPUMaxphysaddr] = element(default=None)
feature:Optional[CPUFeature] = element(default=None)
numa:Optional[CPUNuma] = element(default=None)
class PMSuspendToDisk(BaseXmlModel, search_mode='ordered'):
enabled:YesNoEnum = attr(default=YesNoEnum.NO)
class PMSuspendToMem(BaseXmlModel, search_mode='ordered'):
enabled:YesNoEnum = attr(default=YesNoEnum.NO)
class PM(BaseXmlModel, search_mode='ordered'):
suspend_to_disk:PMSuspendToDisk = element(tag="suspend-to-disk", default=PMSuspendToDisk())
suspend_to_mem:PMSuspendToMem = element(tag="suspend-to-mem", default=PMSuspendToMem())
class FeaturesKVMHidden(BaseXmlModel, search_mode='ordered'):
state:OnOffEnum = attr()
class FeaturesKVMHintDedicated(BaseXmlModel, search_mode='ordered'):
state:OnOffEnum = attr()
class FeaturesKVMPollControl(BaseXmlModel, search_mode='ordered'):
state:OnOffEnum = attr()
class FeaturesKVMPvIpi(BaseXmlModel, search_mode='ordered'):
state:OnOffEnum = attr()
class FeaturesKVMDirtyRing(BaseXmlModel, search_mode='ordered'):
state:OnOffEnum = attr()
size:int = attr()
class FeaturesKVM(BaseXmlModel, search_mode='ordered'):
hidden:Optional[FeaturesKVMHidden] = element(default=None)
hint_dedicated:Optional[FeaturesKVMHintDedicated] = element(tag="hint-dedicated", default=None)
poll_control:Optional[FeaturesKVMPollControl] = element(tag="poll-control", default=None)
pv_ipi:Optional[FeaturesKVMPvIpi] = element(tag="pv-ipi", default=None)
dirty_ring:Optional[FeaturesKVMDirtyRing] = element(tag="dirty-ring", default=None)
class Features(BaseXmlModel, search_mode='ordered'):
pae:str = element(default=None)
acpi:str = element(default="enable")
apic:str = element(default="enable")
hap:str = element(default=None)
privnet:str = element(default=None)
kvm:FeaturesKVM = element(default=None)
class ClockTimerCatchup(BaseXmlModel, search_mode='ordered'):
threshold:int = attr()
slew:int = attr()
limit:int = attr()
class ClockTimer(BaseXmlModel, search_mode='ordered'):
class nameEnum(str, Enum):
kvmclock = "kvmclock"
class tickpolicyEnum(str, Enum):
delay = "delay"
catchup = "catchup"
merge = "merge"
discard = "discard"
class trackEnum(str, Enum):
boot = "boot"
guest = "guest"
wall = "wall"
name:nameEnum = attr(default=nameEnum.kvmclock)
tickpolicy:Optional[tickpolicyEnum] = attr(default=None)
track:Optional[trackEnum] = attr(default=None)
catchup:Optional[ClockTimerCatchup] = element(default=None)
class Clock(BaseXmlModel, search_mode='ordered'):
class offsetEnum(str, Enum):
utc = "utc"
localtime = "localtime"
timezone = "timezone"
variable = "variable"
absolute = "absolute"
offset:offsetEnum = attr(default=offsetEnum.localtime)
timer:ClockTimer = element(default=None)
class Perf(BaseXmlModel, search_mode='ordered'):
"""Not implemented"""
pass
class DevicesDiskDriver(BaseXmlModel, search_mode='ordered'):
class nameEnum(str, Enum):
qemu = "qemu"
class typeEnum(str, Enum):
raw = "raw"
class discardEnum(str, Enum):
ignore = "ignore"
unmap = "unmap"
name:nameEnum = attr(default=nameEnum.qemu)
type:typeEnum = attr(default=typeEnum.raw)
discard:discardEnum = attr(default=discardEnum.unmap)
class DevicesDiskAuthSecret(BaseXmlModel, search_mode='ordered'):
class typeEnum(str, Enum):
ceph = "ceph"
type:typeEnum = attr(default=typeEnum.ceph)
uuid:str = attr(default="1")
class DevicesDiskAuth(BaseXmlModel, search_mode='ordered'):
username:str = attr(default="1")
secret:DevicesDiskAuthSecret = element(default=DevicesDiskAuthSecret())
class DevicesDiskSourceHost(BaseXmlModel, search_mode='ordered'):
name:str = attr()
port:int = attr()
class DevicesDiskSource(BaseXmlModel, search_mode='ordered'):
class protocolEnum(str, Enum):
rbd = "rbd"
http = "http"
https = "https"
ftp = "ftp"
ftps = "ftps"
protocol:protocolEnum = attr(default=protocolEnum.rbd)
name:str = attr()
host:List[DevicesDiskSourceHost] = element(default=None)
class DevicesDiskTarget(BaseXmlModel, search_mode='ordered'):
class busEnum(str, Enum):
virtio = "virtio"
scsi = "scsi"
ide = "ide"
dev:str = attr()
bus:busEnum = attr(default=busEnum.virtio)
class DevicesDisk(BaseXmlModel, search_mode='ordered'):
"""
Disk: CEPH Storage only
CDROM: Network Only
"""
class typeEnum(str, Enum):
network = "network"
class deviceEnum(str, Enum):
disk = "disk"
cdrom = "cdrom"
type:typeEnum = attr(default=typeEnum.network)
device:deviceEnum = attr(default=deviceEnum.disk)
driver:DevicesDiskDriver = element(default=DevicesDiskDriver())
auth:DevicesDiskAuth = element(default=None)
source:DevicesDiskSource = element(default=None)
target:DevicesDiskTarget = element(default=None)
serial:UUID4 = element(default_factory=uuid4)
class DevicesInterfaceMAC(BaseXmlModel, search_mode='ordered'):
address:Optional[str] = attr(default=None)
class DevicesInterfaceSource(BaseXmlModel, search_mode='ordered'):
bridge:str = attr(default="br-int")
class DevicesInterfaceVirtualPortParameters(BaseXmlModel, search_mode='ordered'):
interfaceid:UUID4 = attr(default=None)
class DevicesInterfaceVirtualport(BaseXmlModel, search_mode='ordered'):
class typeEnum(str, Enum):
openvswitch = "openvswitch"
type:typeEnum = attr(default=typeEnum.openvswitch)
parameters:DevicesInterfaceVirtualPortParameters = element(default=DevicesInterfaceVirtualPortParameters())
class DevicesInterfaceModel(BaseXmlModel, search_mode='ordered'):
class typeEnum(str, Enum):
virtio = "virtio"
type:typeEnum = attr(default=typeEnum.virtio)
class DevicesInterfaceMTU(BaseXmlModel, search_mode='ordered'):
mtu:int = attr(default=1500)
class DevicesInterface(BaseXmlModel, search_mode='ordered'):
"""Openvswitch Only"""
class typeEnum(str, Enum):
bridge = "bridge"
type:typeEnum = attr(default=typeEnum.bridge)
mac:DevicesInterfaceMAC = element(default=DevicesInterfaceMAC())
source:DevicesInterfaceSource = element(default=DevicesInterfaceSource())
virtualport:DevicesInterfaceVirtualport = element(default=DevicesInterfaceVirtualport())
model:DevicesInterfaceModel = element(default=DevicesInterfaceModel())
mtu:DevicesInterfaceMTU = element(default=DevicesInterfaceMTU())
class DevicesChannelSource(BaseXmlModel, search_mode='ordered'):
class modeEnum(str, Enum):
bind = "bind"
mode:modeEnum = attr(default=modeEnum.bind)
path:str = attr(default=None)
class DevicesChannelTarget(BaseXmlModel, search_mode='ordered'):
class typeEnum(str, Enum):
virtio = "virtio"
type:typeEnum = attr(default=typeEnum.virtio)
name:str = attr(default="org.qemu.guest_agent.0")
class DevicesChannel(BaseXmlModel):
class typeEnum(str, Enum):
unix = "unix"
type:typeEnum = attr(default=typeEnum.unix)
source:DevicesChannelSource = element(default=DevicesChannelSource())
target:DevicesChannelTarget = element(default=DevicesChannelTarget())
class Graphics(BaseXmlModel, search_mode='ordered'):
class typeEnum(str, Enum):
vnc = "vnc"
class keymapEnum(str, Enum):
ar = "ar"
bepo = "bepo"
cz = "cz"
da = "da"
de = "de"
de_ch = "de-ch"
en_gb = "en-gb"
en_us = "en-us"
es = "es"
et = "et"
fi = "fi"
fo = "fo"
fr = "fr"
fr_be = "fr-be"
fr_ca = "fr-ca"
fr_ch = "fr-ch"
hr = "hr"
hu = "hu"
it = "it"
lv = "lv"
mk = "mk"
nl = "nl"
no = "no"
pl = "pl"
pt = "pt"
pt_br = "pt-br"
ru = "ru"
sl = "sl"
sv = "sv"
th = "th"
tr = "tr"
type:typeEnum = attr(default=typeEnum.vnc)
port:int = attr(default=-1)
autoport:YesNoEnum = attr(default=YesNoEnum.YES)
websocket:int = attr(default=-1)
listen:str = attr(default="0.0.0.0")
password:Optional[str] = attr(default=None)
keymap:keymapEnum = attr(default=keymapEnum.en_us)
powerControl:YesNoEnum = attr(default=YesNoEnum.YES)
class Audio(BaseXmlModel, search_mode='ordered'):
pass
class VideoModel(BaseXmlModel, search_mode='ordered'):
class typeEnum(str, Enum):
vga = "vga"
cirrus = "cirrus"
virtio = "virtio"
type:typeEnum = attr()
vram:int = attr(default=16384)
primary:YesNoEnum = attr(default=YesNoEnum.YES)
class Video(BaseXmlModel, search_mode='ordered'):
model:VideoModel = element()
class Watchdog(BaseXmlModel, search_mode='ordered'):
class modelEnum(str, Enum):
itco = "itco"
class actionEnum(str, Enum):
reset = "reset"
shutdown = "shutdown"
poweroff = "poweroff"
pause = "pause"
none = "none"
dump = "dump"
inject_nmi = "inject-nmi"
model:modelEnum = attr(default=modelEnum.itco)
action:actionEnum = attr(default=actionEnum.reset)
class TPMBackendEncryption(BaseXmlModel):
secret:UUID4 = attr()
class TPMBackend(BaseXmlModel, search_mode='ordered'):
class typeEnum(str, Enum):
emulator = "emulator"
class versionEnum(str, Enum):
v12 = "1.2"
v20 = "2.0"
type:typeEnum = attr(default=typeEnum.emulator)
version:versionEnum = attr(default=versionEnum.v20)
encryption:Optional[TPMBackendEncryption] = element(default=None)
class TPM(BaseXmlModel, search_mode='ordered'):
class modelEnum(str, Enum):
tpm_tis = "tpm-tis"
tpm_crb = "tpm-crb"
model:modelEnum = attr(default=modelEnum.tpm_tis)
backend:TPMBackend = element(default=TPMBackend())
class Devices(BaseXmlModel, search_mode='ordered'):
emulator:str = element(default="/usr/libexec/qemu-kvm")
disk:Optional[List[DevicesDisk]] = element(default=[])
interface:Optional[List[DevicesInterface]] = element(default=[])
channel:Optional[DevicesChannel] = element(default=None)
graphics:Optional[Graphics] = element(default=None)
audio:Optional[Audio] = element(default=None)
video:Optional[Video] = element(default=None)
watchdog:Optional[Watchdog] = element(default=None)
tpm:Optional[TPM] = element(default=None)
class VM(BaseXmlModel, tag='domain', search_mode='ordered'):
class on_poweroffEnum(str, Enum):
destroy = "destroy"
restart = "restart"
preserve = "preverse"
class on_rebootEnum(str, Enum):
restart = "restart"
preserve = "preverse"
class on_crashEnum(str, Enum):
destroy = "destroy"
restart = "restart"
preserve = "preverse"
class on_failurelockEnum(str, Enum):
poweroff = "poweroff"
restart = "restart"
pause = "pause"
ignore = "ignore"
# General metadata
uuid:Optional[UUID4] = element(default=None)
genid:Optional[UUID4] = element(default=None)
title:Optional[str] = element(default=None)
description:Optional[str] = element(default=None)
metadata:Optional[Metadata] = element(default=None)
# Memory Allocation
maxMemory:Optional[MaxMemory] = element(default=None)
memory:Memory = element()
currentMemory:Optional[CurrentMemory] = element(default=None)
memoryBacking:Optional[MemoryBacking] = element(default=None)
memtune:Optional[MemTune] = element(default=None)
numatune:Optional[NumaTune] = element(default=None)
# CPU Allocation
vcpu:VCPU = element()
vcpus:Optional[List[VCPUS]] = element(default=None)
cputune:Optional[CPUTune] = element(default=None)
# Resource patitioning
resource:Optional[Resource] = element(default=None)
# BIOS BootLoader
os:OS = element(default=OS())
# SMBIOS System Information
sysinfo:Sysinfo = element(default=Sysinfo())
# CPU model and topology
cpu:CPU = element(default=CPU())
# Power Management
pm:PM = element(default=None)
# Hypervisor features
features:Features = element(default=Features())
# Time keeping
clock:Clock = element(default=Clock())
# Events configuration
on_poweroff:on_poweroffEnum = element(default=on_poweroffEnum.destroy)
on_reboot:on_rebootEnum = element(default=on_rebootEnum.restart)
on_crash:on_crashEnum = element(default=on_crashEnum.restart)
on_failurelock:on_failurelockEnum = element(default=on_failurelockEnum.ignore)
# Performance monitoring events
perf:Perf = element(default=None)
# Devices
devices:Devices = element(default=Devices())

15
libvirt/enum.py Normal file
View File

@ -0,0 +1,15 @@
from enum import Enum
class YesNoEnum(str, Enum):
YES = "yes"
NO = "no"
class OnOffEnum(str, Enum):
ON = "on"
OFF = "off"
class UnitEnum(str, Enum):
KiB = "KiB"
MiB = "MiB"
GiB = "GiB"
TiB = "TiB"