Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues after migrating from old vcenter-netbox-sync: 'dict' object has no attribute 'get_display_name' #45

Closed
mfyll opened this issue Feb 17, 2021 · 11 comments
Labels
awaiting reply Awaiting reply from issue owner bug Something isn't working
Milestone

Comments

@mfyll
Copy link

mfyll commented Feb 17, 2021

Hello,

Attempting to migrate from synackray/vcenter-netbox-sync to this version, while also upgrading from the last working version with synackray's version (2.8.9) to 2.10.4, I have encountered some issues and would like some guidance. I have followed the upgrade procedure as documented in the netbox repository, and netbox works perfectly on the new version.

The database is already populated with a few hundred virtual machines, ip-adresses, VLANs etc. and I was hoping that since this project is based on synackray's version they would somehow (almost) work.

The error I am getting when running the sync with this new sync tool is (VM names and IP-adresses has been changed):

2021-02-17 10:58:39,398 - ERROR: Unable to determine second key 'virtual_machine' for virtual machine interface 'vm01', got: None
2021-02-17 10:58:39,398 - ERROR: This could cause serious errors and lead to wrongly assigned object relations!!!
2021-02-17 10:58:39,398 - WARNING: Current interface 'vNIC0 (vm01 (None))' for IP '192.168.0.100/27' and this one 'vNIC 1 (vm02) (vm02)' are both enabled. IP assignment skipped because it is unclear which one is the correct one!
Traceback (most recent call last):
  File "netbox-sync.py", line 143, in <module>
    main()
  File "netbox-sync.py", line 119, in main
    source.apply()
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 372, in apply
    view_details.get("view_handler")(obj)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 2170, in add_virtual_machine
    nic_ips=nic_ips, p_ipv4=vm_primary_ip4, p_ipv6=vm_primary_ip6)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 958, in add_device_vm_to_inventory
    device_vm_object = self.get_object_based_on_macs(object_type, nic_macs)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 512, in get_object_based_on_macs
    matching_object.get_display_name(including_second_key=True)))
AttributeError: 'dict' object has no attribute 'get_display_name' 

I am guessing that there are something in the old database that the new tool does not like, but this crashes and is not handled (the script stops completely).

Any suggestions would be appriciated, thank you.

@mfyll mfyll changed the title 'dict' object has no attribute 'get_display_name' Issues after migrating from old vcenter-netbox-sync: 'dict' object has no attribute 'get_display_name' Feb 17, 2021
@bb-Ricardo
Copy link
Owner

Oh, thisnis not meant to happen. I will check tomorrow what the issue is here.

@bb-Ricardo
Copy link
Owner

It looks like some relations could net be resolved.

I added another check which hopefully fixes the issue.

can you try it again?

@bb-Ricardo bb-Ricardo added awaiting reply Awaiting reply from issue owner bug Something isn't working labels Feb 27, 2021
@mfyll
Copy link
Author

mfyll commented Mar 1, 2021

Hello,

Seems like it is still an issue.

  File "netbox-sync.py", line 143, in <module>
    main()
  File "netbox-sync.py", line 119, in main
    source.apply()
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 372, in apply
    view_details.get("view_handler")(obj)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 2170, in add_virtual_machine
    nic_ips=nic_ips, p_ipv4=vm_primary_ip4, p_ipv6=vm_primary_ip6)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 958, in add_device_vm_to_inventory
    device_vm_object = self.get_object_based_on_macs(object_type, nic_macs)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 512, in get_object_based_on_macs
    matching_object.get_display_name(including_second_key=True)))
AttributeError: 'dict' object has no attribute 'get_display_name'

Updated:

mfyll@marius-test:/opt/netbox-sync$ git pull
Already up to date.

@bb-Ricardo
Copy link
Owner

Sorry, you need to switch to the development branch.

@mfyll
Copy link
Author

mfyll commented Mar 2, 2021

