~allenap/maas/rpc-write-dns-config

« back to all changes in this revision

Viewing changes to src/maasserver/api/node_groups.py

  • Committer: Gavin Panella
  • Date: 2014-12-05 12:48:56 UTC
  • mfrom: (3415.1.1 celery-in-dns-removal)
  • Revision ID: gavin.panella@canonical.com-20141205124856-9fxsma5y002newcu
Merged celery-in-dns-removal into rpc-write-dns-config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import httplib
22
22
 
23
23
import bson
24
 
from django.core.exceptions import (
25
 
    PermissionDenied,
26
 
    ValidationError,
27
 
    )
 
24
from django.core.exceptions import PermissionDenied
28
25
from django.http import HttpResponse
29
26
from django.shortcuts import get_object_or_404
30
27
from formencode import validators
43
40
from maasserver.clusterrpc.power_parameters import (
44
41
    get_all_power_types_from_clusters,
45
42
    )
46
 
from maasserver.exceptions import Unauthorized
 
43
from maasserver.exceptions import (
 
44
    MAASAPIValidationError,
 
45
    Unauthorized,
 
46
    )
47
47
from maasserver.forms import (
48
48
    DownloadProgressForm,
49
49
    NodeGroupEdit,
92
92
        :param uuid: The UUID (or list of UUIDs) of the nodegroup(s) to accept.
93
93
        :type name: unicode (or list of unicodes)
94
94
 
95
 
        This method is reserved to admin users.
 
95
        This method is reserved to admin users and returns 403 if the
 
96
        user is not an admin.
 
97
 
 
98
        Returns 404 if the nodegroup (cluster) is not found.
96
99
        """
97
100
        uuids = request.data.getlist('uuid')
98
101
        for uuid in uuids:
125
128
        :param uuid: The UUID (or list of UUIDs) of the nodegroup(s) to reject.
126
129
        :type name: unicode (or list of unicodes)
127
130
 
128
 
        This method is reserved to admin users.
 
131
        This method is reserved to admin users and returns 403 if the
 
132
        user is not an admin.
 
133
 
 
134
        Returns 404 if the nodegroup (cluster) is not found.
129
135
        """
130
136
        uuids = request.data.getlist('uuid')
131
137
        for uuid in uuids:
173
179
    fields = DISPLAYED_NODEGROUP_FIELDS
174
180
 
175
181
    def read(self, request, uuid):
176
 
        """GET a node group."""
 
182
        """GET a node group.
 
183
 
 
184
        Returns 404 if the nodegroup (cluster) is not found.
 
185
        """
177
186
        return get_object_or_404(NodeGroup, uuid=uuid)
178
187
 
179
188
    @classmethod
195
204
        :param status: The new status for this cluster (see
196
205
            vocabulary `NODEGROUP_STATUS`).
197
206
        :type status: int
 
207
 
 
208
        Returns 404 if the nodegroup (cluster) is not found.
198
209
        """
199
210
        nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
200
211
        form = NodeGroupEdit(instance=nodegroup, data=request.data)
201
212
        if form.is_valid():
202
213
            return form.save()
203
214
        else:
204
 
            raise ValidationError(form.errors)
 
215
            raise MAASAPIValidationError(form.errors)
205
216
 
206
217
    @admin_method
207
218
    @operation(idempotent=False)
208
219
    def import_boot_images(self, request, uuid):
209
 
        """Import the pxe files on this cluster controller."""
 
220
        """Import the pxe files on this cluster controller.
 
221
 
 
222
        Returns 404 if the nodegroup (cluster) is not found.
 
223
        """
210
224
        nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
211
225
        nodegroup.import_boot_images()
212
226
        return HttpResponse(
215
229
 
216
230
    @operation(idempotent=True)
217
231
    def list_nodes(self, request, uuid):
218
 
        """Get the list of node ids that are part of this group."""
 
232
        """Get the list of node ids that are part of this group.
 
233
 
 
234
        Returns 404 if the nodegroup (cluster) is not found.
 
235
        """
219
236
        nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
220
237
        if not request.user.is_superuser:
221
238
            check_nodegroup_access(request, nodegroup)
250
267
        b) Requests for nodes that are not part of the nodegroup are
251
268
           just ignored.
252
269
 
 
270
        Returns 404 if the nodegroup (cluster) is not found.
 
271
        Returns 403 if the user does not have access to the nodegroup.
253
272
        """
254
273
        nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
255
274
        if not request.user.is_superuser:
318
337
        :param error: Optional error string.  A download that has submitted an
319
338
            error with its last progress report is considered to have failed.
320
339
        :type error: unicode
 
340
 
 
341
        Returns 404 if the nodegroup (cluster) is not found.
 
342
        Returns 403 if the user does not have access to the nodegroup.
 
343
        Returns 400 if the required parameters were not passed.
321
344
        """
322
345
        nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
323
346
        check_nodegroup_access(request, nodegroup)
333
356
 
334
357
        form = DownloadProgressForm(data=request.data, instance=download)
335
358
        if not form.is_valid():
336
 
            raise ValidationError(form.errors)
 
359
            raise MAASAPIValidationError(form.errors)
337
360
        form.save()
338
361
 
339
362
        return HttpResponse(status=httplib.OK)
372
395
        :param power_pass: The password to use, when qemu+ssh is given as a
373
396
            connection string and ssh key authentication is not being used.
374
397
        :type power_pass: unicode
 
398
 
 
399
        Returns 404 if the nodegroup (cluster) is not found.
 
400
        Returns 403 if the user does not have access to the nodegroup.
 
401
        Returns 400 if the required parameters were not passed.
375
402
        """
376
403
        nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
377
404
 
409
436
        :param password: The password for the API.
410
437
        :type password: unicode
411
438
 
 
439
        Returns 404 if the nodegroup (cluster) is not found.
 
440
        Returns 403 if the user does not have access to the nodegroup.
 
441
        Returns 400 if the required parameters were not passed.
412
442
        """
413
443
        nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
414
444
 
432
462
        :param password: The password for the MSCM.
433
463
        :type password: unicode
434
464
 
 
465
        Returns 404 if the nodegroup (cluster) is not found.
 
466
        Returns 403 if the user does not have access to the nodegroup.
 
467
        Returns 400 if the required parameters were not passed.
435
468
        """
436
469
        nodegroup = get_object_or_404(NodeGroup, uuid=uuid)
437
470