Skip to content

Commit

Permalink
Add Device Role to Virtual Machines when creating it. (QEMU or LXC)
Browse files Browse the repository at this point in the history
  • Loading branch information
emersonfelipesp committed Jul 24, 2024
1 parent db99672 commit 1e9cb41
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netbox_proxbox/backend/routes/netbox/dcim/device_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DeviceRole(NetboxBase):

default_name = "Proxmox Node (Server)"
default_slug = "proxbox-node"
default_description = "Proxbox Basic Manufacturer"
default_description = "Proxbox Basic Device Role"

app = "dcim"
endpoint = "device_roles"
Expand Down
31 changes: 31 additions & 0 deletions netbox_proxbox/backend/routes/proxbox/clusters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,36 @@ class VirtualMachineStatus(Enum):

cluster = clusters[px.name]



role = await DeviceRole(nb = nb).get(slug = vm.get("type"))
if role == None:

vm_type = vm.get("type")

vm_name = None

color = "000000"

if vm_type == "qemu":
vm_name = "Virtual Machine (QEMU)"
color = "00ffff"
description = "Proxmox Virtual Machine"

if vm_type == "lxc":
vm_name = "Container (LXC)"
color = "7fffd4"
description = "Proxmox Container"

role = await DeviceRole(nb = nb).post(data = {
"name": vm_name,
"slug": vm_type,
"vm_role": True,
"color": color,
"description": description
})


created_virtual_machines.append(
await VirtualMachine(nb = nb).post(data = {
"name": vm.get("name"),
Expand All @@ -200,6 +230,7 @@ class VirtualMachineStatus(Enum):
"vcpus": int(vm.get("maxcpu", 0)),
"memory": int(int(vm.get("maxmem", 0)) / 1000000),
"disk": int(int(vm.get("maxdisk", 0)) / 1000000000),
"role": role.id
})
)

Expand Down

0 comments on commit 1e9cb41

Please sign in to comment.