deevirt_schema/api/storage.py

74 lines
2.4 KiB
Python

from typing import List, Optional
from pydantic import UUID4, BaseModel, ConfigDict, Field
from pydantic_xml import attr
from ..libvirt.dom import config as configDom
class VMHardDisk(BaseModel):
model_config = ConfigDict(from_attributes=True)
vm_id:UUID4
storage_block:UUID4 = Field(alias="storage_block_rbd_id")
class StorageBlock(BaseModel):
model_config = ConfigDict(from_attributes=True)
id:UUID4 = Field()
name:str = Field()
size:int = Field()
vm_hard_disk:List[VMHardDisk] = Field()
class StoragePool(BaseModel):
model_config = ConfigDict(from_attributes=True)
id:UUID4 = Field()
name:str = Field()
block:Optional[List[StorageBlock]] = Field(default=[], alias='block')
class Storage(BaseModel):
model_config = ConfigDict(from_attributes=True)
id:UUID4 = Field()
name:str = Field()
pool: Optional[List[StoragePool]] = Field(default=[], alias='pool')
class DiskDriver(configDom.DevicesDiskDriver):
name:str = Field(default="qemu")
type:configDom.DevicesDiskDriver.typeEnum = Field(default=configDom.DevicesDiskDriver.typeEnum.raw)
class DiskAuthSecret(configDom.DevicesDiskAuthSecret):
type:configDom.DevicesDiskAuthSecret.typeEnum = Field(default=configDom.DevicesDiskAuthSecret.typeEnum.ceph)
class DiskAuth(configDom.DevicesDiskAuth):
secret:DiskAuthSecret = Field(default=DiskAuthSecret())
class DiskSourceHost(configDom.DevicesDiskSourceHost):
port:int = Field(default=6689)
class DiskSource(configDom.DevicesDiskSource):
name:str = Field(default="source")
protocol:configDom.DevicesDiskSource.protocolEnum = Field(default=configDom.DevicesDiskSource.protocolEnum.rbd)
class DiskTarget(configDom.DevicesDiskTarget):
dev:str = Field(default="dev")
bus:str = Field(default="virtio")
class Disk(configDom.DevicesDisk):
type:configDom.DevicesDisk.typeEnum = Field(default=configDom.DevicesDisk.typeEnum.network)
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()