From c63fe1f517a49fd94d3e39e5cc9dcc43a505a5db Mon Sep 17 00:00:00 2001 From: Mickael B Date: Wed, 9 Oct 2024 12:28:01 +0200 Subject: [PATCH] update --- api/cluster.py | 12 +++++++++ api/datacenter.py | 29 ++++++++++++++++++++ api/network.py | 27 +++++++++++++++++++ api/storage.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 api/cluster.py create mode 100644 api/datacenter.py create mode 100644 api/network.py create mode 100644 api/storage.py diff --git a/api/cluster.py b/api/cluster.py new file mode 100644 index 0000000..2f68b1e --- /dev/null +++ b/api/cluster.py @@ -0,0 +1,12 @@ +from typing import List, Optional +import uuid +from pydantic import UUID4, BaseModel, ConfigDict, Field + +class Cluster(BaseModel): + model_config = ConfigDict(from_attributes=True) + + id: UUID4 + name: str + compute_id: UUID4 + storage_id: UUID4 + network_switch_id: UUID4 \ No newline at end of file diff --git a/api/datacenter.py b/api/datacenter.py new file mode 100644 index 0000000..e453142 --- /dev/null +++ b/api/datacenter.py @@ -0,0 +1,29 @@ +from typing import List, Optional +import uuid +from pydantic import UUID4, BaseModel, ConfigDict, Field + +class VM(BaseModel): + model_config = ConfigDict(from_attributes=True) + + id:UUID4 + name:str + state:str + +class Datacenter(BaseModel): + model_config = ConfigDict(from_attributes=True) + + company_id:UUID4 + id:UUID4 + name:str + cluster_id:UUID4 + storage_pool_id:UUID4 + vm:List[VM] = Field(default=[]) + +class DatacenterCreate(BaseModel): + model_config = ConfigDict(from_attributes=True) + + company_id:UUID4 + id:Optional[UUID4] = Field(default_factory=lambda:uuid.uuid4()) + name:str + cluster_id:UUID4 + storage_pool_id:UUID4 \ No newline at end of file diff --git a/api/network.py b/api/network.py new file mode 100644 index 0000000..e21f0e4 --- /dev/null +++ b/api/network.py @@ -0,0 +1,27 @@ +from ipaddress import IPv4Address, IPv6Address +from typing import List, Optional +from pydantic_xml import element, attr +from pydantic import UUID4, BaseModel, ConfigDict, Field +from pydantic_extra_types.mac_address import MacAddress + +from deevirt_common.lib.virt import vm as vmVirt + +class lsp(BaseModel): + model_config = ConfigDict(from_attributes=True) + + id:UUID4 = Field() + mac_addr:str = Field() + ipv4_addr:Optional[IPv4Address] = Field(default=None) + ipv6_addr:Optional[IPv6Address] = Field(default=None) + +class ls(BaseModel): + model_config = ConfigDict(from_attributes=True) + + id:UUID4 = Field() + name:str = Field() + network_switch_port:Optional[List[lsp]] = Field(default=[]) + +class lspCreate(BaseModel): + switch_id:UUID4 = Field(default=None) + id:Optional[UUID4] + mac_addr:Optional[str] = Field() \ No newline at end of file diff --git a/api/storage.py b/api/storage.py new file mode 100644 index 0000000..edcff58 --- /dev/null +++ b/api/storage.py @@ -0,0 +1,69 @@ +from typing import List +from pydantic_xml import element, attr +from pydantic import UUID4, BaseModel, ConfigDict, Field + +from deevirt_common.lib.virt import vm as vmVirt + +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() + +class DiskDriver(vmVirt.DiskDriver): + name:str = Field(default="qemu") + type:vmVirt.DiskDriver.enumType = Field(default=vmVirt.DiskDriver.enumType.raw) + +class DiskAuthSecret(vmVirt.DiskAuthSecret): + type:vmVirt.DiskAuthSecret.enumType = Field(default=vmVirt.DiskAuthSecret.enumType.ceph) + +class DiskAuth(vmVirt.DiskAuth): + secret:DiskAuthSecret = Field(default=DiskAuthSecret()) + +class DiskSourceHost(vmVirt.DiskSourceHost): + port:int = Field(default=6689) + +class DiskSource(vmVirt.DiskSource): + protocol:vmVirt.DiskSource.enumProtocol = Field(default=vmVirt.DiskSource.enumProtocol.rbd) + +class DiskTarget(vmVirt.DiskTarget): + bus:str = Field(default="virtio") + +class Disk(vmVirt.Disk): + type:vmVirt.Disk.enumType = Field(default=vmVirt.Disk.enumType.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() +