~lutostag/ubuntu/trusty/maas/1.5.4+keystone

« back to all changes in this revision

Viewing changes to src/metadataserver/api.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-03-04 11:49:44 UTC
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20130304114944-azcvu9anlf8mizpa
Tags: upstream-1.3+bzr1452+dfsg
ImportĀ upstreamĀ versionĀ 1.3+bzr1452+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
__metaclass__ = type
13
13
__all__ = [
14
14
    'AnonMetaDataHandler',
 
15
    'CommissioningScriptsHandler',
15
16
    'IndexHandler',
16
17
    'MetaDataHandler',
17
18
    'UserDataHandler',
25
26
from django.core.exceptions import PermissionDenied
26
27
from django.http import HttpResponse
27
28
from django.shortcuts import get_object_or_404
28
 
from maasserver.api import (
 
29
from maasserver.api import store_node_power_parameters
 
30
from maasserver.api_support import (
 
31
    operation,
 
32
    OperationsHandler,
 
33
    )
 
34
from maasserver.api_utils import (
29
35
    extract_oauth_key,
30
36
    get_mandatory_param,
31
 
    operation,
32
 
    OperationsHandler,
33
 
    store_node_power_parameters,
34
37
    )
35
38
from maasserver.enum import (
36
39
    NODE_STATUS,
53
56
    )
54
57
from maasserver.utils import find_nodegroup
55
58
from maasserver.utils.orm import get_one
 
59
from metadataserver.enum import COMMISSIONING_STATUS
56
60
from metadataserver.models import (
 
61
    CommissioningScript,
57
62
    NodeCommissionResult,
58
63
    NodeKey,
59
64
    NodeUserData,
154
159
class VersionIndexHandler(MetadataViewHandler):
155
160
    """Listing for a given metadata version."""
156
161
    create = update = delete = None
157
 
    fields = ('meta-data', 'user-data')
 
162
    fields = ('maas-commissioning-scripts', 'meta-data', 'user-data')
158
163
 
159
164
    # States in which a node is allowed to signal commissioning status.
160
165
    # (Only in Commissioning state, however, will it have any effect.)
167
172
    # Statuses that a commissioning node may signal, and the respective
168
173
    # state transitions that they trigger on the node.
169
174
    signaling_statuses = {
170
 
        'OK': NODE_STATUS.READY,
171
 
        'FAILED': NODE_STATUS.FAILED_TESTS,
172
 
        'WORKING': None,
 
175
        COMMISSIONING_STATUS.OK: NODE_STATUS.READY,
 
176
        COMMISSIONING_STATUS.FAILED: NODE_STATUS.FAILED_TESTS,
 
177
        COMMISSIONING_STATUS.WORKING: None,
173
178
    }
174
179
 
175
180
    def read(self, request, version, mac=None):
185
190
 
186
191
    def _store_commissioning_results(self, node, request):
187
192
        """Store commissioning result files for `node`."""
 
193
        script_result = request.POST.get('script_result', None)
188
194
        for name, uploaded_file in request.FILES.items():
189
195
            raw_content = uploaded_file.read()
190
 
            if name == "01-lshw.out":
 
196
            if name == "00-maas-01-lshw.out":
191
197
                node.set_hardware_details(raw_content)
192
198
            contents = raw_content.decode('utf-8')
193
 
            NodeCommissionResult.objects.store_data(node, name, contents)
 
199
            NodeCommissionResult.objects.store_data(
 
200
                node, name, script_result, contents)
194
201
 
195
202
    @operation(idempotent=False)
196
203
    def signal(self, request, version=None, mac=None):
206
213
        :param status: A commissioning status code.  This can be "OK" (to
207
214
            signal that commissioning has completed successfully), or "FAILED"
208
215
            (to signal failure), or "WORKING" (for progress reports).
 
216
        :param script_result: If this call uploads files, this parameter must
 
217
            be provided and will be stored as the return value for the script
 
218
            which produced these files.
209
219
        :param error: An optional error string.  If given, this will be stored
210
220
            (overwriting any previous error string), and displayed in the MAAS
211
221
            UI.  If not given, any previous error string will be cleared.
212
222
        """
213
223
        node = get_queried_node(request, for_mac=mac)
214
 
        status = request.POST.get('status', None)
215
 
 
216
224
        status = get_mandatory_param(request.POST, 'status')
217
225
        if node.status not in self.signalable_states:
218
226
            raise NodeStateViolation(
339
347
            return HttpResponse(status=httplib.NOT_FOUND)
340
348
 
341
349
 
 
350
class CommissioningScriptsHandler(MetadataViewHandler):
 
351
    """Return a tar archive containing the commissioning scripts."""
 
352
 
 
353
    def read(self, request, version, mac=None):
 
354
        check_version(version)
 
355
        return HttpResponse(
 
356
            CommissioningScript.objects.get_archive(),
 
357
            mimetype='application/tar')
 
358
 
 
359
 
342
360
class EnlistMetaDataHandler(OperationsHandler):
343
361
    """this has to handle the 'meta-data' portion of the meta-data api
344
362
    for enlistment only.  It should mimic the read-only portion