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

« back to all changes in this revision

Viewing changes to src/maasserver/api/tags.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:
20
20
 
21
21
import httplib
22
22
 
23
 
from django.core.exceptions import (
24
 
    PermissionDenied,
25
 
    ValidationError,
26
 
    )
 
23
from django.core.exceptions import PermissionDenied
27
24
from django.db.utils import DatabaseError
28
25
from django.http import HttpResponse
29
26
from maasserver.api.node_groups import check_nodegroup_access
33
30
    )
34
31
from maasserver.api.utils import get_list_from_dict_or_multidict
35
32
from maasserver.enum import NODE_PERMISSION
 
33
from maasserver.exceptions import MAASAPIValidationError
36
34
from maasserver.forms import TagForm
37
35
from maasserver.models import (
38
36
    Node,
62
60
        )
63
61
 
64
62
    def read(self, request, name):
65
 
        """Read a specific Tag"""
 
63
        """Read a specific Tag.
 
64
 
 
65
        Returns 404 if the tag is not found.
 
66
        """
66
67
        return Tag.objects.get_tag_or_404(name=name, user=request.user)
67
68
 
68
69
    def update(self, request, name):
74
75
            It is meant as a human readable description of the tag.
75
76
        :param definition: An XPATH query that will be evaluated against the
76
77
            hardware_details stored for all nodes (output of `lshw -xml`).
 
78
 
 
79
        Returns 404 if the tag is not found.
77
80
        """
78
81
        tag = Tag.objects.get_tag_or_404(
79
82
            name=name, user=request.user, to_edit=True)
84
87
                new_tag.save()
85
88
                form.save_m2m()
86
89
            except DatabaseError as e:
87
 
                raise ValidationError(e)
 
90
                raise MAASAPIValidationError(e)
88
91
            return new_tag
89
92
        else:
90
 
            raise ValidationError(form.errors)
 
93
            raise MAASAPIValidationError(form.errors)
91
94
 
92
95
    def delete(self, request, name):
93
 
        """Delete a specific Tag."""
 
96
        """Delete a specific Tag.
 
97
 
 
98
        Returns 404 if the tag is not found.
 
99
        Returns 204 if the tag is successfully deleted.
 
100
        """
94
101
        tag = Tag.objects.get_tag_or_404(
95
102
            name=name, user=request.user, to_edit=True)
96
103
        tag.delete()
98
105
 
99
106
    @operation(idempotent=True)
100
107
    def nodes(self, request, name):
101
 
        """Get the list of nodes that have this tag."""
 
108
        """Get the list of nodes that have this tag.
 
109
 
 
110
        Returns 404 if the tag is not found.
 
111
        """
102
112
        tag = Tag.objects.get_tag_or_404(name=name, user=request.user)
103
113
        return Node.objects.get_nodes(
104
114
            request.user, NODE_PERMISSION.VIEW, from_nodes=tag.node_set.all())
120
130
        This is considered a maintenance operation, which should normally not
121
131
        be necessary. Adding nodes or updating a tag's definition should
122
132
        automatically trigger the appropriate changes.
 
133
 
 
134
        Returns 404 if the tag is not found.
123
135
        """
124
136
        tag = Tag.objects.get_tag_or_404(name=name, user=request.user,
125
137
                                         to_edit=True)
141
153
            supplied, then the requester must be the worker associated with
142
154
            that nodegroup, and only nodes that are part of that nodegroup can
143
155
            be updated.
 
156
 
 
157
        Returns 404 if the tag is not found.
 
158
        Returns 401 if the user does not have permission to update the nodes.
 
159
        Returns 409 if 'definition' doesn't match the current definition.
144
160
        """
145
161
        tag = Tag.objects.get_tag_or_404(name=name, user=request.user)
146
162
        nodegroup = None
196
212
            value overrides the global 'kernel_opts' setting. If more than one
197
213
            tag is associated with a node, the one with the lowest alphabetical
198
214
            name will be picked (eg 01-my-tag will be taken over 99-tag-name).
 
215
 
 
216
        Returns 401 if the user is not an admin.
199
217
        """
200
218
        if not request.user.is_superuser:
201
219
            raise PermissionDenied()
203
221
        if form.is_valid():
204
222
            return form.save()
205
223
        else:
206
 
            raise ValidationError(form.errors)
 
224
            raise MAASAPIValidationError(form.errors)
207
225
 
208
226
    @operation(idempotent=True)
209
227
    def list(self, request):