def create_logical_volume(self, params): """Create a logical volume.""" # Only admin users can perform delete. if not reload_object(self.user).is_superuser: raise HandlerPermissionError() node = self.get_object(params) volume_group = VolumeGroup.objects.get(id=params['volume_group_id']) if volume_group.get_node() != node: raise VolumeGroup.DoesNotExist() form = CreateLogicalVolumeForm(volume_group, { 'name': params['name'], 'size': params['size'], }) if not form.is_valid(): raise HandlerError(form.errors) else: logical_volume = form.save() self._update_obj_tags(logical_volume, params) if 'fstype' in params: self.update_blockdevice_filesystem(logical_volume, params.get("fstype"), params.get("mount_point"), params.get("mount_options"))
def create_logical_volume(self, request, system_id, id): """@description-title Create a logical volume @description Create a logical volume in the volume group with the given id on the machine with the given system_id. @param (string) "{system_id}" [required=true] The machine system_id containing the volume group. @param (int) "{id}" [required=true] The id of the volume group. @param (string) "name" [required=true] Name of the logical volume. @param (string) "uuid" [required=false] (optional) UUID of the logical volume. @param (string) "size" [required=true] Size of the logical volume. Must be larger than or equal to 4,194,304 bytes. E.g. ``4194304``. @success (http-status-code) "server-success" 200 @success (json) "success-json" A JSON object containing the requested volume group. @success-example "success-json" [exkey=vol-groups-create-log-vol] placeholder text @error (http-status-code) "404" 404 @error (content) "not-found" The requested machine 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. """ volume_group = VolumeGroup.objects.get_object_or_404( system_id, id, request.user, NodePermission.admin ) node = volume_group.get_node() if node.status != NODE_STATUS.READY: raise NodeStateViolation( "Cannot create logical volume because the machine is not " "Ready." ) form = CreateLogicalVolumeForm(volume_group, data=request.data) if not form.is_valid(): raise MAASAPIValidationError(form.errors) else: return form.save()
def test_creates_logical_volume(self): volume_group = factory.make_VolumeGroup() name = factory.make_name("lv") vguuid = "%s" % uuid.uuid4() size = random.randint(MIN_BLOCK_DEVICE_SIZE, volume_group.get_size()) data = {"name": name, "uuid": vguuid, "size": size} form = CreateLogicalVolumeForm(volume_group, data=data) self.assertTrue(form.is_valid(), form._errors) logical_volume = form.save() expected_size = round_size_to_nearest_block( size, PARTITION_ALIGNMENT_SIZE, False ) self.assertThat( logical_volume, MatchesStructure.byEquality( name=name, uuid=vguuid, size=expected_size ), )
def create_logical_volume(self, params): """Create a logical volume.""" node = self._get_node_or_permission_error( params, permission=self._meta.edit_permission) volume_group = VolumeGroup.objects.get(id=params['volume_group_id']) if volume_group.get_node() != node: raise VolumeGroup.DoesNotExist() form = CreateLogicalVolumeForm( volume_group, { 'name': params['name'], 'size': params['size'], }) if not form.is_valid(): raise HandlerError(form.errors) else: logical_volume = form.save() self._update_obj_tags(logical_volume, params) if 'fstype' in params: self.update_blockdevice_filesystem( logical_volume, params.get("fstype"), params.get("mount_point"), params.get("mount_options"))
def create_logical_volume(self, request, system_id, id): """Create a logical volume in the volume group. :param name: Name of the logical volume. :param uuid: (optional) UUID of the logical volume. :param size: Size of the logical volume. Returns 404 if the machine or volume group is not found. Returns 409 if the machine is not Ready. """ volume_group = VolumeGroup.objects.get_object_or_404( system_id, id, request.user, NodePermission.admin) node = volume_group.get_node() if node.status != NODE_STATUS.READY: raise NodeStateViolation( "Cannot create logical volume because the machine is not " "Ready.") form = CreateLogicalVolumeForm(volume_group, data=request.data) if not form.is_valid(): raise MAASAPIValidationError(form.errors) else: return form.save()