deevirt_schema/api/storage.py

72 lines
2.2 KiB
Python
Raw Normal View History

2024-10-09 12:28:01 +02:00
from typing import List
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")
class Storage(BaseModel):
model_config = ConfigDict(from_attributes=True)
id:UUID4 = Field()
name:str = Field()
class StoragePool(BaseModel):
model_config = ConfigDict(from_attributes=True)
id:UUID4 = Field()
name:str = Field()
class StorageBlock(BaseModel):
model_config = ConfigDict(from_attributes=True)
id:UUID4 = Field()
name:str = Field()
size:int = Field()
vm_hard_disk:List[VMHardDisk] = Field()
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()