Skip to content

Commit

Permalink
Merge pull request #16 from netboxlabs/feature-scsi0-add
Browse files Browse the repository at this point in the history
adds scsi0 to NetBox after Proxmox VM create
  • Loading branch information
netboxlabs-nvp authored Dec 1, 2024
2 parents 5c5296f + 55f0924 commit b047489
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions example-netbox-webhook-flask-app/helpers/netbox_proxmox.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import pynetbox
import requests
import urllib
Expand Down Expand Up @@ -180,6 +181,37 @@ def proxmox_clone_vm(self, json_in):
nb_obj_update_vmid.save()
except pynetbox.core.query.RequestError as e:
raise e

# set scsi0 in NetBox
try:
proxmox_vm_config = self.proxmox_api.nodes(self.proxmox_api_config['node']).qemu(new_vm_id).config.get()

if 'bootdisk' in proxmox_vm_config:
os_disk = proxmox_vm_config['bootdisk']

if os_disk in proxmox_vm_config:
m = re.search(r'size=(\d+)([MG]){1}', proxmox_vm_config[os_disk])

if m:
disk_raw_size = m.group(1)

if m.group(2) == 'G':
disk_size = int(disk_raw_size) * 1000
elif m.group(2) == 'M':
disk_size = int(disk_raw_size)

nb_obj_add_vm_disk = self.netbox_api.virtualization.virtual_disks.create(
virtual_machine=nb_obj_update_vmid['id'],
name=proxmox_vm_config['bootdisk'],
size=disk_size,
description=f"OS/boot disk for {json_in['data']['name']}"
)

if not nb_obj_add_vm_disk:
raise ValueError("Unable to add VM disk to NetBox")

except pynetbox.core.query.RequestError as e:
raise e

# update VM vcpus and memory if defined
if json_in['data']['vcpus']:
Expand Down

0 comments on commit b047489

Please sign in to comment.