Skip to content
Snippets Groups Projects
Commit 854d033a authored by mvrp21's avatar mvrp21
Browse files

fix: interface update


Signed-off-by: default avatarmvrp21 <mvrp21@inf.ufpr.br>
parent 22224740
Branches
No related tags found
No related merge requests found
...@@ -122,7 +122,7 @@ def update_old_interfaces(proxmox_interfaces, netbox_interfaces): ...@@ -122,7 +122,7 @@ def update_old_interfaces(proxmox_interfaces, netbox_interfaces):
for ni in netbox_interfaces: for ni in netbox_interfaces:
updated_interface = False updated_interface = False
# same VM, same interface name, see if it's necessary to update # same VM, same interface name, see if it's necessary to update
if ni.virtual_machine.name == pi['virtual_machine']['name']: if ni.virtual_machine['name'] == pi['virtual_machine']['name']:
if ni.name == pi['name']: if ni.name == pi['name']:
found = True found = True
updated_interface = ni.untagged_vlan.vid != pi['untagged_vlan']['vid'] or \ updated_interface = ni.untagged_vlan.vid != pi['untagged_vlan']['vid'] or \
...@@ -130,7 +130,12 @@ def update_old_interfaces(proxmox_interfaces, netbox_interfaces): ...@@ -130,7 +130,12 @@ def update_old_interfaces(proxmox_interfaces, netbox_interfaces):
ni.mac_address = pi['mac_address'].upper() ni.mac_address = pi['mac_address'].upper()
ni.untagged_vlan = pi['untagged_vlan'] ni.untagged_vlan = pi['untagged_vlan']
if updated_interface: if updated_interface:
updated.append(dict(ni)) ui = dict(ni)
# Virtual machine won't change, nor mode
del ui['virtual_machine']
del ui['mode']
# better to be a dict here
updated.append(ui)
break break
# if not found: create # if not found: create
if not found: if not found:
...@@ -139,7 +144,7 @@ def update_old_interfaces(proxmox_interfaces, netbox_interfaces): ...@@ -139,7 +144,7 @@ def update_old_interfaces(proxmox_interfaces, netbox_interfaces):
found = False found = False
# if not found in proxmox: delete (seem simple?) # if not found in proxmox: delete (seem simple?)
for pi in proxmox_interfaces: for pi in proxmox_interfaces:
if ni.virtual_machine.name == pi['virtual_machine']['name']: if ni.virtual_machine['name'] == pi['virtual_machine']['name']:
if ni.name == pi['name']: if ni.name == pi['name']:
found = True found = True
break break
...@@ -164,6 +169,8 @@ def update_virtual_machines(cluster_id, proxmox_vms, proxmox_interfaces): ...@@ -164,6 +169,8 @@ def update_virtual_machines(cluster_id, proxmox_vms, proxmox_interfaces):
to_create = [vm for vm in proxmox_vms if vm['name'] not in old_vms] to_create = [vm for vm in proxmox_vms if vm['name'] not in old_vms]
updated = update_old_vms(old_vms, new_vms) updated = update_old_vms(old_vms, new_vms)
for interface in netbox_interfaces:
interface.virtual_machine = {'name': interface.virtual_machine['name']}
to_create_i, updated_i, deleted_i = update_old_interfaces( to_create_i, updated_i, deleted_i = update_old_interfaces(
proxmox_interfaces, netbox_interfaces proxmox_interfaces, netbox_interfaces
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment