Exemple #1
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)
Exemple #2
0
 def test_has_perm_rbac_permission_on_pool(self):
     rbac = self.useFixture(RBACEnabled())
     user = factory.make_User()
     rbac.store.allow(user.username, factory.make_ResourcePool(),
                      "admin-machines")
     form = DeviceForm()
     self.assertTrue(form.has_perm(user))
Exemple #3
0
 def test_has_perm_rbac_read_permission_on_pool(self):
     rbac = self.useFixture(RBACEnabled())
     user = factory.make_User()
     rbac.store.allow(
         user.username, factory.make_ResourcePool(), 'view')
     form = DeviceForm()
     self.assertFalse(form.has_perm(user))
Exemple #4
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)
Exemple #5
0
    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)
Exemple #6
0
    def test_contains_limited_set_of_fields(self):
        form = DeviceForm()

        self.assertItemsEqual([
            'hostname',
            'domain',
            'parent',
            'disable_ipv4',
            'swap_size',
            'zone',
        ], list(form.fields))
Exemple #7
0
    def test_contains_limited_set_of_fields(self):
        form = DeviceForm()

        self.assertItemsEqual(
            [
                "hostname",
                "description",
                "domain",
                "parent",
                "disable_ipv4",
                "swap_size",
                "zone",
            ],
            list(form.fields),
        )
Exemple #8
0
 def test_has_perm_rbac_global_admin(self):
     self.useFixture(RBACEnabled())
     user = factory.make_admin()
     form = DeviceForm()
     self.assertTrue(form.has_perm(user))
Exemple #9
0
 def test_has_perm_rbac_no_permision(self):
     self.useFixture(RBACEnabled())
     form = DeviceForm()
     self.assertFalse(form.has_perm(factory.make_User()))
Exemple #10
0
 def test_has_perm_no_rbac(self):
     form = DeviceForm()
     self.assertTrue(form.has_perm(factory.make_User()))