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

Update for netbox ver 4 #387

Closed
Sivolen opened this issue May 7, 2024 · 17 comments
Closed

Update for netbox ver 4 #387

Sivolen opened this issue May 7, 2024 · 17 comments
Labels
bug Something isn't working

Comments

@Sivolen
Copy link

Sivolen commented May 7, 2024

Hi!

Tell me, will there be an update for netbox version 4?

@jhammond-git
Copy link

The largest issue seems to be the change from ContentType to ObjectType. We were able to get it working by replacing all instances of content_types in the files in module/ and subdirectories with object_types, and replacing line 1192 in module/netbox/object_classes.py with:
for content_type in data.get("object_types", []):

Whether or not that was all required or if it fixes all problems, I don't know yet, but that got it to run for us.

@bb-Ricardo
Copy link
Owner

Hey @jhammond-git,

Thank you for the hint. Currently implementing the support for 4.0, hope I can finish it before I have to leave for holidays.

bb-Ricardo added a commit that referenced this issue May 8, 2024
@bb-Ricardo
Copy link
Owner

bb-Ricardo commented May 8, 2024

Hi,

I just pushed a new commit to "development" would you be able to test and see if it's working with NetBox 3.7 and NetBox 4.0?

Thank you

@Sivolen
Copy link
Author

Sivolen commented May 8, 2024

Thank you, I can check on Monday

@jhammond-git
Copy link

Still need to change line 1192 as noted above:

for content_type in data.get("object_types", []):

@jhammond-git
Copy link

Traceback (most recent call last):
  File "/opt/netbox-sync/./netbox-sync.py", line 146, in <module>
    main()
  File "/opt/netbox-sync/./netbox-sync.py", line 98, in main
    nb_handler.query_current_data(source.dependent_netbox_objects)
  File "/opt/netbox-sync/module/netbox/connection.py", line 521, in query_current_data
    self.inventory.add_object(nb_object_class, data=object_data, read_from_netbox=True)
  File "/opt/netbox-sync/module/netbox/inventory.py", line 176, in add_object
    new_object = object_type(data, read_from_netbox=read_from_netbox, inventory=self, source=source)
  File "/opt/netbox-sync/module/netbox/object_classes.py", line 1178, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/netbox-sync/module/netbox/object_classes.py", line 296, in __init__
    self.update(data=data, read_from_netbox=read_from_netbox, source=source)
  File "/opt/netbox-sync/module/netbox/object_classes.py", line 1194, in update
    for object_type in data.get("object_types"):
TypeError: 'NoneType' object is not iterable

@yaiqsa
Copy link

yaiqsa commented May 8, 2024

Awesome that 4.0 compatibility is already on it's way! When I saw the changelogs I was exited and anxious at the same time. (Jay new UI with working Markdown hyperlinks & inline images, but SO many breaking changes).

I should be able to spin up a testing environment for this next week, and I'll keep my eyes on this issue in case further testing is required.

@jhammond-git
Copy link

Still need to change line 1192 as noted above:

for content_type in data.get("object_types", []):

Apparently I was wrong. Whatever happened the first run after pulling the new code didn't happen the second, so please ignore for now.

@Sivolen
Copy link
Author

Sivolen commented May 13, 2024

I have the same error


2024-05-13 11:33:56,894 - INFO: Querying necessary objects from NetBox. This might take a while.
Traceback (most recent call last):
  File "/opt/scripts/netbox-sync/./netbox-sync.py", line 146, in <module>
    main()
  File "/opt/scripts/netbox-sync/./netbox-sync.py", line 98, in main
    nb_handler.query_current_data(source.dependent_netbox_objects)
  File "/opt/scripts/netbox-sync/module/netbox/connection.py", line 521, in query_current_data
    self.inventory.add_object(nb_object_class, data=object_data, read_from_netbox=True)
  File "/opt/scripts/netbox-sync/module/netbox/inventory.py", line 176, in add_object
    new_object = object_type(data, read_from_netbox=read_from_netbox, inventory=self, source=source)
  File "/opt/scripts/netbox-sync/module/netbox/object_classes.py", line 1178, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/scripts/netbox-sync/module/netbox/object_classes.py", line 296, in __init__
    self.update(data=data, read_from_netbox=read_from_netbox, source=source)
  File "/opt/scripts/netbox-sync/module/netbox/object_classes.py", line 1194, in update
    for object_type in data.get("object_types"):
