Merge ~jsseidel/maas:jsseidel-ip-ranges-api-annotations into maas:master

Proposed by Spencer Seidel
Status: Merged
Approved by: Spencer Seidel
Approved revision: e9211b7c5cdc17d0db7517bd98fa3e9bd11361d3
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~jsseidel/maas:jsseidel-ip-ranges-api-annotations
Merge into: maas:master
Diff against target: 338 lines (+274/-19)
2 files modified
src/maasserver/api/examples/ipranges.json (+188/-0)
src/maasserver/api/ipranges.py (+86/-19)
Reviewer Review Type Date Requested Status
MAAS Lander Needs Fixing
Newell Jensen (community) Approve
Review via email: mp+360953@code.launchpad.net

Commit message

Added API annotations and examples to ipranges.

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

Looks good.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b jsseidel-ip-ranges-api-annotations lp:~jsseidel/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/4720/console
COMMIT: e9211b7c5cdc17d0db7517bd98fa3e9bd11361d3

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b jsseidel-ip-ranges-api-annotations lp:~jsseidel/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/4731/consoleText

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/examples/ipranges.json b/src/maasserver/api/examples/ipranges.json
2new file mode 100644
3index 0000000..29e346e
4--- /dev/null
5+++ b/src/maasserver/api/examples/ipranges.json
6@@ -0,0 +1,188 @@
7+{
8+ "ipranges-read": [
9+ {
10+ "subnet": {
11+ "name": "name-rLI3eq",
12+ "vlan": {
13+ "vid": 0,
14+ "mtu": 1500,
15+ "dhcp_on": false,
16+ "external_dhcp": null,
17+ "relay_vlan": null,
18+ "name": "untagged",
19+ "space": "management",
20+ "secondary_rack": "fcka3t",
21+ "fabric_id": 0,
22+ "id": 5001,
23+ "fabric": "fabric-0",
24+ "primary_rack": "7xtf67",
25+ "resource_uri": "/MAAS/api/2.0/vlans/5001/"
26+ },
27+ "cidr": "172.16.1.0/24",
28+ "rdns_mode": 2,
29+ "gateway_ip": "172.16.1.1",
30+ "dns_servers": [
31+ "fd89:8724:81f1:5512:557f:99c3:6967:8d63"
32+ ],
33+ "allow_dns": true,
34+ "allow_proxy": true,
35+ "active_discovery": false,
36+ "managed": true,
37+ "space": "management",
38+ "id": 1,
39+ "resource_uri": "/MAAS/api/2.0/subnets/1/"
40+ },
41+ "type": "reserved",
42+ "start_ip": "172.16.1.200",
43+ "end_ip": "172.16.1.210",
44+ "user": {
45+ "is_superuser": true,
46+ "username": "admin",
47+ "email": "NN7ER2rH6x@example.com",
48+ "is_local": true,
49+ "resource_uri": "/MAAS/api/2.0/users/admin/"
50+ },
51+ "comment": "",
52+ "id": 1,
53+ "resource_uri": "/MAAS/api/2.0/ipranges/1/"
54+ }
55+ ],
56+ "ipranges-create": {
57+ "subnet": {
58+ "name": "name-rLI3eq",
59+ "vlan": {
60+ "vid": 0,
61+ "mtu": 1500,
62+ "dhcp_on": false,
63+ "external_dhcp": null,
64+ "relay_vlan": null,
65+ "name": "untagged",
66+ "space": "management",
67+ "secondary_rack": "fcka3t",
68+ "fabric_id": 0,
69+ "id": 5001,
70+ "fabric": "fabric-0",
71+ "primary_rack": "7xtf67",
72+ "resource_uri": "/MAAS/api/2.0/vlans/5001/"
73+ },
74+ "cidr": "172.16.1.0/24",
75+ "rdns_mode": 2,
76+ "gateway_ip": "172.16.1.1",
77+ "dns_servers": [
78+ "fd89:8724:81f1:5512:557f:99c3:6967:8d63"
79+ ],
80+ "allow_dns": true,
81+ "allow_proxy": true,
82+ "active_discovery": false,
83+ "managed": true,
84+ "space": "management",
85+ "id": 1,
86+ "resource_uri": "/MAAS/api/2.0/subnets/1/"
87+ },
88+ "type": "reserved",
89+ "start_ip": "172.16.1.200",
90+ "end_ip": "172.16.1.210",
91+ "user": {
92+ "is_superuser": true,
93+ "username": "admin",
94+ "email": "NN7ER2rH6x@example.com",
95+ "is_local": true,
96+ "resource_uri": "/MAAS/api/2.0/users/admin/"
97+ },
98+ "comment": "",
99+ "id": 1,
100+ "resource_uri": "/MAAS/api/2.0/ipranges/1/"
101+ },
102+ "ipranges-read-by-id": {
103+ "subnet": {
104+ "name": "name-rLI3eq",
105+ "vlan": {
106+ "vid": 0,
107+ "mtu": 1500,
108+ "dhcp_on": false,
109+ "external_dhcp": null,
110+ "relay_vlan": null,
111+ "id": 5001,
112+ "secondary_rack": "fcka3t",
113+ "fabric": "fabric-0",
114+ "fabric_id": 0,
115+ "name": "untagged",
116+ "space": "management",
117+ "primary_rack": "7xtf67",
118+ "resource_uri": "/MAAS/api/2.0/vlans/5001/"
119+ },
120+ "cidr": "172.16.1.0/24",
121+ "rdns_mode": 2,
122+ "gateway_ip": "172.16.1.1",
123+ "dns_servers": [
124+ "fd89:8724:81f1:5512:557f:99c3:6967:8d63"
125+ ],
126+ "allow_dns": true,
127+ "allow_proxy": true,
128+ "active_discovery": false,
129+ "managed": true,
130+ "id": 1,
131+ "space": "management",
132+ "resource_uri": "/MAAS/api/2.0/subnets/1/"
133+ },
134+ "type": "reserved",
135+ "start_ip": "172.16.1.200",
136+ "end_ip": "172.16.1.210",
137+ "user": {
138+ "is_superuser": true,
139+ "username": "admin",
140+ "email": "NN7ER2rH6x@example.com",
141+ "is_local": true,
142+ "resource_uri": "/MAAS/api/2.0/users/admin/"
143+ },
144+ "comment": "",
145+ "id": 1,
146+ "resource_uri": "/MAAS/api/2.0/ipranges/1/"
147+ },
148+ "ipranges-update": {
149+ "subnet": {
150+ "name": "name-rLI3eq",
151+ "vlan": {
152+ "vid": 0,
153+ "mtu": 1500,
154+ "dhcp_on": false,
155+ "external_dhcp": null,
156+ "relay_vlan": null,
157+ "id": 5001,
158+ "space": "management",
159+ "fabric_id": 0,
160+ "primary_rack": "7xtf67",
161+ "fabric": "fabric-0",
162+ "secondary_rack": "fcka3t",
163+ "name": "untagged",
164+ "resource_uri": "/MAAS/api/2.0/vlans/5001/"
165+ },
166+ "cidr": "172.16.1.0/24",
167+ "rdns_mode": 2,
168+ "gateway_ip": "172.16.1.1",
169+ "dns_servers": [
170+ "fd89:8724:81f1:5512:557f:99c3:6967:8d63"
171+ ],
172+ "allow_dns": true,
173+ "allow_proxy": true,
174+ "active_discovery": false,
175+ "managed": true,
176+ "id": 1,
177+ "space": "management",
178+ "resource_uri": "/MAAS/api/2.0/subnets/1/"
179+ },
180+ "type": "reserved",
181+ "start_ip": "172.16.1.200",
182+ "end_ip": "172.16.1.210",
183+ "user": {
184+ "is_superuser": true,
185+ "username": "admin",
186+ "email": "NN7ER2rH6x@example.com",
187+ "is_local": true,
188+ "resource_uri": "/MAAS/api/2.0/users/admin/"
189+ },
190+ "comment": "",
191+ "id": 1,
192+ "resource_uri": "/MAAS/api/2.0/ipranges/1/"
193+ }
194+}
195diff --git a/src/maasserver/api/ipranges.py b/src/maasserver/api/ipranges.py
196index 8f8477b..6565c6f 100644
197--- a/src/maasserver/api/ipranges.py
198+++ b/src/maasserver/api/ipranges.py
199@@ -43,19 +43,43 @@ class IPRangesHandler(OperationsHandler):
200 return ('ipranges_handler', [])
201
202 def read(self, request):
203- """List all IP ranges."""
204+ """@description-title List all IP ranges
205+ @description List all available IP ranges.
206+
207+ @success (http-status-code) "server-success" 200
208+ @success (json) "success-json" A JSON object containing a list of IP
209+ ranges.
210+ @success-example "success-json" [exkey=ipranges-read] placeholder text
211+ """
212 return IPRange.objects.all()
213
214 def create(self, request):
215- """Create an IP range.
216+ """@description-title Create an IP range
217+ @description Create a new IP range.
218+
219+ @param (string) "type" [required=true] Type of this range. (``dynamic``
220+ or ``reserved``)
221+
222+ @param (string) "start_ip" [required=true] Start IP address of this
223+ range (inclusive).
224+
225+ @param (string) "end_ip" [required=true] End IP address of this range
226+ (inclusive).
227
228- :param type: Type of this range. (`dynamic` or `reserved`)
229- :param start_ip: Start IP address of this range (inclusive).
230- :param end_ip: End IP address of this range (inclusive).
231- :param subnet: Subnet this range is associated with. (optional)
232- :param comment: A description of this range. (optional)
233+ @param (string) "subnet" [required=true] Subnet associated with this
234+ range.
235
236- Returns 403 if standard users tries to create a dynamic IP range.
237+ @param (string) "comment" [required=false] A description of this range.
238+
239+ @success (http-status-code) "server-success" 200
240+ @success (json) "success-json" A JSON object containing the new IP
241+ range.
242+ @success-example "success-json" [exkey=ipranges-create] placeholder
243+ text
244+
245+ @error (http-status-code) "403" 403
246+ @error (content) "no-perms" The user does not have the permissions
247+ required to create an IP range.
248 """
249 if ('type' in request.data and
250 request.data['type'] == IPRANGE_TYPE.DYNAMIC and
251@@ -87,22 +111,54 @@ class IPRangeHandler(OperationsHandler):
252 return ('iprange_handler', (iprange_id,))
253
254 def read(self, request, id):
255- """Read IP range.
256+ """@description-title Read an IP range
257+ @description Read an IP range with the given id.
258+
259+ @param (int) "{id}" [required=true] An IP range id.
260+
261+ @success (http-status-code) "server-success" 200
262+ @success (json) "success-json" A JSON object containing the requested
263+ IP range.
264+ @success-example "success-json" [exkey=ipranges-read-by-id] placeholder
265+ text
266
267- Returns 404 if the IP range is not found.
268+ @error (http-status-code) "404" 404
269+ @error (content) "not-found" The requested IP range is not found.
270+ @error-example "not-found"
271+ Not Found
272 """
273 iprange = IPRange.objects.get_iprange_or_404(id)
274 return iprange
275
276 def update(self, request, id):
277- """Update IP range.
278+ """@description-title Update an IP range
279+ @description Update an IP range with the given id.
280
281- :param start_ip: Start IP address of this range (inclusive).
282- :param end_ip: End IP address of this range (inclusive).
283- :param comment: A description of this range. (optional)
284+ @param (int) "{id}" [required=true] An IP range id.
285
286- Returns 403 if not owner of IP range.
287- Returns 404 if the IP Range is not found.
288+ @param (string) "start_ip" [required=false] Start IP address of this
289+ range (inclusive).
290+
291+ @param (string) "end_ip" [required=false] End IP address of this range
292+ (inclusive).
293+
294+ @param (string) "comment" [required=false] A description of this range.
295+ (optional)
296+
297+ @success (http-status-code) "server-success" 200
298+ @success (json) "success-json" A JSON object containing the requested
299+ IP range.
300+ @success-example "success-json" [exkey=ipranges-update] placeholder
301+ text
302+
303+ @error (http-status-code) "403" 403
304+ @error (content) "no-perms" The user does not have the permissions
305+ required to update the IP range.
306+
307+ @error (http-status-code) "404" 404
308+ @error (content) "not-found" The requested IP range is not found.
309+ @error-example "not-found"
310+ Not Found
311 """
312 iprange = IPRange.objects.get_iprange_or_404(id)
313 raise_error_if_not_owner(iprange, request.user)
314@@ -113,10 +169,21 @@ class IPRangeHandler(OperationsHandler):
315 raise MAASAPIValidationError(form.errors)
316
317 def delete(self, request, id):
318- """Delete IP range.
319+ """@description-title Delete an IP range
320+ @description Delete an IP range with the given id.
321+
322+ @param (int) "{id}" [required=true] An IP range id.
323+
324+ @success (http-status-code) "server-success" 204
325+
326+ @error (http-status-code) "403" 403
327+ @error (content) "no-perms" The user does not have the permissions
328+ required to delete the IP range.
329
330- Returns 403 if not owner of IP range.
331- Returns 404 if the IP range is not found.
332+ @error (http-status-code) "404" 404
333+ @error (content) "not-found" The requested IP range is not found.
334+ @error-example "not-found"
335+ Not Found
336 """
337 iprange = IPRange.objects.get_iprange_or_404(id)
338 raise_error_if_not_owner(iprange, request.user)

Subscribers

People subscribed via source and target branches