Skip to content

Commit 8cf11d1

Browse files
authored
Merge pull request #428 from markkuleinio/add-available-vlans
Fixes #427: Adds support for `available-vlans` child endpoint for VLAN groups
2 parents 087c513 + 395567b commit 8cf11d1

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

docs/IPAM.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ IPAM
22
========
33

44
.. autoclass:: pynetbox.models.ipam.Prefixes
5-
:members:
5+
:members:
6+
7+
.. autoclass:: pynetbox.models.ipam.VlanGroups
8+
:members:

pynetbox/models/ipam.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,34 @@ def available_prefixes(self):
9797
class Aggregates(Record):
9898
def __str__(self):
9999
return str(self.prefix)
100+
101+
102+
class Vlans(Record):
103+
def __str__(self):
104+
return super().__str__(self) or str(self.vid)
105+
106+
107+
class VlanGroups(Record):
108+
@property
109+
def available_vlans(self):
110+
""" Represents the ``available-vlans`` detail endpoint.
111+
112+
Returns a DetailEndpoint object that is the interface for
113+
viewing and creating VLANs inside a VLAN group.
114+
115+
Available since NetBox 3.2.0.
116+
117+
:returns: :py:class:`.DetailEndpoint`
118+
119+
:Examples:
120+
121+
>>> vlan_group = nb.ipam.vlan_groups.get(1)
122+
>>> vlan_group.available_vlans.list()
123+
[10, 11, 12]
124+
125+
To create a new VLAN:
126+
127+
>>> vlan_group.available_vlans.create({"name": "NewVLAN"})
128+
NewVLAN (10)
129+
"""
130+
return DetailEndpoint(self, "available-vlans", custom_return=Vlans)

0 commit comments

Comments
 (0)