Merge ~jsseidel/maas:jsseidel-vlans-api-annotations into maas:master

Proposed by Spencer Seidel
Status: Merged
Approved by: Newell Jensen
Approved revision: 350aee68fa8cb3b1dca3f89ae5010b32cec74f3d
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~jsseidel/maas:jsseidel-vlans-api-annotations
Merge into: maas:master
Diff against target: 283 lines (+181/-49)
2 files modified
src/maasserver/api/examples/fabrics.json (+64/-0)
src/maasserver/api/vlans.py (+117/-49)
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
MAAS Lander unittests Pending
Review via email: mp+359138@code.launchpad.net

Commit message

Added API annotations and examples database.

Description of the change

Note that the name of the database is "fabrics" because of the URI when working with VLANs, which is like: /MAAS/api/2.0/fabrics/[0-9]+/vlan[s]*/[0-9]+/. The annotation code parses out "fabrics" from this URI and looks for that file.

To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/examples/fabrics.json b/src/maasserver/api/examples/fabrics.json
2new file mode 100644
3index 0000000..2889e72
4--- /dev/null
5+++ b/src/maasserver/api/examples/fabrics.json
6@@ -0,0 +1,64 @@
7+{
8+ "vlan-list": [
9+ {
10+ "vid": 0,
11+ "mtu": 1500,
12+ "dhcp_on": false,
13+ "external_dhcp": null,
14+ "relay_vlan": null,
15+ "space": "undefined",
16+ "fabric_id": 10,
17+ "secondary_rack": null,
18+ "fabric": "fabric-10",
19+ "id": 5014,
20+ "primary_rack": null,
21+ "name": "untagged",
22+ "resource_uri": "/MAAS/api/2.0/vlans/5014/"
23+ }
24+ ],
25+ "vlan-create": {
26+ "vid": 4000,
27+ "mtu": 1500,
28+ "dhcp_on": false,
29+ "external_dhcp": null,
30+ "relay_vlan": null,
31+ "name": "4000",
32+ "primary_rack": null,
33+ "secondary_rack": null,
34+ "fabric_id": 0,
35+ "id": 5017,
36+ "fabric": "fabric-0",
37+ "space": "undefined",
38+ "resource_uri": "/MAAS/api/2.0/vlans/5017/"
39+ },
40+ "vlan-read": {
41+ "vid": 10,
42+ "mtu": 1500,
43+ "dhcp_on": false,
44+ "external_dhcp": null,
45+ "relay_vlan": null,
46+ "fabric_id": 0,
47+ "name": "10",
48+ "primary_rack": "7xtf67",
49+ "space": "internal",
50+ "secondary_rack": "76y7pg",
51+ "id": 5002,
52+ "fabric": "fabric-0",
53+ "resource_uri": "/MAAS/api/2.0/vlans/5002/"
54+ },
55+ "vlan-update": {
56+ "vid": 0,
57+ "mtu": 1500,
58+ "dhcp_on": false,
59+ "external_dhcp": null,
60+ "relay_vlan": null,
61+ "id": 5001,
62+ "primary_rack": "7xtf67",
63+ "fabric_id": 0,
64+ "space": "management",
65+ "secondary_rack": "76y7pg",
66+ "name": "untagged",
67+ "fabric": "fabric-0",
68+ "resource_uri": "/MAAS/api/2.0/vlans/5001/"
69+ }
70+}
71diff --git a/src/maasserver/api/vlans.py b/src/maasserver/api/vlans.py
72index 9486a15..ad87e71 100644
73--- a/src/maasserver/api/vlans.py
74+++ b/src/maasserver/api/vlans.py
75@@ -45,30 +45,55 @@ class VlansHandler(OperationsHandler):
76 return ('vlans_handler', ["fabric_id"])
77
78 def read(self, request, fabric_id):
79- """List all VLANs belonging to fabric.
80+ """@description-title List VLANs
81+ @description List all VLANs belonging to given fabric.
82
83- Returns 404 if the fabric is not found.
84+ @param (int) "{fabric_id}" [required=true] The fabric for which to list
85+ the VLANs.
86+
87+ @success (http-status-code) "200" 200
88+ @success (json) "success-json" A JSON object containing a list of VLANs
89+ in the given fabric.
90+ @success-example "success-json" [exkey=vlan-list] placeholder text
91+
92+ @error (http-status-code) "404" 404
93+ @error (content) "not-found" The requested fabric_id is not found.
94+ @error-example "not-found"
95+ Not Found
96 """
97 fabric = Fabric.objects.get_fabric_or_404(
98 fabric_id, request.user, NodePermission.view)
99 return fabric.vlan_set.all()
100
101 def create(self, request, fabric_id):
102- """Create a VLAN.
103-
104- :param name: Name of the VLAN.
105- :type name: unicode
106- :param description: Description of the VLAN.
107- :type description: unicode
108- :param vid: VLAN ID of the VLAN.
109- :type vid: integer
110- :param mtu: The MTU to use on the VLAN.
111- :type mtu: integer
112- :param space: The space this VLAN should be placed in. Passing in an
113- empty string (or the string 'undefined') will cause the VLAN to be
114- placed in the 'undefined' space.
115- :type space: unicode
116+ """@description-title Create a VLAN
117+ @description Creates a new VLAN.
118+
119+ @param (int) "{fabric_id}" [required=true] The fabric_id on which to
120+ add the new VLAN.
121+
122+ @param (string) "name" [required=false] Name of the VLAN.
123+
124+ @param (string) "description" [required=false] Description of the new
125+ VLAN.
126+
127+ @param (int) "vid" [required=true] VLAN ID of the new VLAN.
128+
129+ @param (int) "mtu" [required=false] The MTU to use on the VLAN.
130
131+ @param (string) "space" [required=false] The space this VLAN should be
132+ placed in. Passing in an empty string (or the string 'undefined') will
133+ cause the VLAN to be placed in the 'undefined' space.
134+
135+ @success (http-status-code) "200" 200
136+ @success (json) "success-json" A JSON object containing information
137+ about the new VLAN.
138+ @success-example "success-json" [exkey=vlan-create] placeholder text
139+
140+ @error (http-status-code) "404" 404
141+ @error (content) "not-found" The requested fabric_id is not found.
142+ @error-example "not-found"
143+ Not Found
144 """
145 fabric = Fabric.objects.get_fabric_or_404(
146 fabric_id, request.user, NodePermission.admin)
147@@ -80,7 +105,7 @@ class VlansHandler(OperationsHandler):
148
149
150 class VlanHandler(OperationsHandler):
151- """Manage VLAN on a fabric."""
152+ """Manage a VLAN on a fabric."""
153 api_doc_section_name = "VLAN"
154 create = update = None
155 model = VLAN
156@@ -154,42 +179,73 @@ class VlanHandler(OperationsHandler):
157 return vlan
158
159 def read(self, request, **kwargs):
160- """Read VLAN on fabric.
161+ """@description-title Retrieve VLAN
162+ @description Retrieves a VLAN on a given fabric_id.
163+
164+ @param (int) "{fabric_id}" [required=true] The fabric_id containing the
165+ VLAN.
166+
167+ @param (int) "{vid}" [required=true] The VLAN ID.
168
169- Returns 404 if the fabric or VLAN is not found.
170+ @success (http-status-code) "200" 200
171+ @success (json) "success-json" A JSON object containing information
172+ about the requested VLAN.
173+ @success-example "success-json" [exkey=vlan-read] placeholder text
174+
175+ @error (http-status-code) "404" 404
176+ @error (content) "not-found" The requested fabric_id or vid is not
177+ found.
178+ @error-example "not-found"
179+ Not Found
180 """
181 vlan = self._get_vlan(request.user, NodePermission.view, **kwargs)
182 return vlan
183
184 def update(self, request, **kwargs):
185- """Update VLAN.
186-
187- :param name: Name of the VLAN.
188- :type name: unicode
189- :param description: Description of the VLAN.
190- :type description: unicode
191- :param vid: VLAN ID of the VLAN.
192- :type vid: integer
193- :param mtu: The MTU to use on the VLAN.
194- :type mtu: integer
195- :param dhcp_on: Whether or not DHCP should be managed on the VLAN.
196- :type dhcp_on: boolean
197- :param primary_rack: The primary rack controller managing the VLAN.
198- :type primary_rack: system_id
199- :param secondary_rack: The secondary rack controller manging the VLAN.
200- :type secondary_rack: system_id
201- :param relay_vlan: Only set when this VLAN will be using a DHCP relay
202- to forward DHCP requests to another VLAN that MAAS is or will run
203- the DHCP server. MAAS will not run the DHCP relay itself, it must
204- be configured to proxy reqests to the primary and/or secondary
205- rack controller interfaces for the VLAN specified in this field.
206- :type relay_vlan: ID of VLAN
207- :param space: The space this VLAN should be placed in. Passing in an
208- empty string (or the string 'undefined') will cause the VLAN to be
209- placed in the 'undefined' space.
210- :type space: unicode
211-
212- Returns 404 if the fabric or VLAN is not found.
213+ """@description-title Update VLAN
214+ @description Updates a given VLAN.
215+
216+ @param (int) "{fabric_id}" [required=true] Fabric ID containing the
217+ VLAN.
218+
219+ @param (int) "{vid}" [required=true] VLAN ID of the VLAN.
220+
221+ @param (string) "name" [required=false] Name of the VLAN.
222+
223+ @param (string) "description" [required=false] Description of the VLAN.
224+
225+ @param (int) "mtu" [required=false] The MTU to use on the VLAN.
226+
227+ @param (boolean) "dhcp_on" [required=false] Whether or not DHCP should
228+ be managed on the VLAN.
229+
230+ @param (string) "primary_rack" [required=false] The primary rack
231+ controller managing the VLAN (system_id).
232+
233+ @param (string) "secondary_rack" [required=false] The secondary rack
234+ controller managing the VLAN (system_id).
235+
236+ @param (int) "relay_vlan" [required=false] Relay VLAN ID. Only set when
237+ this VLAN will be using a DHCP relay to forward DHCP requests to
238+ another VLAN that MAAS is managing. MAAS will not run the DHCP relay
239+ itself, it must be configured to proxy reqests to the primary and/or
240+ secondary rack controller interfaces for the VLAN specified in this
241+ field.
242+
243+ @param (string) "space" [required=false] The space this VLAN should be
244+ placed in. Passing in an empty string (or the string 'undefined') will
245+ cause the VLAN to be placed in the 'undefined' space.
246+
247+ @success (http-status-code) "200" 200
248+ @success (json) "success-json" A JSON object containing information
249+ about the updated VLAN.
250+ @success-example "success-json" [exkey=vlan-update] placeholder text
251+
252+ @error (http-status-code) "404" 404
253+ @error (content) "not-found" The requested fabric_id or vid is not
254+ found.
255+ @error-example "not-found"
256+ Not Found
257 """
258 vlan = self._get_vlan(request.user, NodePermission.admin, **kwargs)
259 data = {}
260@@ -207,9 +263,21 @@ class VlanHandler(OperationsHandler):
261 raise MAASAPIValidationError(form.errors)
262
263 def delete(self, request, **kwargs):
264- """Delete VLAN on fabric.
265+ """@description-title Delete a VLAN
266+ @description Delete VLAN on a given fabric.
267+
268+ @param (int) "{fabric_id}" [required=true] Fabric ID containing the
269+ VLAN to delete.
270+
271+ @param (int) "{vid}" [required=true] VLAN ID of the VLAN to delete.
272+
273+ @success (http-status-code) "204" 204
274
275- Returns 404 if the fabric or VLAN is not found.
276+ @error (http-status-code) "404" 404
277+ @error (content) "not-found" The requested fabric_id or vid is not
278+ found.
279+ @error-example "not-found"
280+ Not Found
281 """
282 vlan = self._get_vlan(request.user, NodePermission.admin, **kwargs)
283 vlan.delete()

Subscribers

People subscribed via source and target branches