TypeError: 'NoneType' object is not iterable

@sulik76
Copy link

sulik76 commented May 13, 2024

For me it doesn't work with Netbox v3.7 - same error as @Sivolen. It works with Netbox v4.0.1 but before that I needed to delete the cache directory.

@bb-Ricardo
Copy link
Owner

Hi @sulik76 and @Sivolen,

did you try to clean the cache folder first?

@sulik76
Copy link

sulik76 commented May 13, 2024

Hi @bb-Ricardo,

Before I ran the script, I deleted the entire cache directory in both Netbox versions (3.7.6 and 4.0.1). For version 4.0.1 the script worked fine, but for version 3.7.6 there is this error:

2024-05-13 12:16:26,721 - DEBUG: Requesting all custom fields from NetBox
{'_body_position': None,
'_cookies': <RequestsCookieJar[]>,
'body': None,
'headers': {'User-Agent': 'netbox-sync/1.6.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '/', 'Connection': 'keep-alive', 'Authorization': 'Token xxxxxxxxxxxxx', 'Content-Type': 'application/json'},
'hooks': {'response': []},
'method': 'GET',
'url': 'https://localhost:443/api/extras/custom-fields/?limit=200&exclude=config_context'}
send: b'GET /api/extras/custom-fields/?limit=200&exclude=config_context HTTP/1.1\r\nHost: localhost\r\nUser-Agent: netbox-sync/1.6.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: /\r\nConnection: keep-alive\r\nAuthorization: Token xxxxxxxxxxxxx\r\nContent-Type: application/json\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Server: nginx/1.22.1
header: Date: Mon, 13 May 2024 10:16:26 GMT
header: Content-Type: application/json
header: Content-Length: 2276
header: Connection: keep-alive
header: Vary: HX-Request, Cookie, origin
header: Allow: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
header: X-Request-ID: 22a497c1-b7af-48a1-b985-168136518868
header: API-Version: 3.7
header: X-Content-Type-Options: nosniff
header: Referrer-Policy: same-origin
header: Cross-Origin-Opener-Policy: same-origin
header: X-Frame-Options: SAMEORIGIN
2024-05-13 12:16:26,766 - DEBUG: https://localhost:443 "GET /api/extras/custom-fields/?limit=200&exclude=config_context HTTP/1.1" 200 2276
2024-05-13 12:16:26,766 - DEBUG2: Received HTTP Status 200.
2024-05-13 12:16:26,767 - DEBUG: Response Body:
{'count': 3,
'next': None,
'previous': None,
'results': [{'choice_set': None,
'content_types': ['dcim.device'],
'created': '2023-01-27T15:30:12.579760+01:00',
'data_type': 'string',
'default': None,
'description': "vCenter 'vcenterOZI1' reported Host CPU cores",
'display': 'Physical CPU Cores',
'filter_logic': {'label': 'Loose', 'value': 'loose'},
'group_name': '',
'id': 1,
'is_cloneable': False,
'label': 'Physical CPU Cores',
'last_updated': '2023-01-27T15:30:12.579787+01:00',
'name': 'vcsa_host_cpu_cores',
'object_type': None,
'required': False,
'search_weight': 1000,
'type': {'label': 'Text', 'value': 'text'},
'ui_editable': {'label': 'Yes', 'value': 'yes'},
'ui_visible': {'label': 'Always', 'value': 'always'},
'url': 'https://localhost/api/extras/custom-fields/1/',
'validation_maximum': None,
'validation_minimum': None,
'validation_regex': '',
'weight': 100},
{'choice_set': None,
'content_types': ['dcim.device'],
'created': '2023-01-27T15:30:12.712891+01:00',
'data_type': 'string',
'default': None,
'description': "vCenter 'vcenterOZI1' reported Memory",
'display': 'Memory',
'filter_logic': {'label': 'Loose', 'value': 'loose'},
'group_name': '',
'id': 2,
'is_cloneable': False,
'label': 'Memory',
'last_updated': '2023-01-27T15:30:12.712912+01:00',
'name': 'vcsa_host_memory',
'object_type': None,
'required': False,
'search_weight': 1000,
'type': {'label': 'Text', 'value': 'text'},
'ui_editable': {'label': 'Yes', 'value': 'yes'},
'ui_visible': {'label': 'Always', 'value': 'always'},
'url': 'https://localhost/api/extras/custom-fields/2/',
'validation_maximum': None,
'validation_minimum': None,
'validation_regex': '',
'weight': 100},
{'choice_set': None,
'content_types': ['dcim.device'],
'created': '2023-02-02T09:48:50.475600+01:00',
'data_type': 'string',
'default': None,
'description': 'Support',
'display': 'Support',
'filter_logic': {'label': 'Loose', 'value': 'loose'},
'group_name': 'Support',
'id': 3,
'is_cloneable': False,
'label': 'Support',
'last_updated': '2023-02-02T10:43:19.424703+01:00',
'name': 'Support',
'object_type': None,
'required': False,
'search_weight': 1000,
'type': {'label': 'Text', 'value': 'text'},
'ui_editable': {'label': 'Yes', 'value': 'yes'},
'ui_visible': {'label': 'Always', 'value': 'always'},
'url': 'https://localhost/api/extras/custom-fields/3/',
'validation_maximum': None,
'validation_minimum': None,
'validation_regex': '',
'weight': 100}]}
2024-05-13 12:16:26,772 - DEBUG: Successfully cached 3 objects.
2024-05-13 12:16:26,772 - DEBUG: Processing 3 returned custom fields
Traceback (most recent call last):
File "/opt/netbox-sync/netbox-sync.py", line 146, in
main()
File "/opt/netbox-sync/netbox-sync.py", line 98, in main
nb_handler.query_current_data(source.dependent_netbox_objects)
File "/opt/netbox-sync/module/netbox/connection.py", line 521, in query_current_data
self.inventory.add_object(nb_object_class, data=object_data, read_from_netbox=True)
File "/opt/netbox-sync/module/netbox/inventory.py", line 176, in add_object
new_object = object_type(data, read_from_netbox=read_from_netbox, inventory=self, source=source)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox-sync/module/netbox/object_classes.py", line 1178, in init
super().init(*args, **kwargs)
File "/opt/netbox-sync/module/netbox/object_classes.py", line 296, in init
self.update(data=data, read_from_netbox=read_from_netbox, source=source)
File "/opt/netbox-sync/module/netbox/object_classes.py", line 1194, in update
for object_type in data.get("object_types"):
TypeError: 'NoneType' object is not iterable

@bb-Ricardo
Copy link
Owner

bb-Ricardo commented May 13, 2024

Hi,

I pushed another fix to handle the renamed field correctly. Can you try it out if it works now. Also deleting cache is important.

thank you

@Sivolen
Copy link
Author

Sivolen commented May 13, 2024

Hi,

I pushed another fix to handle the renamed field correctly. Can you try it out if it works now. Also deleting cache is important.

thank you

after clearing the cache the script works correctly,
after the last commit the script works just as correctly

@sulik76
Copy link

sulik76 commented May 14, 2024

Hi,

Netbox 3.7.6
After pulling the script with the latest changes, it works correctly.

Upgrade Netbox from 3.7.6 to 4.0.1
The script works correctly after clearing the cache directory.

@bb-Ricardo
Copy link
Owner

Awesome, thank you for testing and confirming.

@bb-Ricardo bb-Ricardo added the bug Something isn't working label May 14, 2024
@bb-Ricardo
Copy link
Owner

andreiKuznets0v pushed a commit to andreiKuznets0v/netbox-sync_try_vcloud that referenced this issue Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants