Example #1
0
def global_options(context):
    return {
        'persistent_errors': get_persistent_errors(),
        'node_form': get_node_edit_form(context.user)(),
        'POWER_TYPE_PARAMETERS_FIELDS':
            [(power_type, field.widget.render('power_parameters', []))
                for power_type, field in POWER_TYPE_PARAMETERS.items()
                if power_type is not POWER_TYPE.DEFAULT],
        'global_options': {
            'site_name': Config.objects.get_config('maas_name'),
        }
    }
Example #2
0
    def start(self, request, system_id):
        """Power up a node.

        :param user_data: If present, this blob of user-data to be made
            available to the nodes through the metadata service.
        :type user_data: base64-encoded unicode
        :param distro_series: If present, this parameter specifies the
            OS release the node will use.
        :type distro_series: unicode

        Ideally we'd have MIME multipart and content-transfer-encoding etc.
        deal with the encapsulation of binary data, but couldn't make it work
        with the framework in reasonable time so went for a dumb, manual
        encoding instead.

        Returns 404 if the node is not found.
        Returns 403 if the user does not have permission to stop the node.
        Returns 503 if the start-up attempted to allocate an IP address,
        and there were no IP addresses available on the relevant cluster
        interface.
        """
        user_data = request.POST.get('user_data', None)
        series = request.POST.get('distro_series', None)
        license_key = request.POST.get('license_key', None)

        node = Node.objects.get_node_or_404(
            system_id=system_id, user=request.user,
            perm=NODE_PERMISSION.EDIT)

        if user_data is not None:
            user_data = b64decode(user_data)
        if series is not None or license_key is not None:
            Form = get_node_edit_form(request.user)
            form = Form(instance=node)
            if series is not None:
                form.set_distro_series(series=series)
            if license_key is not None:
                form.set_license_key(license_key=license_key)
            if form.is_valid():
                form.save()
            else:
                raise ValidationError(form.errors)

        try:
            node.start(request.user, user_data=user_data)
        except StaticIPAddressExhaustion:
            # The API response should contain error text with the
            # system_id in it, as that is the primary API key to a node.
            raise StaticIPAddressExhaustion(
                "%s: Unable to allocate static IP due to address"
                " exhaustion." % system_id)
        return node
Example #3
0
def global_options(context):
    return {
        'persistent_errors':
        get_persistent_errors(),
        'node_form':
        get_node_edit_form(context.user)(),
        'POWER_TYPE_PARAMETERS_FIELDS':
        [(power_type, field.widget.render('power_parameters', []))
         for power_type, field in POWER_TYPE_PARAMETERS.items()
         if power_type is not POWER_TYPE.DEFAULT],
        'global_options': {
            'site_name': Config.objects.get_config('maas_name'),
        }
    }
Example #4
0
    def update(self, request, system_id):
        """Update a specific Node.

        :param hostname: The new hostname for this node.
        :type hostname: unicode
        :param architecture: The new architecture for this node.
        :type architecture: unicode
        :param power_type: The new power type for this node. If you use the
            default value, power_parameters will be set to the empty string.
            Available to admin users.
            See the `Power types`_ section for a list of the available power
            types.
        :type power_type: unicode
        :param power_parameters_{param1}: The new value for the 'param1'
            power parameter.  Note that this is dynamic as the available
            parameters depend on the selected value of the Node's power_type.
            For instance, if the power_type is 'ether_wake', the only valid
            parameter is 'power_address' so one would want to pass 'myaddress'
            as the value of the 'power_parameters_power_address' parameter.
            Available to admin users.
            See the `Power types`_ section for a list of the available power
            parameters for each power type.
        :type power_parameters_{param1}: unicode
        :param power_parameters_skip_check: Whether or not the new power
            parameters for this node should be checked against the expected
            power parameters for the node's power type ('true' or 'false').
            The default is 'false'.
        :type power_parameters_skip_check: unicode
        :param zone: Name of a valid physical zone in which to place this node
        :type zone: unicode
        :param boot_type: The installation type of the node. 'fastpath': use
            the default installer. 'di' use the debian installer.
            Note that using 'di' is now deprecated and will be removed in favor
            of the default installer in MAAS 1.9.
        :type boot_type: unicode

        Returns 404 if the node is node found.
        Returns 403 if the user does not have permission to update the node.
        """
        node = Node.objects.get_node_or_404(
            system_id=system_id, user=request.user, perm=NODE_PERMISSION.EDIT)
        Form = get_node_edit_form(request.user)
        form = Form(data=request.data, instance=node)
        if form.is_valid():
            return form.save()
        else:
            raise ValidationError(form.errors)
Example #5
0
 def test_get_node_edit_form_returns_AdminNodeForm_if_admin(self):
     admin = factory.make_admin()
     self.assertEqual(AdminNodeForm, get_node_edit_form(admin))
Example #6
0
 def test_get_node_edit_form_returns_NodeForm_if_non_admin(self):
     user = factory.make_User()
     self.assertEqual(NodeForm, get_node_edit_form(user))
Example #7
0
 def get_form_class(self):
     return get_node_edit_form(self.request.user)
Example #8
0
 def get_form_class(self):
     return get_node_edit_form(self.request.user)
Example #9
0
 def test_get_node_edit_form_returns_APIAdminNodeEdit_if_admin(self):
     admin = factory.make_admin()
     self.assertEqual(AdminNodeForm, get_node_edit_form(admin))
Example #10
0
 def test_get_node_edit_form_returns_NodeForm_if_non_admin(self):
     user = factory.make_user()
     self.assertEqual(NodeForm, get_node_edit_form(user))