netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Bulk cable import does not validate interface types

Open klaernie opened this issue 3 years ago • 9 comments

NetBox version

v3.2.3

Python version

3.9

Steps to Reproduce

  1. create device role dummy role
  2. create site demo site
  3. create manufacturer dummy manufacturer
  4. create a device type demo model, using the dummy manufacturer
  5. add an interface template to the demo model device type:
    • name it demo virtual if
    • set the type to Virtual
  6. create two devices using the demo model, thedummy role and the demo site
    • name the first one demo1
    • name the second one demo2
  7. attempt to import the following cable CSV:
    side_a_device,side_a_type,side_a_name,side_b_device,side_b_type,side_b_name
    demo1,dcim.interface,demo virtual if,demo2,dcim.interface,demo virtual if
    

Expected Behavior

Either of:

  • The cable gets imported and displayed as usually
  • The import fails with a meaningful error message like Virtual interfaces cannot have a cable attached.

Observed Behavior

The following exception is thrown:

<class 'ValueError'>

'CableCSVForm' has no field named 'termination_a_id'.

Python version: 3.8.10
NetBox version: 3.2.3

klaernie avatar May 23 '22 12:05 klaernie

This issue was already reported once as #6045, but was missing the concrete reproduction steps.

Additionally I should mention, that as soon as I change the interface type of demo1's demo virtual if interface to other the exception changes to 'CableCSVForm' has no field named 'termination_b_id'.. Following this up with changing the demo virtual if interface on demo2 to other as well leads to a properly imported cable.

klaernie avatar May 23 '22 12:05 klaernie

Either of:

  • The cable gets imported and displayed as usually
  • The import fails with a meaningful error message like Virtual interfaces cannot have a cable attached.

Virtual interfaces cannot have a cable connected; the second item is correct. The error occurs because the interfaces fields' queryset is being filtered by type to exclude virtual interfaces in the current implementation.

jeremystretch avatar May 23 '22 12:05 jeremystretch

As I didn't find it yet: where is described, why virtual interfaces cannot be cabled? From my point of view there is merit in having cables between virtual interfaces, for example to clearly document multiple network interfaces belonging to VMs, or to represent hypervisors nested in VMs.

klaernie avatar May 23 '22 12:05 klaernie

Why not model the VM infrastructure with your prefixes and Virtualisation options in Netbox? Cables are a physical (Layer 1) part. VM's are at least application level code.

TheNetworkGuy avatar May 23 '22 13:05 TheNetworkGuy

Why not model the VM infrastructure with your prefixes and Virtualisation options in Netbox?

VMs cannot be members of virtualization clusters. IP address management is totally separate from managing connections.

Cables are a physical (Layer 1) part.

If you talk about bare metal: yes. But for a virtual machine the "cable" is not made of copper, but it still plugs into a switch, be it a vSwitch in VMware, be it a Linux bridge for libvirt/KVM/Proxmox. But a VM's "cable" can also be directly attached to a hypervisor host's physical interface, by taking the entire control of the NIC away from the hypervisor and handing it to the VM. And lastly you can build entire network environments in software inside of a single host - take a typical virtualized lab environment for testing weird edge cases or non-typical routing.

It all boils down to: Allows netbox to model reality, or does it prescribe some concepts?

And taking a look at certain design decisions (like for example the possibility to attach a wifi ssid to an 100BASE-TX typed interface on the create screen) I interpret the intentions more as "encourages best practises, but allows to model reality"

klaernie avatar May 23 '22 14:05 klaernie

@klaernie The cable model in Netbox is used to model physical cables only. This will not change.

jeremystretch avatar May 23 '22 14:05 jeremystretch

@klaernie The cable model in Netbox is used to model physical cables only. This will not change.

Totally fair point. I'll be fine pretending my first virtualization layer exists physically and use the "other" interface type to make my connections able to be modelled.

The only point for opening this issue is to have this constraint clearly communicated to future users, so they don't have to spend an hour figuring it out.

klaernie avatar May 23 '22 15:05 klaernie

I have to agree that virtual interfaces shouldn't be cabled.

For virtual systems, I could see adding a "virtual switch" system where interfaces are attached to virtual switches either on the host(s) they belong to or on the cluster itself. This might be something to consider as a FR. Perhaps open a discussion regarding this as a FR and see if you can gain some traction.

DanSheps avatar May 24 '22 13:05 DanSheps

Holding off on this until #9102 has been completed

jeremystretch avatar May 24 '22 14:05 jeremystretch

During import, it now looks like this is checked. However, the following exception is generated:

ValueError at /dcim/cables/import/
'CableCSVForm' has no field named 'termination'.
Request Method:	POST
Request URL:	http://127.0.0.1:8000/dcim/cables/import/
Django Version:	4.0.7
Exception Type:	ValueError
Exception Value:	
'CableCSVForm' has no field named 'termination'.
Exception Location:	C:\Development\netbox\venv\lib\site-packages\django\forms\forms.py, line 400, in add_error
Python Executable:	C:\Development\netbox\venv\Scripts\python.exe
Python Version:	3.10.4
Python Path:	
['C:\\Development\\netbox\\netbox\\netbox',
 'C:\\Program Files\\Python\\3.10\\python310.zip',
 'C:\\Program Files\\Python\\3.10\\DLLs',
 'C:\\Program Files\\Python\\3.10\\lib',
 'C:\\Program Files\\Python\\3.10',
 'C:\\Development\\netbox\\venv',
 'C:\\Development\\netbox\\venv\\lib\\site-packages',
 'c:\\development\\netbox\\netbox-routing',
 'c:\\development\\netbox\\netbox-config-backup',
 'C:\\Development\\netbox\\venv\\lib\\site-packages\\pydriller-2.1-py3.10.egg',
 'C:\\Development\\netbox\\venv\\lib\\site-packages\\dulwich-0.20.35-py3.10-win-amd64.egg',
 'C:\\Development\\netbox\\venv\\lib\\site-packages\\uuid-1.30-py3.10.egg',
 'C:\\Development\\netbox\\venv\\lib\\site-packages\\lizard-1.17.9-py3.10.egg',
 'C:\\Development\\netbox\\venv\\lib\\site-packages\\types_pytz-2021.3.6-py3.10.egg',
 'C:\\Development\\netbox\\venv\\lib\\site-packages\\gitpython-3.1.27-py3.10.egg',
 'C:\\Development\\netbox\\venv\\lib\\site-packages\\gitdb-4.0.9-py3.10.egg',
 'C:\\Development\\netbox\\venv\\lib\\site-packages\\smmap-5.0.0-py3.10.egg',
 'c:\\development\\netbox\\netbox-sync',
 'c:\\development\\netbox\\netbox-secretstore']
Server time:	Fri, 02 Sep 2022 17:30:30 +0000

Going to close this out and opena new issue.

DanSheps avatar Sep 02 '22 17:09 DanSheps