Yeah, the dev branch fixed this issue. The script does now add new objects to Netbox, but creates quite a few duplicates and has a livid fanstasy creating objects that does not exist in vCenter and connects IP-adresses to servers to the completely wrong servers.

Also, when running the script a second time (after it worked once), I got this error:

Traceback (most recent call last):
  File "netbox-sync.py", line 143, in <module>
    main()
  File "netbox-sync.py", line 119, in main
    source.apply()
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 379, in apply
    view_details.get("view_handler")(obj)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 2196, in add_virtual_machine
    nic_ips=nic_ips, p_ipv4=vm_primary_ip4, p_ipv6=vm_primary_ip6)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 965, in add_device_vm_to_inventory
    device_vm_object = self.get_object_based_on_macs(object_type, nic_macs)
  File "/opt/netbox-sync/module/sources/vmware/connection.py", line 532, in get_object_based_on_macs
    (object_type.name, matching_object.get_display_name(including_second_key=True)))
AttributeError: 'dict' object has no attribute 'get_display_name'

@bb-Ricardo
Copy link
Owner

Hi,

yes this is the same issue in a different spot.

I'm wondering if this the only ERROR you get. When you start the sync, do you get any other WARNING or ERROR messages? Maybe check the log if activated.

@mfyll
Copy link
Author

mfyll commented Mar 4, 2021

Hi again,

I can see that if I scroll a bit up there are a few other errors:

2021-03-02 07:36:44,053 - ERROR: This could cause serious errors and lead to wrongly assigned object relations!!!
2021-03-02 07:36:44,054 - WARNING: Current interface 'vNIC0 (server1 (None))' for IP '10.x.x.x/27' and this one 'vNIC 1 (vLAN) (server2)' are both enabled. IP assignment skipped because it is unclear which one is the correct one!

This one repeats a lot:

2021-03-02 07:36:43,887 - INFO: Virtual machine interface 'vNIC 1 (vlan1) (server3)' attribute 'untagged_vlan' changed from 'xxxx (vlan3)' to 'xxxx (vlan4)'
2021-03-02 07:36:43,891 - WARNING: Current interface 'vNIC 1 (vlan2) (server4)' for IP '192.168.x.x/24' and this one 'vNIC 1 (vlan1) (server3)' are both enabled. IP assignment skipped because it is unclear which one is the correct one!

This one is repeated 10-30 times in a row:

2021-03-02 07:36:34,810 - ERROR: Unable to determine second key 'device' for interface 'server5', got: None
2021-03-02 07:36:34,810 - ERROR: This could cause serious errors and lead to wrongly assigned object relations!!!
2021-03-02 07:36:34,810 - ERROR: Problems resolving relation 'device' for object 'eth0 (server5 (None))' and value '{'id': 22, 'url': 'http://netbox/api/dcim/devices/22/', 'name': 'server5', 'display_name': 'server5'}'

The first error when running the script seems to be:

2021-03-02 07:36:34,769 - ERROR: Problems resolving relation 'vlan' for object '10.x.x.x/24' and value '{'id': 28, 'url': 'http://netbox/api/ipam/vlans/28/', 'vid': xx, 'name': 'vlanx', 'display_name': 'vlanx (xx)'}'

I have modified the error messages somewhat to remove server-names and IP-addresses.

@bb-Ricardo
Copy link
Owner

I believe that your NetBox upgrade went wrong and some relations are not present anymore.

Nevertheless, the code should be able to handle this. I will fix this issue.

bb-Ricardo added a commit that referenced this issue Apr 1, 2021
@bb-Ricardo
Copy link
Owner

closing due to no response

@mfyll
Copy link
Author

mfyll commented May 27, 2021

@bb-Ricardo Sorry, I have been unable to look at this for a while. I can however confirm that your fix has been successful. After some testing today, everything looks great. Thank you!

@bb-Ricardo
Copy link
Owner

Thank you for the feedback. Great to hear.

Sometimes people don't get back at all, that's why I close tickets I consider fixed after a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reply Awaiting reply from issue owner bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants