Skip to content

Commit

Permalink
Add 'Start at Boot' custom field and group Proxmox CF's together
Browse files Browse the repository at this point in the history
  • Loading branch information
emersonfelipesp committed Jul 29, 2024
1 parent cdad0a5 commit 12d4635
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions netbox_proxbox/backend/routes/proxbox/clusters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,53 @@ class VirtualMachineStatus(Enum):
"description": description
})

try:
custom_field_id = nb.session.extras.custom_fields.get(name="proxmox_vm_id")
except:

custom_field_id = nb.session.extras.custom_fields.get(name="proxmox_vm_id")

if not custom_field_id:
custom_field_id = nb.session.extras.custom_fields.create(
{
"object_types": [
"virtualization.virtualmachine"
],
"type": "integer",
"name": "proxmox_vm_id",
"label": "Proxmox VM ID",
"label": "VM ID",
"description": "Proxmox Virtual Machine or Container ID",
"ui_visible": "always",
"ui_editable": "hidden",
"weight": 100,
"filter_logic": "loose",
"search_weight": 1000,
"group_name": "Proxmox"
}
)
print(f'custom_field_id: {custom_field_id}')
#print(f'custom_field_id: {custom_field_id}')



start_at_boot_field = nb.session.extras.custom_fields.get(name="proxmox_start_at_boot")

if not start_at_boot_field:
start_at_boot_field = nb.session.extras.custom_fields.create(
{
"object_types": [
"virtualization.virtualmachine"
],
"type": "boolean",
"name": "proxmox_start_at_boot",
"label": "Start at Boot",
"description": "Proxmox Start at Boot Option",
"ui_visible": "always",
"ui_editable": "hidden",
"weight": 100,
"filter_logic": "loose",
"search_weight": 1000,
"group_name": "Proxmox"
}
)

print(f"start_at_boot_field: {start_at_boot_field}")

platform = None

Expand All @@ -258,10 +284,18 @@ class VirtualMachineStatus(Enum):
slug = platform_slug
).id


if vm.get("type") == 'qemu': vm_config = px.session.nodes(vm.get("node")).qemu(vm.get("vmid")).config.get()


start_at_boot = False

if vm.get("type") == 'qemu':
vm_config = px.session.nodes(vm.get("node")).qemu(vm.get("vmid")).config.get()

onboot = int(vm_config.get("onboot", 0))

if onboot == 1:
start_at_boot = True


print(f"vm_config: {vm_config}")

print(f"\nplatform: {platform}\n")
Expand All @@ -277,7 +311,8 @@ class VirtualMachineStatus(Enum):
"disk": int(int(vm.get("maxdisk", 0)) / 1000000000),
"role": role.id,
"custom_fields": {
"proxmox_vm_id": vm.get("vmid")
"proxmox_vm_id": vm.get("vmid"),
"proxmox_start_at_boot": start_at_boot,
},
"platform": platform
}
Expand Down

0 comments on commit 12d4635

Please sign in to comment.