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

Discovery of VMware vSphere device has error vim.dvs.PortConnection is not JSON serializable #75

Closed
dietybright opened this issue Sep 28, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@dietybright
Copy link

When running discovery vcenter/esxi-host with admin credential, I am facing issue with netdoc 3.5.3 or 0.10.33, any idea?

An exception occurred: TypeError: Object of type vim.dvs.PortConnection is not JSON serializable

Traceback (most recent call last):
File "/opt/netbox/netbox/extras/scripts.py", line 504, in _run_script
script.output = script.run(data=data, commit=commit)
File "/opt/netbox/netbox/scripts/netdoc_scripts.py", line 262, in run
output = discovery(
File "/opt/netbox/venv/lib/python3.10/site-packages/netdoc/tasks.py", line 111, in discovery
module.discovery(filtered_devices, filters=filters, filter_type=filter_type)
File "/opt/netbox/venv/lib/python3.10/site-packages/netdoc/discoverers/json_vmware_vsphere.py", line 272, in discovery
raw_output=json.dumps(result.result),
File "/usr/lib/python3.10/json/init.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.10/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type vim.dvs.PortConnection is not JSON serializable

@dainok
Copy link
Owner

dainok commented Sep 28, 2023

Unfortunately I don't have a DVS on my lab so I cannot debug this issue. Can you debug /opt/netbox/venv/lib/python3.10/site-packages/netdoc/discoverers/json_vmware_vsphere.py ?

@dainok dainok added the bug Something isn't working label Sep 28, 2023
@dietybright
Copy link
Author

This is the debug output, not sure if it helpful

INFO:nornir.core:Running task 'multiple_tasks' with args {} on 1 hosts
DEBUG:nornir.core.task:Host '192.168.1.53': running task 'multiple_tasks'
DEBUG:nornir.core.task:Host '192.168.1.53': running task '{"command": "pyVmomi", "template": "pyVmomi", "order": 0, "enable": false, "supported": true, "verify_cert": false}'
ERROR:netbox.scripts.NetDoc.Discover:An exception occurred: TypeError: Object of type vim.dvs.PortConnection is not JSON serializable

Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/scripts.py", line 476, in _run_script
    script.output = script.run(data=data, commit=commit)
  File "/opt/netbox/netbox/scripts/NetDoc.py", line 264, in run
    output = discovery(
  File "/opt/netbox/venv/lib/python3.10/site-packages/netdoc/tasks.py", line 111, in discovery
    module.discovery(filtered_devices, filters=filters, filter_type=filter_type)
  File "/opt/netbox/venv/lib/python3.10/site-packages/netdoc/discoverers/json_vmware_vsphere.py", line 280, in discovery
    raw_output=json.dumps(result.result),
  File "/usr/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type vim.dvs.PortConnection is not JSON serializable

INFO:netbox.scripts.NetDoc.Discover:Database changes have been reverted due to error.
ERROR:netbox.scripts.NetDoc.Discover:Exception raised during script execution: Object of type vim.dvs.PortConnection is not JSON serializable
INFO:webhooks:Clearing 0 queued webhooks (<utilities.utils.NetBoxFakeRequest object at 0x7f8e0614b490>)
INFO:netbox.scripts.NetDoc.Discover:Script completed in 0 minutes, 13.96 seconds
DEBUG:netbox.config:No previous configuration found in database; proceeding with default values
DEBUG:netbox.config:Initialized configuration
INFO:rq.worker:default: Job OK (a727df2b-962c-4108-b92a-3fd1ccf228c0)
INFO:rq.worker:Result is kept for 500 seconds

@cmong-nextech
Copy link

cmong-nextech commented Sep 29, 2023

Try replacing line 272 in "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/discoverers/json_vmware_vsphere.py"
raw_output=json.dumps(result.result),
with
raw_output=json.dumps(result.result, default=lambda o: o.__dict__),
That got it working for me.

@dainok
Copy link
Owner

dainok commented Sep 30, 2023

Thank you. Let me fix a major issue then I'll merge your suggestion.

@dainok
Copy link
Owner

dainok commented Sep 30, 2023

Merged with #80
Give a while for the CI/CD, upgrade to 3.5.6 and let me know.

@dietybright
Copy link
Author

Its worked with 3.5.6 but my enviroment unable to get vswitch/portgroup, seem we need to define on netbox first

Another thing is the connected interface/device of host physical adapter via pyVmomi cdp neighbor information, it would be greate if netdoc can make this connection

@dainok
Copy link
Owner

dainok commented Oct 2, 2023

Currently I'm using the NetBox data structure to store clusters, hosts and VMs. I'm not completely satisfied because all network information are lost. NetBox does not have the vSwitch concept.

Regarding host CDP, if you can modify the discover script, to grab those info, I can modify the ingest script.

@dainok
Copy link
Owner

dainok commented Oct 5, 2023

In case, open a new issue to track improvements.

@dainok dainok closed this as completed Oct 5, 2023
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

3 participants