def create_vmfs_datastore(self, params): """Create a VMFS datastore.""" node = self._get_node_or_permission_error( params, permission=self._meta.edit_permission) form = CreateVMFSForm(node, data=params) if not form.is_valid(): raise HandlerError(form.errors) else: form.save()
def test_creates_with_partitions_by_name(self): node = make_Node_with_VMFS6_layout() block_device = factory.make_PhysicalBlockDevice( node=node, size=(MIN_BLOCK_DEVICE_SIZE * 3) + PARTITION_TABLE_EXTRA_SPACE) partition_table = factory.make_PartitionTable( block_device=block_device) partitions = [ partition_table.add_partition(size=MIN_BLOCK_DEVICE_SIZE) for _ in range(2) ] partition_names = [ partition.name for partition in partitions ] data = { 'name': factory.make_name('name'), 'partitions': partition_names, } form = CreateVMFSForm(node, data=data) self.assertTrue(form.is_valid(), form._errors) volume_group = form.save() partitions_in_vg = [ filesystem.partition for filesystem in volume_group.filesystems.all() ] self.assertItemsEqual(partitions, partitions_in_vg)
def test_creates_with_partitions(self): node = make_Node_with_VMFS6_layout() block_device = factory.make_PhysicalBlockDevice( node=node, size=(MIN_BLOCK_DEVICE_SIZE * 3) + PARTITION_TABLE_EXTRA_SPACE) partition_table = factory.make_PartitionTable( block_device=block_device) partitions = [ partition_table.add_partition(size=MIN_BLOCK_DEVICE_SIZE) for _ in range(2) ] partition_ids = [ partition.id for partition in partitions ] data = { 'name': factory.make_name('name'), 'partitions': partition_ids, } form = CreateVMFSForm(node, data=data) self.assertTrue(form.is_valid(), form._errors) vmfs = form.save() self.assertItemsEqual( partition_ids, [fs.get_parent().id for fs in vmfs.filesystems.all()])
def create(self, request, system_id): """@description-title Create a VMFS datastore. @description Create a VMFS datastore belonging to a machine with the given system_id. Note that at least one valid block device or partition is required. @param (string) "{system_id}" [required=true] The machine system_id on which to create the VMFS datastore. @param (string) "name" [required=true] Name of the VMFS datastore. @param (string) "uuid" [required=false] (optional) UUID of the VMFS group. @param (string) "block_devices" [required=false] Block devices to add to the VMFS datastore. @param (string) "partitions" [required=false] Partitions to add to the VMFS datastore. @success (http-status-code) "server-success" 200 @success (json) "success-json" A JSON object containing the new VMFS datastore. @success-example "success-json" [exkey=vmfs-datastores-create] 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 VMFS group because the machine is not Ready." ) form = CreateVMFSForm(machine, data=request.data) if not form.is_valid(): raise MAASAPIValidationError(form.errors) else: return form.save()
def test_creates_volume_group_with_block_devices(self): node = make_Node_with_VMFS6_layout() block_devices = [ factory.make_PhysicalBlockDevice(node=node) for _ in range(3) ] block_device_ids = [block_device.id for block_device in block_devices] data = { "name": factory.make_name("name"), "block_devices": block_device_ids, } form = CreateVMFSForm(node, data=data) self.assertTrue(form.is_valid(), form._errors) vmfs = form.save() self.assertItemsEqual( block_device_ids, [ fs.get_parent().partition_table.block_device.id for fs in vmfs.filesystems.all() ], )
def test_creates_with_block_devices_by_name(self): node = make_Node_with_VMFS6_layout() block_devices = [ factory.make_PhysicalBlockDevice(node=node) for _ in range(3) ] block_device_names = [ block_device.name for block_device in block_devices ] data = { 'name': factory.make_name('name'), 'block_devices': block_device_names, } form = CreateVMFSForm(node, data=data) self.assertTrue(form.is_valid(), form._errors) vmfs = form.save() self.assertItemsEqual( [ block_device.id for block_device in block_devices ], [ fs.get_parent().partition_table.block_device.id for fs in vmfs.filesystems.all() ])