コード例 #1
0
    def test_changes_device_parent(self):
        device = factory.make_Device()
        parent = factory.make_Node()

        form = DeviceForm(data={"parent": parent.system_id}, instance=device)
        form.save()
        reload_object(device)
        reload_object(parent)

        self.assertEqual(parent, device.parent)
コード例 #2
0
    def update(self, request, system_id):
        """Update a specific device.

        :param hostname: The new hostname for this device.
        :type hostname: unicode

        :param domain: The domain for this device.
        :type domain: unicode

        :param parent: Optional system_id to indicate this device's parent.
            If the parent is already set and this parameter is omitted,
            the parent will be unchanged.
        :type parent: unicode

        :param zone: Name of a valid physical zone in which to place this
            node.
        :type zone: unicode

        Returns 404 if the device is not found.
        Returns 403 if the user does not have permission to update the device.
        """
        device = self.model.objects.get_node_or_404(system_id=system_id,
                                                    user=request.user,
                                                    perm=NODE_PERMISSION.EDIT)
        form = DeviceForm(data=request.data, instance=device)

        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
コード例 #3
0
ファイル: devices.py プロジェクト: th3architect/maas
    def update(self, request, system_id):
        """@description-title Update a device
        @description Update a device with a given system_id.

        @param (string) "{system_id}" [required=true] A device system_id.

        @param (string) "hostname" [required=false] The hostname for this
        device.

        @param (string) "description" [required=false] The optional description
        for this machine.

        @param (string) "domain" [required=false] The domain for this device.

        @param (string) "parent" [required=false] Optional system_id to
        indicate this device's parent. If the parent is already set and this
        parameter is omitted, the parent will be unchanged.

        @param (string) "zone" [required=false] Name of a valid physical zone
        in which to place this node.

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing the updated
        device.
        @success-example "success-json" [exkey=devices-update] placeholder text

        @error (http-status-code) "403" 403
        @error (content) "no-perms" The user does not have the permissions
        required to update the device.

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested device is not found.
        @error-example "not-found"
            Not Found
        """
        device = self.model.objects.get_node_or_404(
            system_id=system_id, user=request.user, perm=NodePermission.edit
        )
        form = DeviceForm(data=request.data, instance=device)

        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)