Skip to content

Commit

Permalink
Merge pull request #87 from Gskill75/develop
Browse files Browse the repository at this point in the history
Fix Virtual Machine ID selection and minor bug
  • Loading branch information
emersonfelipesp authored Mar 14, 2023
2 parents 531eea0 + be8085f commit 3686219
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions netbox_proxbox/proxbox_api/updates/virtual_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,23 +324,23 @@ def interfaces(netbox_vm, proxmox_vm):
_pmx_if.append({'name': ifname, 'mac_address': _mac_addr, 'mtu': _mtu})

for interface in nb.virtualization.interfaces.filter(virtual_machine_id=netbox_vm.id):
_ntb_if.append({'name': interface.name, 'mac_address': interface.mac_address.lower(), 'mtu': interface.mtu})
_ntb_if.append({'name': interface.name, 'mac_address': interface.mac_address, 'mtu': interface.mtu})

for pmx_if_mac in [_if['mac_address'] for _if in _pmx_if]:
pmx_if = next((_if for _if in _pmx_if if _if['mac_address'] == pmx_if_mac), None)
if pmx_if is not None:
if pmx_if_mac not in [_if['mac_address'] for _if in _ntb_if]:
try:
if nb.virtualization.interfaces.get(virtual_machine=netbox_vm.id, name=pmx_if['name']):
if nb.virtualization.interfaces.get(virtual_machine_id=netbox_vm.id, virtual_machine=netbox_vm.name, name=pmx_if['name']):
print("Interface already exist.")
else:
# Create interface if does not exist.
netbox_interface = nb.virtualization.interfaces.create(virtual_machine=netbox_vm.id, name=pmx_if['name'], mac_address=pmx_if_mac, mtu=pmx_if['mtu'])
netbox_interface = nb.virtualization.interfaces.create(virtual_machine_id=netbox_vm.id, virtual_machine=netbox_vm.id, name=pmx_if['name'], mac_address=pmx_if_mac, mtu=pmx_if['mtu'])
updated = True
except Exception as error: print(error)
else:
if pmx_if not in _ntb_if:
netbox_interface = list(nb.virtualization.interfaces.filter(virtual_machine_id=netbox_vm.id, mac_address=pmx_if_mac))
netbox_interface = list(nb.virtualization.interfaces.filter(virtual_machine_id=netbox_vm.id, virtual_machine=netbox_vm.id, mac_address=pmx_if_mac))
if len(netbox_interface) == 1:
netbox_interface = netbox_interface[0]
netbox_interface = nb.virtualization.interfaces.update([{'id': netbox_interface.id, 'name': pmx_if['name'], 'mac_address': pmx_if_mac, 'mtu': pmx_if['mtu']}])
Expand Down

0 comments on commit 3686219

Please sign in to comment.