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 VM Interface Role. #415

Merged
merged 22 commits into from
Sep 9, 2024
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
8 changes: 8 additions & 0 deletions plugins/modules/vm_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
required: false
type: raw
version_added: "3.0.0"
role:
description:
- The role of the interface
required: false
type: raw
version_added: "5.3.0"
"""

EXAMPLES = r"""
Expand Down Expand Up @@ -125,6 +131,7 @@
- name: VoIP
location: "{{ test_location['key'] }}"
mtu: 1600
role: Server
mode: Tagged
state: present

Expand Down Expand Up @@ -184,6 +191,7 @@ def main():
mode=dict(required=False, type="raw"),
untagged_vlan=dict(required=False, type="raw"),
tagged_vlans=dict(required=False, type="raw"),
role=dict(required=False, type="raw"),
)
)

Expand Down
11 changes: 10 additions & 1 deletion tests/integration/nautobot-populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ def make_nautobot_calls(endpoint, payload):
device_roles.append({"name": "Test Controller Role", "color": "e91e65", "vm_role": False, "content_types": ["dcim.controller"]})

created_device_roles = make_nautobot_calls(nb.extras.roles, device_roles)

# Device role variables to be used later on
core_switch = nb.extras.roles.get(name="Core Switch")


# Create Rack Groups
rack_groups = [
{"name": "Parent Rack Group", "location": location_child.id},
Expand Down Expand Up @@ -620,6 +620,15 @@ def make_nautobot_calls(endpoint, payload):
contacts = [{"name": "My Contact"}, {"name": "My Contact 2"}]
created_contacts = make_nautobot_calls(nb.extras.contacts, contacts)

###############
# v2.3+ items #
###############
if nautobot_version >= version.parse("2.3"):
# Create role for virtual machine interfaces
vm_interface_roles = [
{"name": "Test VM Interface Role", "color": "aa1409", "vm_role": False, "content_types": ["virtualization.vminterface"]},
]
created_vm_interface_roles = make_nautobot_calls(nb.extras.roles, vm_interface_roles)

if ERRORS:
sys.exit("Errors have occurred when creating objects, and should have been printed out. Check previous output.")
1 change: 0 additions & 1 deletion tests/integration/targets/latest/tasks/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
role: "{{ lookup('networktocode.nautobot.lookup', 'roles', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Core Switch\"') }}"
vc1: "{{ lookup('networktocode.nautobot.lookup', 'virtual-chassis', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=VC1') }}"
staged: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Staged') }}"
active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}"
device_redundancy_group: "{{ lookup('networktocode.nautobot.lookup', 'device-redundancy-groups', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"My Device Redundancy Group\"') }}"

- name: "1 - Device with required information"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
##
##
- set_fact:
active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}"
secrets_group: "{{ lookup('networktocode.nautobot.lookup', 'secrets-groups', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Test Secrets Group\"') }}"

- name: "1 - Create device redundancy group within Nautobot with only required information"
Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/latest/tasks/location.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- set_fact:
parent_location_type: "{{ lookup('networktocode.nautobot.lookup', 'location-types', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"My Parent Location Type\"') }}"
child_location_type: "{{ lookup('networktocode.nautobot.lookup', 'location-types', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"My Child Location Type\"') }}"
active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}"

- name: "1 - Create location within Nautobot with only required information"
networktocode.nautobot.location:
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/targets/latest/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---
- name: "Set facts used in multiple tests."
set_fact:
active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}"
tags:
- always

# Lookup tests should run first so items created by other tests don't influence the results
- name: "PYNAUTOBOT_LOOKUP TESTS"
include_tasks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
##
##
- set_fact:
active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}"
planned: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Planned') }}"

- name: "BGP ASN 1: Creation"
Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/latest/tasks/prefix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
tag_schnozzberry: "{{ lookup('networktocode.nautobot.lookup', 'tags', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Schnozzberry') }}"
vlan_group: "{{ lookup('networktocode.nautobot.lookup', 'vlan-groups', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Test Vlan Group\"') }}"
reserved: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Reserved') }}"
active: "{{ lookup('networktocode.nautobot.lookup', 'statuses', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Active') }}"
global_namespace: "{{ lookup('networktocode.nautobot.lookup', 'namespaces', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Global') }}"
private_namespace: "{{ lookup('networktocode.nautobot.lookup', 'namespaces', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=Private') }}"

Expand Down
57 changes: 57 additions & 0 deletions tests/integration/targets/latest/tasks/vm_interface.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,60 @@
- test_five['interface']['tagged_vlans']|length == 2
- test_five['interface']['tags'][0] == tag_schnozzberry['key']
- test_five['msg'] == "interface Eth0 updated"

- name: "NAUTOBOT 2.3+ TESTS"
when:
- "nautobot_version is version('2.3', '>=')"
block:
- name: SET ADDITIONAL FACTS
set_fact:
vm_interface_role: "{{ lookup('networktocode.nautobot.lookup', 'roles', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Test VM Interface Role\"' )}}"

- name: "PYNAUTOBOT_VM_INTERFACE 10: Created"
networktocode.nautobot.vm_interface:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
virtual_machine: "test100-vm"
name: "Eth101"
enabled: false
mtu: 9000
mac_address: "00:00:00:AA:AA:01"
description: "Updated test100-vm"
mode: Tagged
role: "Test VM Interface Role"
status: "Active"
untagged_vlan:
name: Wireless
location: "Child Test Location"
tagged_vlans:
- name: Data
location: "Child Test Location"
- name: VoIP
location: "Child Test Location"
tags:
- "Schnozzberry"
state: present
register: test_ten

- debug:
msg: "{{ test_ten }}"

- name: "PYNAUTOBOT_VM_INTERFACE 10: ASSERT - Created"
assert:
that:
- test_ten is changed
- test_ten['diff']['before']['state'] == "absent"
- test_ten['diff']['after']['state'] == "present"
- test_ten['interface']['name'] == "Eth101"
- test_ten['interface']['status'] == active['key']
- test_ten['interface']['virtual_machine'] == vm100['key']
- test_ten['interface']['enabled'] == false
- test_ten['interface']['mtu'] == 9000
- test_ten['interface']['mac_address'] == "00:00:00:AA:AA:01"
- test_ten['interface']['description'] == "Updated test100-vm"
- test_ten['interface']['mode'] == "tagged"
- test_ten['interface']['untagged_vlan'] == wireless['key']
- test_ten['interface']['tagged_vlans']|length == 2
- test_ten['interface']['tags'][0] == tag_schnozzberry['key']
- test_ten['interface']['role'] == vm_interface_role['key']
- test_ten['msg'] == "interface Eth101 created"