From 9b9617540c4edf92f1a1babe8689593d84d36173 Mon Sep 17 00:00:00 2001 From: Mickael B Date: Wed, 9 Oct 2024 12:35:38 +0200 Subject: [PATCH] update --- api/vm.py | 57 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 47 deletions(-) diff --git a/api/vm.py b/api/vm.py index 5f5c746..6e2a1cd 100644 --- a/api/vm.py +++ b/api/vm.py @@ -1,17 +1,7 @@ -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 typing import List, Optional +from uuid import uuid4 +from pydantic import UUID4, Field, ConfigDict from pydantic import BaseModel as _BaseModel -from pydantic_core import core_schema as cs - - -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, configDom from deevirt_schema.libvirt.dom import config as configDom @@ -25,8 +15,7 @@ class BaseModel(_BaseModel): props[k] = v schema["properties"] = props - -""" Common """ +"""Common""" class Resource(BaseModel): """Experimental""" name:Optional[str] = Field(default=None, description="Nom du pool") @@ -67,30 +56,10 @@ class Clock(BaseModel): offset:configDom.Clock.offsetEnum = Field(default=configDom.Clock.offsetEnum.utc, description="Sélection de l'offset ?") class Event(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:configDom.Dom.on_poweroffEnum = Field(default=configDom.Dom.on_poweroffEnum.destroy, description="Action lors d'un poweroff") on_reboot:configDom.Dom.on_rebootEnum = Field(default=configDom.Dom.on_rebootEnum.restart, description="Action lors d'un redémarrage") on_crash:configDom.Dom.on_crashEnum = Field(default=configDom.Dom.on_crashEnum.restart, description="Action lors d'un crash de la VM") - on_failurelock:configDom.Dom.on_failurelockEnum = element(default=configDom.Dom.on_failurelockEnum.ignore, description="A tester") + on_failurelock:configDom.Dom.on_failurelockEnum = Field(default=configDom.Dom.on_failurelockEnum.ignore, description="A tester") class DevicesDisk(BaseModel): model_config = ConfigDict(from_attributes=True) @@ -102,20 +71,14 @@ class DevicesDisk(BaseModel): bus:configDom.DevicesDiskTarget.busEnum = Field(default=configDom.DevicesDiskTarget.busEnum.scsi) class DevicesCDROMSource(BaseModel): - class protocolEnum(str, Enum): - http = "http" - https = "https" - ftp = "ftp" - ftps = "ftps" - - protocol:protocolEnum = attr(default=protocolEnum.https) - name:str = attr() + protocol:configDom.DevicesDiskSource.protocolEnum = Field(default=configDom.DevicesDiskSource.protocolEnum.https) + name:str = Field() class DevicesCDROM(BaseModel): model_config = ConfigDict(from_attributes=True) device:configDom.DevicesDisk.deviceEnum = Field(default=configDom.DevicesDisk.deviceEnum.cdrom, json_schema_extra={"hidden": True}) - source:DevicesCDROMSource = element(default=None) + source:DevicesCDROMSource = Field(default=None) class DevicesInterfaceGuest(BaseModel): model_config = ConfigDict(from_attributes=True) @@ -146,14 +109,14 @@ class VideoModel(BaseModel): primary:configDom.YesNoEnum = Field(default=configDom.YesNoEnum.YES) class Video(BaseModel): - model:VideoModel = element() + model:VideoModel = Field() class Watchdog(BaseModel): model:configDom.Watchdog.modelEnum = Field(default=configDom.Watchdog.modelEnum.itco) action:configDom.Watchdog.actionEnum = Field(default=configDom.Watchdog.actionEnum.reset) class TPM(BaseModel): - model:configDom.TPM.modelEnum = attr(default=configDom.TPM.modelEnum.tpm_tis) + model:configDom.TPM.modelEnum = Field(default=configDom.TPM.modelEnum.tpm_tis) version:configDom.TPMBackend.versionEnum = Field(default=configDom.TPMBackend.versionEnum.v20) class Devices(BaseModel):