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

Adds parent_interface & bridge options to device_interface #229

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions plugins/modules/device_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@
required: false
type: raw
version_added: "3.0.0"
parent_interface:
description:
- Interface that will be the parent of the interface being created
required: false
type: raw
version_added: "4.5.0"
bridge:
description:
- Interface that will be the bridge of the interface being created
required: false
type: raw
version_added: "4.5.0"
mtu:
description:
- The MTU of the interface
Expand Down Expand Up @@ -206,6 +218,23 @@
enabled: false
custom_fields:
monitored: True
- name: Create child interface
networktocode.nautobot.device_interface:
url: http://nautobot.local
token: thisIsMyToken
device: test100
name: GigabitEthernet1/1/1
type: Virtual
parent_interface:
name: GigabitEthernet1/1
- name: Create bridge interface
networktocode.nautobot.device_interface:
url: http://nautobot.local
token: thisIsMyToken
device: test100
name: Bridge1
bridge:
name: GigabitEthernet1/1
"""

RETURN = r"""
Expand Down Expand Up @@ -243,6 +272,8 @@ def main():
type=dict(required=False, type="str"),
enabled=dict(required=False, type="bool"),
lag=dict(required=False, type="raw"),
parent_interface=dict(required=False, type="raw"),
bridge=dict(required=False, type="raw"),
mtu=dict(required=False, type="int"),
mac_address=dict(required=False, type="str"),
mgmt_only=dict(required=False, type="bool"),
Expand Down
98 changes: 74 additions & 24 deletions tests/integration/targets/latest/tasks/device_interface.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,31 +289,81 @@
- test_eleven is failed
- test_eleven['msg'] == "Must set update_vc_child to True to allow child device interface modification"

##
##
### Nautobot 1.4+ tests
##
##
- block:
- name: "12 - Interface with status"
networktocode.nautobot.device_interface:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device: test100
api_version: "{{ nautobot_version }}"
name: GigabitEthernet9999
status: planned
type: "1000Base-T (1GE)"
register: test_twelve

- name: "12 - Interface with status"
networktocode.nautobot.device_interface:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device: test100
api_version: "{{ nautobot_version }}"
name: GigabitEthernet9999
status: planned
type: "1000Base-T (1GE)"
register: test_twelve
when:
# Status is mandatory only on Nautobot 1.4+
- "nautobot_version is version('1.4', '>=')"
- name: "12 - ASSERT"
assert:
that:
- test_twelve is changed
- test_twelve['msg'] == "interface GigabitEthernet9999 created"
- test_twelve['diff']['before']['state'] == 'absent'
- test_twelve['diff']['after']['state'] == 'present'
- test_twelve['interface']['name'] == "GigabitEthernet9999"
- test_twelve['interface']['status'] == "planned"
- test_twelve['interface']['device'] == test100['key']

- name: "13 - Create child interface"
networktocode.nautobot.device_interface:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device: test100
api_version: "{{ nautobot_version }}"
name: GigabitEthernet9999/1
status: active
type: "Virtual"
parent_interface:
name: GigabitEthernet9999
register: test_thirteen

- name: "13 - ASSERT"
assert:
that:
- test_thirteen is changed
- test_thirteen['msg'] == "interface GigabitEthernet9999/1 created"
- test_thirteen['diff']['before']['state'] == 'absent'
- test_thirteen['diff']['after']['state'] == 'present'
- test_thirteen['interface']['name'] == "GigabitEthernet9999/1"
- test_thirteen['interface']['device'] == test100['key']
- test_thirteen['interface']['parent_interface'] == test_twelve['interface']['id']

- name: "14 - Create bridge interface"
networktocode.nautobot.device_interface:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device: test100
api_version: "{{ nautobot_version }}"
name: Bridge1
status: active
type: "1000Base-T (1GE)"
bridge:
name: GigabitEthernet9999
register: test_fourteen

- name: "14 - ASSERT"
assert:
that:
- test_fourteen is changed
- test_fourteen['msg'] == "interface Bridge1 created"
- test_fourteen['diff']['before']['state'] == 'absent'
- test_fourteen['diff']['after']['state'] == 'present'
- test_fourteen['interface']['name'] == "Bridge1"
- test_fourteen['interface']['device'] == test100['key']
- test_fourteen['interface']['bridge'] == test_twelve['interface']['id']

- name: "12 - ASSERT"
assert:
that:
- test_twelve is changed
- test_twelve['msg'] == "interface GigabitEthernet9999 created"
- test_twelve['diff']['before']['state'] == 'absent'
- test_twelve['diff']['after']['state'] == 'present'
- test_twelve['interface']['name'] == "GigabitEthernet9999"
- test_twelve['interface']['status'] == "planned"
- test_twelve['interface']['device'] == test100['key']
when:
# Status is mandatory only on Nautobot 1.4+
- "nautobot_version is version('1.4', '>=')"