public static void validateAdd(Cdrom cdrom) { if (cdrom == null) { throw new ValidationException("Parameter 'cdrom' is mandatory but was not provided."); } if (cdrom.getFile()==null || cdrom.getFile().getId()==null) { throw new ValidationException("Parameter 'cdrom.file.id' is mandatory but was not provided."); } }
/** * Bi-directional Cdrom->VmTemplate not required as * template device collections are always read-only */ @Mapping(from = VmTemplate.class, to = Cdrom.class) public static Cdrom map(VmTemplate entity, Cdrom template) { Cdrom model = template != null ? template : new Cdrom(); model.setId(CDROM_ID.toString()); if (!StringUtils.isEmpty(entity.getIsoPath())) { model.setFile(new File()); model.getFile().setId(entity.getIsoPath()); } return model; } }
@Mapping(from = VM.class, to = Cdrom.class) public static Cdrom map(VM entity, Cdrom template) { Cdrom model = template != null ? template : new Cdrom(); model.setId(CDROM_ID.toString()); if (!StringUtils.isEmpty(entity.getStaticData().getIsoPath())) { model.setFile(new File()); model.getFile().setId(entity.getStaticData().getIsoPath()); } return model; }
private Cdrom getCdrom(String path) { Cdrom cdrom = new Cdrom(); cdrom.setFile(new File()); cdrom.getFile().setId(path); return cdrom; }
private Cdrom getCdrom() { Cdrom model = new Cdrom(); model.setFile(new File()); model.getFile().setId(ISO_PATH); return model; }
@Override public Cdrom update(Cdrom cdrom) { validateParameters(cdrom, "file"); boolean current = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, CURRENT, true, false); if (current) { ChangeDiskCommandParameters parameters = new ChangeDiskCommandParameters(vmId, cdrom.getFile().getId()); performAction(ActionType.ChangeDisk, parameters); } else { VM vm = getVm(); vm = map(cdrom, vm); VmManagementParametersBase parameters = new VmManagementParametersBase(vm); performAction(ActionType.UpdateVm, parameters); } return get(); }
@Test public void testEjectCd() { UriInfo uriInfo = setUpBasicUriExpectations(); uriInfo = addMatrixParameterExpectations(uriInfo, "current"); setUriInfo(uriInfo); setUpEntityQueryExpectations(getVm(A_ISO, NO_ISO, VMStatus.Up)); setUpActionExpectations( ActionType.ChangeDisk, ChangeDiskCommandParameters.class, new String[] { "CdImagePath" }, new Object[] { NO_ISO }, true, true ); Cdrom cdrom = getCdrom(NO_ISO); cdrom = resource.update(cdrom); assertNull(cdrom.getFile()); }
private void verifyModel(Cdrom model) { assertEquals(Guid.Empty.toString(), model.getId()); assertTrue(model.isSetTemplate()); assertEquals(TEMPLATE_ID.toString(), model.getTemplate().getId()); assertTrue(model.isSetFile()); assertEquals(ISO_PATH, model.getFile().getId()); } }
private static void verifyModelWithIso(Cdrom model, String isoPath) { assertEquals(Guid.Empty.toString(), model.getId()); assertTrue(model.isSetVm()); assertEquals(VM_ID.toString(), model.getVm().getId()); assertTrue(model.isSetFile()); assertEquals(isoPath, model.getFile().getId()); } }
private static void verifyModelWithIso(Cdrom model, String isoPath) { assertEquals(Guid.Empty.toString(), model.getId()); assertTrue(model.isSetVm()); assertEquals(VM_ID.toString(), model.getVm().getId()); assertTrue(model.isSetFile()); assertEquals(isoPath, model.getFile().getId()); } }
private void verifyModel(Cdrom model) { assertEquals(Guid.Empty.toString(), model.getId()); assertTrue(model.isSetTemplate()); assertEquals(TEMPLATE_ID.toString(), model.getTemplate().getId()); assertTrue(model.isSetFile()); assertEquals(ISO_PATH, model.getFile().getId()); verifyLinks(model); } }
@Test public void testStartWithCdRomAndFloppy() { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId", "DiskPath", "FloppyPath" }, new Object[] { GUIDS[0], ISO_ID, FLOPPY_ID })); Action action = new Action(); action.setVm(new Vm()); action.getVm().setCdroms(new Cdroms()); action.getVm().getCdroms().getCdroms().add(new Cdrom()); action.getVm().getCdroms().getCdroms().get(0).setFile(new File()); action.getVm().getCdroms().getCdroms().get(0).getFile().setId(ISO_ID); action.getVm().setFloppies(new Floppies()); action.getVm().getFloppies().getFloppies().add(new Floppy()); action.getVm().getFloppies().getFloppies().get(0).setFile(new File()); action.getVm().getFloppies().getFloppies().get(0).getFile().setId(FLOPPY_ID); verifyActionResponse(resource.start(action)); }
to.setFile(adaptOut(from.getFile()));
String file = vm.getCdroms().getCdroms().get(0).getFile().getId(); if (file != null) { params.setDiskPath(file);