Skip to content

Commit 886fc20

Browse files
BugFix: Added logic to netbox_dcim to determine if interface is part of a vc device or not (#111)
1 parent 0b143b0 commit 886fc20

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

plugins/module_utils/netbox_dcim.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ def run(self):
9090
object_query_params = self._build_query_params(endpoint_name, data)
9191
self.nb_object = self._nb_endpoint_get(nb_endpoint, object_query_params, name)
9292

93+
# This is logic to handle interfaces on a VC
94+
if self.endpoint == "interfaces":
95+
if self.nb_object:
96+
if self.nb_object.device:
97+
device = nb_endpoint.get(self.nb_object.device.id)
98+
if (
99+
device["virtual_chassis"]
100+
and self.nb_object.device.id != self.data["device"]
101+
):
102+
self.object = None
103+
93104
if self.state == "present":
94105
self._ensure_object_exists(nb_endpoint, endpoint_name, name, data)
95106

tests/integration/integration-tests.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
- test_five['interface']['enabled'] == false
340340
- test_five['interface']['form_factor'] == 1000
341341
- test_five['interface']['mgmt_only'] == false
342-
- test_five['interface']['lag'] == 14
342+
- test_five['interface']['lag'] == 15
343343
- test_five['interface']['mode'] == 100
344344
- test_five['interface']['mtu'] == 1600
345345

@@ -428,10 +428,33 @@
428428
- test_eight['interface']['enabled'] == false
429429
- test_eight['interface']['form_factor'] == 1000
430430
- test_eight['interface']['mgmt_only'] == false
431-
- test_eight['interface']['lag'] == 14
431+
- test_eight['interface']['lag'] == 15
432432
- test_eight['interface']['mode'] == 100
433433
- test_eight['interface']['mtu'] == 1600
434434

435+
- name: "9 - Create interface on VC child"
436+
netbox_device_interface:
437+
netbox_url: "http://localhost:32768"
438+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
439+
data:
440+
device: Test Nexus Child One
441+
name: Ethernet1/1
442+
form_factor: 1000Base-T (1GE)
443+
state: present
444+
register: test_nine
445+
446+
- name: "9 - ASSERT"
447+
assert:
448+
that:
449+
- test_nine is changed
450+
- test_nine['msg'] == "interface Ethernet1/1 created"
451+
- test_nine['diff']['before']['state'] == 'absent'
452+
- test_nine['diff']['after']['state'] == 'present'
453+
- test_nine['interface']['name'] == "Ethernet1/1"
454+
- test_nine['interface']['device'] == 5
455+
- test_nine['interface']['enabled'] == true
456+
- test_nine['interface']['form_factor'] == 1000
457+
435458
##
436459
##
437460
### NETBOX_IP_ADDRESS
@@ -615,7 +638,7 @@
615638
- test_eight['msg'] == "ip_address 10.10.1.30/16 created"
616639
- test_eight['ip_address']['address'] == "10.10.1.30/16"
617640
- test_eight['ip_address']['family'] == 4
618-
- test_eight['ip_address']['interface'] == 1
641+
- test_eight['ip_address']['interface'] == 2
619642
- test_eight['ip_address']['nat_inside'] == 7
620643
- test_eight['ip_address']['vrf'] == 1
621644

@@ -640,7 +663,7 @@
640663
- test_nine['msg'] == "ip_address 10.10.200.30/16 created"
641664
- test_nine['ip_address']['address'] == "10.10.200.30/16"
642665
- test_nine['ip_address']['family'] == 4
643-
- test_nine['ip_address']['interface'] == 2
666+
- test_nine['ip_address']['interface'] == 3
644667

645668
- name: "10 - Create IP address on GigabitEthernet2 - test100 - State: new"
646669
netbox_ip_address:
@@ -664,7 +687,7 @@
664687
- test_ten['msg'] == "ip_address 10.10.0.1/16 created"
665688
- test_ten['ip_address']['address'] == "10.10.0.1/16"
666689
- test_ten['ip_address']['family']['value'] == 4
667-
- test_ten['ip_address']['interface']['id'] == 2
690+
- test_ten['ip_address']['interface']['id'] == 3
668691

669692
- name: "11 - Create IP address on GigabitEthernet2 - test100 - State: present"
670693
netbox_ip_address:
@@ -706,7 +729,7 @@
706729
- not test_twelve['changed']
707730
- test_twelve['msg'] == "ip_address 192.168.100.2/24 already exists"
708731
- test_twelve['ip_address']['address'] == "192.168.100.2/24"
709-
- test_twelve['ip_address']['interface'] == 2
732+
- test_twelve['ip_address']['interface'] == 3
710733

711734
- name: "13 - Duplicate - 192.168.100.2/24"
712735
netbox_ip_address:
@@ -745,7 +768,7 @@
745768
- test_fourteen['msg'] == "ip_address 10.188.1.100/24 created"
746769
- test_fourteen['ip_address']['address'] == "10.188.1.100/24"
747770
- test_fourteen['ip_address']['family'] == 4
748-
- test_fourteen['ip_address']['interface'] == 3
771+
- test_fourteen['ip_address']['interface'] == 4
749772

750773
- name: "15 - Create IP address with no mask - State: Present"
751774
netbox_ip_address:

tests/integration/netbox-deploy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@
189189
### Device variables to be used later on
190190
test100 = nb.dcim.devices.get(name="test100")
191191

192+
# Create VC, assign member, create initial interface
193+
created_vcs = nb.dcim.virtual_chassis.create({"master": 4})
194+
nexus_child = nb.dcim.devices.get(5)
195+
nexus_child.update({"virtual_chassis": 1, "vc_position": 1})
196+
nexus = nb.dcim.devices.get(4)
197+
nexus.update({"vc_position": 0})
198+
nb.dcim.interfaces.create({"device": 4, "name": "Ethernet1/1", "type": 1000})
192199

193200
## Create Interfaces
194201
dev_interfaces = [

0 commit comments

Comments
 (0)