2024-10-15 15:46:23 +02:00
|
|
|
from typing import List, Optional
|
2024-10-09 12:28:01 +02:00
|
|
|
from pydantic import UUID4, BaseModel, ConfigDict, Field
|
2024-10-15 13:54:41 +02:00
|
|
|
from pydantic_xml import attr
|
2024-10-09 12:28:01 +02:00
|
|
|
|
2024-10-15 13:54:41 +02:00
|
|
|
from ..libvirt.dom import config as configDom
|
2024-10-09 12:28:01 +02:00
|
|
|
|
|
|
|
class VMHardDisk(BaseModel):
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
|
|
vm_id:UUID4
|
|
|
|
storage_block:UUID4 = Field(alias="storage_block_rbd_id")
|
2024-10-15 15:46:23 +02:00
|
|
|
|
|
|
|
class StorageBlock(BaseModel):
|
2024-10-09 12:28:01 +02:00
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
|
|
id:UUID4 = Field()
|
|
|
|
name:str = Field()
|
2024-10-15 15:46:23 +02:00
|
|
|
size:int = Field()
|
2024-10-18 10:47:54 +02:00
|
|
|
vm_hard_disk:Optional[List[VMHardDisk]] = Field(default=[])
|
2024-10-15 15:46:23 +02:00
|
|
|
|
2024-10-09 12:28:01 +02:00
|
|
|
class StoragePool(BaseModel):
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
|
|
id:UUID4 = Field()
|
|
|
|
name:str = Field()
|
2024-10-18 10:47:54 +02:00
|
|
|
block:Optional[List[StorageBlock]] = Field(default=[], alias='storage_block_rbd')
|
2024-10-09 12:28:01 +02:00
|
|
|
|
2024-10-15 15:46:23 +02:00
|
|
|
class Storage(BaseModel):
|
2024-10-09 12:28:01 +02:00
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
|
|
id:UUID4 = Field()
|
|
|
|
name:str = Field()
|
2024-10-18 10:47:54 +02:00
|
|
|
pool: Optional[List[StoragePool]] = Field(default=[], alias='storage_pool')
|
2024-10-09 12:28:01 +02:00
|
|
|
|
2024-10-09 12:47:06 +02:00
|
|
|
class DiskDriver(configDom.DevicesDiskDriver):
|
2024-10-09 12:28:01 +02:00
|
|
|
name:str = Field(default="qemu")
|
2024-10-15 13:54:41 +02:00
|
|
|
type:configDom.DevicesDiskDriver.typeEnum = Field(default=configDom.DevicesDiskDriver.typeEnum.raw)
|
2024-10-09 12:28:01 +02:00
|
|
|
|
2024-10-09 12:47:06 +02:00
|
|
|
class DiskAuthSecret(configDom.DevicesDiskAuthSecret):
|
2024-10-15 13:54:41 +02:00
|
|
|
type:configDom.DevicesDiskAuthSecret.typeEnum = Field(default=configDom.DevicesDiskAuthSecret.typeEnum.ceph)
|
2024-10-09 12:28:01 +02:00
|
|
|
|
2024-10-09 12:47:06 +02:00
|
|
|
class DiskAuth(configDom.DevicesDiskAuth):
|
2024-10-09 12:28:01 +02:00
|
|
|
secret:DiskAuthSecret = Field(default=DiskAuthSecret())
|
|
|
|
|
2024-10-09 12:47:06 +02:00
|
|
|
class DiskSourceHost(configDom.DevicesDiskSourceHost):
|
2024-10-09 12:28:01 +02:00
|
|
|
port:int = Field(default=6689)
|
|
|
|
|
2024-10-09 12:47:06 +02:00
|
|
|
class DiskSource(configDom.DevicesDiskSource):
|
2024-10-15 13:54:41 +02:00
|
|
|
name:str = Field(default="source")
|
|
|
|
protocol:configDom.DevicesDiskSource.protocolEnum = Field(default=configDom.DevicesDiskSource.protocolEnum.rbd)
|
2024-10-09 12:28:01 +02:00
|
|
|
|
2024-10-09 12:47:06 +02:00
|
|
|
class DiskTarget(configDom.DevicesDiskTarget):
|
2024-10-15 13:54:41 +02:00
|
|
|
dev:str = Field(default="dev")
|
2024-10-09 12:28:01 +02:00
|
|
|
bus:str = Field(default="virtio")
|
|
|
|
|
2024-10-09 12:47:06 +02:00
|
|
|
class Disk(configDom.DevicesDisk):
|
2024-10-15 13:54:41 +02:00
|
|
|
type:configDom.DevicesDisk.typeEnum = Field(default=configDom.DevicesDisk.typeEnum.network)
|
2024-10-09 12:28:01 +02:00
|
|
|
device:str = Field(default="disk")
|
|
|
|
driver:DiskDriver = Field(default=DiskDriver())
|
|
|
|
source:DiskSource = Field(default=DiskSource())
|
|
|
|
target:DiskTarget = Field(default=DiskTarget())
|
|
|
|
size:int = Field(default=0)
|
|
|
|
|
|
|
|
class DiskCreate(Disk):
|
|
|
|
size:int = Field()
|
|
|
|
order:int = Field(default=0, json_schema_extra={"hidden": True})
|
|
|
|
|
|
|
|
class DiskAttached(BaseModel):
|
|
|
|
order:int = Field()
|
|
|
|
|
|
|
|
class BlockCreate(BaseModel):
|
|
|
|
size:int = Field()
|
|
|
|
|