Esempio n. 1
0
    def update(self, request, system_id, id):
        """Update RAID on a machine.

        :param name: Name of the RAID.
        :param uuid: UUID of the RAID.
        :param add_block_devices: Block devices to add to the RAID.
        :param remove_block_devices: Block devices to remove from the RAID.
        :param add_spare_devices: Spare block devices to add to the RAID.
        :param remove_spare_devices: Spare block devices to remove
               from the RAID.
        :param add_partitions: Partitions to add to the RAID.
        :param remove_partitions: Partitions to remove from the RAID.
        :param add_spare_partitions: Spare partitions to add to the RAID.
        :param remove_spare_partitions: Spare partitions to remove from the
               RAID.

        Returns 404 if the machine or RAID is not found.
        Returns 409 if the machine is not Ready.
        """
        raid = RAID.objects.get_object_or_404(system_id, id, request.user,
                                              NodePermission.admin)
        node = raid.get_node()
        if node.status != NODE_STATUS.READY:
            raise NodeStateViolation(
                "Cannot update RAID because the machine is not Ready.")
        form = UpdateRaidForm(raid, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
Esempio n. 2
0
 def test_add_valid_spare_boot_disk(self):
     node = factory.make_Node(with_boot_disk=False)
     boot_disk = factory.make_PhysicalBlockDevice(node=node)
     raid = factory.make_FilesystemGroup(
         group_type=FILESYSTEM_GROUP_TYPE.RAID_6, node=node)
     raid = RAID.objects.get(id=raid.id)
     form = UpdateRaidForm(raid, data={'add_spare_devices': [boot_disk.id]})
     self.assertTrue(form.is_valid(), form.errors)
     raid = form.save()
     boot_partition = boot_disk.get_partitiontable().partitions.first()
     self.assertEqual(
         boot_partition.get_effective_filesystem().filesystem_group.id,
         raid.id)
Esempio n. 3
0
    def update(self, request, system_id, id):
        """@description-title Update a RAID
        @description Update a RAID with the given id on a machine with the
        given system_id.

        @param (string) "{system_id}" [required=true] The system_id of the
        machine containing the RAID.
        @param (int) "{id}" [required=true] A RAID id.

        @param (string) "name" [required=false] Name of the RAID.

        @param (string) "uuid" [required=false] UUID of the RAID.

        @param (string) "add_block_devices" [required=false] Block devices to
        add to the RAID.

        @param (string) "remove_block_devices" [required=false] Block devices
        to remove from the RAID.

        @param (string) "add_spare_devices" [required=false] Spare block
        devices to add to the RAID.

        @param (string) "remove_spare_devices" [required=false] Spare block
        devices to remove from the RAID.

        @param (string) "add_partitions" [required=false] Partitions to add to
        the RAID.

        @param (string) "remove_partitions" [required=false] Partitions to
        remove from the RAID.

        @param (string) "add_spare_partitions" [required=false] Spare
        partitions to add to the RAID.

        @param (string) "remove_spare_partitions" [required=false] Spare
        partitions to remove from the RAID.

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

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested machine or RAID id is not
        found.
        @error-example "not-found"
            Not Found

        @error (http-status-code) "409" 409
        @error (content) "not-ready" The requested machine is not ready.
        """
        raid = RAID.objects.get_object_or_404(system_id, id, request.user,
                                              NodePermission.admin)
        node = raid.get_node()
        if node.status != NODE_STATUS.READY:
            raise NodeStateViolation(
                "Cannot update RAID because the machine is not Ready.")
        form = UpdateRaidForm(raid, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)