def test_cache_set_creation_with_block_device(self): node = factory.make_Node() cache_device = factory.make_PhysicalBlockDevice(node=node) form = CreateCacheSetForm(node=node, data={"cache_device": cache_device.id}) self.assertTrue(form.is_valid(), form.errors) cache_set = form.save() self.assertEqual(cache_device, cache_set.get_device())
def create_cache_set(self, params): """Create a cache set.""" node = self._get_node_or_permission_error(params) block_id = params.get('block_id') partition_id = params.get('partition_id') data = {} if partition_id is not None: data["cache_partition"] = partition_id elif block_id is not None: data["cache_device"] = block_id else: raise HandlerError("Either block_id or partition_id is required.") form = CreateCacheSetForm(node=node, data=data) if not form.is_valid(): raise HandlerError(form.errors) else: form.save()
def test_cache_set_creation_with_boot_disk(self): node = factory.make_Node(with_boot_disk=False) boot_disk = factory.make_PhysicalBlockDevice(node=node) form = CreateCacheSetForm(node=node, data={"cache_device": boot_disk.id}) self.assertTrue(form.is_valid(), form.errors) cache_set = form.save() boot_partition = boot_disk.get_partitiontable().partitions.first() self.assertEqual(boot_partition, cache_set.get_device())
def test_cache_set_creation_with_partition(self): node = factory.make_Node() block_device = factory.make_PhysicalBlockDevice(node=node) partition_table = factory.make_PartitionTable( block_device=block_device) partition = factory.make_Partition(partition_table=partition_table) form = CreateCacheSetForm(node=node, data={"cache_partition": partition.id}) self.assertTrue(form.is_valid(), form.errors) cache_set = form.save() self.assertEqual(partition, cache_set.get_device())
def create_cache_set(self, params): """Create a cache set.""" # Only admin users can perform delete. if not reload_object(self.user).is_superuser: raise HandlerPermissionError() node = self.get_object(params) block_id = params.get('block_id') partition_id = params.get('partition_id') data = {} if partition_id is not None: data["cache_partition"] = partition_id elif block_id is not None: data["cache_device"] = block_id else: raise HandlerError("Either block_id or partition_id is required.") form = CreateCacheSetForm(node=node, data=data) if not form.is_valid(): raise HandlerError(form.errors) else: form.save()
def create(self, request, system_id): """@description-title Creates a bcache cache set @description Creates a bcache cache set. Note: specifying both a cache_device and a cache_partition is not allowed. @param (string) "{system_id}" [required=true] A machine system_id. @param (string) "cache_device" [required=false] Cache block device. @param (string) "cache_partition" [required=false] Cache partition. @success (http-status-code) "server-success" 200 @success (json) "success-json" A JSON object containing the new bcache set. @success-example "success-json" [exkey=bcache-placeholder] 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. """ machine = Machine.objects.get_node_or_404(system_id, request.user, NodePermission.admin) if machine.status != NODE_STATUS.READY: raise NodeStateViolation( "Cannot create cache set because the node is not Ready.") form = CreateCacheSetForm(machine, data=request.data) if form.is_valid(): create_audit_event( EVENT_TYPES.NODE, ENDPOINT.API, request, system_id, "Created bcache cache set.", ) return form.save() else: raise MAASAPIValidationError(form.errors)
def create(self, request, system_id): """Creates a Bcache Cache Set. :param cache_device: Cache block device. :param cache_partition: Cache partition. Specifying both a cache_device and a cache_partition is not allowed. Returns 404 if the machine is not found. Returns 409 if the machine is not Ready. """ machine = Machine.objects.get_node_or_404(system_id, request.user, NODE_PERMISSION.ADMIN) if machine.status != NODE_STATUS.READY: raise NodeStateViolation( "Cannot create cache set because the node is not Ready.") form = CreateCacheSetForm(machine, data=request.data) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)
def create(self, request, system_id): """Creates a bcache Cache Set. :param cache_device: Cache block device. :param cache_partition: Cache partition. Specifying both a cache_device and a cache_partition is not allowed. Returns 404 if the machine is not found. Returns 409 if the machine is not Ready. """ machine = Machine.objects.get_node_or_404(system_id, request.user, NodePermission.admin) if machine.status != NODE_STATUS.READY: raise NodeStateViolation( "Cannot create cache set because the node is not Ready.") form = CreateCacheSetForm(machine, data=request.data) if form.is_valid(): create_audit_event(EVENT_TYPES.NODE, ENDPOINT.API, request, system_id, "Created bcache cache set.") return form.save() else: raise MAASAPIValidationError(form.errors)