Skip to content

Commit 2d807e5

Browse files
committed
feat: Update endpoint mappings for tunnels in netbox_utils
1 parent 3b738aa commit 2d807e5

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
vpn={
132132
"l2vpns": {"introduced": "3.7"},
133133
"l2vpn_terminations": {"introduced": "3.7"},
134+
"tunnels": {"introduced": "3.7"},
134135
},
135136
)
136137

plugins/modules/netbox_tunnel.py

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
# Copyright: (c) 2024, Rich Bibby (@richbibby)
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
from __future__ import absolute_import, division, print_function
7+
8+
__metaclass__ = type
9+
10+
DOCUMENTATION = r"""
11+
---
12+
module: netbox_location
13+
short_description: Create, update or delete locations within NetBox
14+
description:
15+
- Creates, updates or removes locations from NetBox
16+
notes:
17+
- Tags should be defined as a YAML list
18+
- This should be ran with connection C(local) and hosts C(localhost)
19+
author:
20+
- Andrew Simmons (@andybro19)
21+
requirements:
22+
- pynetbox
23+
version_added: '3.3.0'
24+
extends_documentation_fragment:
25+
- netbox.netbox.common
26+
options:
27+
data:
28+
type: dict
29+
description:
30+
- Defines the location configuration
31+
suboptions:
32+
name:
33+
description:
34+
- The name of the location
35+
required: true
36+
type: str
37+
status:
38+
description:
39+
- Status of the location
40+
required: false
41+
type: raw
42+
version_added: "3.20.0"
43+
slug:
44+
description:
45+
- The slugified version of the name or custom slug.
46+
- This is auto-generated following NetBox rules if not provided
47+
required: false
48+
type: str
49+
site:
50+
description:
51+
- Required if I(state=present) and the location does not exist yet
52+
required: false
53+
type: raw
54+
parent_location:
55+
description:
56+
- The parent location the location will be associated with
57+
required: false
58+
type: raw
59+
tenant:
60+
description:
61+
- The tenant that the location will be associated with
62+
required: false
63+
type: raw
64+
version_added: "3.8.0"
65+
facility:
66+
description:
67+
- Data center provider or facility, ex. Equinix NY7
68+
required: false
69+
type: str
70+
version_added: "3.20.0"
71+
description:
72+
description:
73+
- The description of the location
74+
required: false
75+
type: str
76+
tags:
77+
description:
78+
- The tags to add/update
79+
required: false
80+
type: list
81+
elements: raw
82+
version_added: "3.6.0"
83+
custom_fields:
84+
description:
85+
- Must exist in NetBox
86+
required: false
87+
type: dict
88+
version_added: "3.6.0"
89+
required: true
90+
"""
91+
92+
EXAMPLES = r"""
93+
- name: "Test NetBox modules"
94+
connection: local
95+
hosts: localhost
96+
gather_facts: false
97+
98+
tasks:
99+
- name: Create location within NetBox with only required information
100+
netbox.netbox.netbox_location:
101+
netbox_url: http://netbox.local
102+
netbox_token: thisIsMyToken
103+
data:
104+
name: Test location
105+
site: Test Site
106+
state: present
107+
108+
- name: Create location within NetBox with a parent location, status and facility
109+
netbox.netbox.netbox_location:
110+
netbox_url: http://netbox.local
111+
netbox_token: thisIsMyToken
112+
data:
113+
name: Child location
114+
site: Test Site
115+
parent_location: Test location
116+
status: planned
117+
facility: Test Facility
118+
state: present
119+
120+
- name: Delete location within NetBox
121+
netbox.netbox.netbox_location:
122+
netbox_url: http://netbox.local
123+
netbox_token: thisIsMyToken
124+
data:
125+
name: Test location
126+
state: absent
127+
"""
128+
129+
RETURN = r"""
130+
location:
131+
description: Serialized object as created or already existent within NetBox
132+
returned: success (when I(state=present))
133+
type: dict
134+
msg:
135+
description: Message indicating failure or info about what has been achieved
136+
returned: always
137+
type: str
138+
"""
139+
140+
from ansible_collections.netbox.netbox.plugins.module_utils.netbox_utils import (
141+
NetboxAnsibleModule,
142+
NETBOX_ARG_SPEC,
143+
)
144+
from ansible_collections.netbox.netbox.plugins.module_utils.netbox_vpn import (
145+
NetboxVpnModule,
146+
NB_TUNNELS,
147+
)
148+
from copy import deepcopy
149+
150+
151+
def main():
152+
"""
153+
Main entry point for module execution
154+
"""
155+
argument_spec = deepcopy(NETBOX_ARG_SPEC)
156+
argument_spec.update(
157+
dict(
158+
data=dict(
159+
type="dict",
160+
required=True,
161+
options=dict(
162+
name=dict(required=True, type="str"),
163+
status=dict(required=False, type="raw"),
164+
encapsulation=dict(required=False, type="raw"),
165+
tenant=dict(required=False, type="raw"),
166+
description=dict(required=False, type="str"),
167+
tags=dict(required=False, type="list", elements="raw"),
168+
custom_fields=dict(required=False, type="dict"),
169+
),
170+
),
171+
)
172+
)
173+
174+
required_if = [("state", "present", ["name"]), ("state", "absent", ["name"])]
175+
176+
module = NetboxAnsibleModule(
177+
argument_spec=argument_spec, supports_check_mode=True, required_if=required_if
178+
)
179+
180+
netbox_tunnel = NetboxVpnModule(module, NB_TUNNELS)
181+
netbox_tunnel.run()
182+
183+
184+
if __name__ == "__main__": # pragma: no cover
185+
main()

0 commit comments

Comments
 (0)