public static void validateClone(Action action) { if (action == null) { throw new ValidationException("Action is mandatory but was not provided."); } if (action.getVm()==null || action.getVm().getName()==null) { throw new ValidationException("Parameter 'vm.name' is mandatory but was not provided."); } }
private void verifyTestAllocateVmActionResponse(Response r) { assertNotNull(r.getEntity()); assertNotNull(((org.ovirt.engine.api.model.Action)r.getEntity()).getVm()); assertNotNull(((org.ovirt.engine.api.model.Action)r.getEntity()).getVm().getId()); assertEquals(((org.ovirt.engine.api.model.Action)r.getEntity()).getVm().getId(), GUIDS[0].toString()); verifyActionResponse(r, "vmpools/" + GUIDS[0], false); }
protected Map<Guid, Guid> getDiskToDestinationMap(Action action) { Map<Guid, Guid> diskToDestinationMap = new HashMap<>(); if (action.isSetVm() && action.getVm().isSetDiskAttachments() && action.getVm().getDiskAttachments().isSetDiskAttachments()) { for (DiskAttachment diskAttachment : action.getVm().getDiskAttachments().getDiskAttachments()) { Disk disk = diskAttachment.getDisk(); if (disk != null && disk.isSetId() && disk.isSetStorageDomains() && disk.getStorageDomains().isSetStorageDomains() && disk.getStorageDomains().getStorageDomains().get(0).isSetId()) { diskToDestinationMap.put(Guid.createGuidFromStringDefaultEmpty(disk.getId()), Guid.createGuidFromStringDefaultEmpty(disk.getStorageDomains().getStorageDomains().get(0).getId())); } } } return diskToDestinationMap; } }
@Override public Response doClone(Action action) { validateParameters(action, "vm.name"); org.ovirt.engine.core.common.businessentities.VM vm = getEntity( org.ovirt.engine.core.common.businessentities.VM.class, QueryType.GetVmByVmId, new IdQueryParameters(guid), "VM: id=" + guid); CloneVmParameters cloneVmParameters = new CloneVmParameters(vm, action.getVm().getName()); cloneVmParameters.setMakeCreatorExplicitOwner(isFiltered()); Response response = doAction(ActionType.CloneVm, cloneVmParameters, action); return response; }
@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)); }
@Test public void testStart() { setUriInfo(setUpActionExpectations(ActionType.RunVm, RunVmParams.class, new String[] { "VmId" }, new Object[] { GUIDS[0] })); Response response = resource.start(new Action()); verifyActionResponse(response); verifyActionModel(((Action) response.getEntity()).getVm(), 0); }
@Test public void testStartWithBootDev() { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId", "BootSequence" }, new Object[] { GUIDS[0], BootSequence.N })); Action action = new Action(); action.setVm(new Vm()); action.getVm().setOs(new OperatingSystem()); action.getVm().getOs().setBoot(new Boot()); action.getVm().getOs().getBoot().setDevices(new Boot.DevicesList()); action.getVm().getOs().getBoot().getDevices().getDevices().add(BootDevice.NETWORK); verifyActionResponse(resource.start(action)); }
private void testStartWithModifiedGraphics(GraphicsType graphicsType) { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId", "RunOnceGraphics" }, new Object[] { GUIDS[0], Collections.singleton(graphicsType) })); Action action = new Action(); action.setVm(new Vm()); action.getVm().setDisplay(new Display()); DisplayType display = (graphicsType == GraphicsType.VNC) ? DisplayType.VNC : DisplayType.SPICE; action.getVm().getDisplay().setType(display); verifyActionResponse(resource.start(action)); }
@Test public void testStartWithBootMenu() { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId", "BootMenuEnabled" }, new Object[] { GUIDS[0], true })); Action action = new Action(); action.setVm(new Vm()); action.getVm().setBios(new Bios()); action.getVm().getBios().setBootMenu(new BootMenu()); action.getVm().getBios().getBootMenu().setEnabled(true); verifyActionResponse(resource.start(action)); }
ActionType actionType; if (action.isSetVm()) { Vm vm = action.getVm(); actionType = ActionType.RunVmOnce; params = createRunVmOnceParams(vm, action.isSetVolatile() && action.isVolatile());
private void setVolumesTypeFormat(Action action) { if (action.isSetVm()) { Vm modelVm = action.getVm(); if (!modelVm.isSetDiskAttachments()) { return; } Map<Guid, org.ovirt.engine.core.common.businessentities.storage.Disk> entityDisks = getDiskMap(); for (DiskAttachment modelDiskAttachment : modelVm.getDiskAttachments().getDiskAttachments()) { Disk modelDisk = modelDiskAttachment.getDisk(); if (modelDisk != null) { validateParameters(modelDisk, "id"); Guid modelDiskId = Guid.createGuidFromString(modelDisk.getId()); DiskImage entityDisk = (DiskImage) entityDisks.get(modelDiskId); if (entityDisk == null) { continue; } if (modelDisk.isSetFormat()) { VolumeFormat entityDiskFormat = DiskMapper.map(modelDisk.getFormat(), null); entityDisk.setVolumeFormat(entityDiskFormat); } if (modelDisk.isSetSparse()) { entityDisk.setVolumeType(modelDisk.isSparse() ? VolumeType.Sparse : VolumeType.Preallocated); } } } } }
@Test public void testStartWithVm() { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[]{"VmId"}, new Object[]{GUIDS[0]})); Action action = new Action(); action.setVm(new Vm()); Response response = resource.start(action); verifyActionResponse(response); verifyActionModel(((Action) response.getEntity()).getVm(), 0); }
@Override public Response doImport(Action action) { validateParameters(action, "storageDomain.id|name"); Guid destStorageDomainId = getDestStorageDomainId(action); Guid clusterId = null; if (action.isSetCluster()) { clusterId = getClusterId(action); } ImportVmParameters params = new ImportVmParameters(getEntity(), parent.getStorageDomainId(), destStorageDomainId, parent.getDataCenterId(destStorageDomainId), clusterId); params.setImageToDestinationDomainMap(getDiskToDestinationMap(action)); params.setForceOverride(action.isSetExclusive() ? action.isExclusive() : false); boolean collapseSnapshots = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, COLLAPSE_SNAPSHOTS, true, false); if (collapseSnapshots) { params.setCopyCollapse(collapseSnapshots); } setVolumesTypeFormat(action); if (action.isSetClone()) { params.setImportAsNewEntity(action.isClone()); if (action.isSetVm() && action.getVm().isSetName()) { params.getVm().setName(action.getVm().getName()); } } return doAction(ActionType.ImportVm, params, action); }
protected void testStartWithHost(Host host, Guid hostId) { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId", "DestinationVdsId" }, new Object[] { GUIDS[0], hostId })); Action action = new Action(); action.setVm(new Vm()); VmPlacementPolicy placementPolicy = new VmPlacementPolicy(); placementPolicy.setHosts(new Hosts()); placementPolicy.getHosts().getHosts().add(host); action.getVm().setPlacementPolicy(placementPolicy); verifyActionResponse(resource.start(action)); }
@Test public void testStartWithPauseAndStateless() { setUpWindowsGetEntityExpectations(1, false); setUriInfo(setUpActionExpectations(ActionType.RunVmOnce, RunVmOnceParams.class, new String[] { "VmId", "RunAndPause", "RunAsStateless" }, new Object[] { GUIDS[0], true, Boolean.TRUE })); Action action = new Action(); action.setPause(true); action.setVm(new Vm()); action.getVm().setStateless(true); verifyActionResponse(resource.start(action)); }
to.setVm(adaptOut(from.getVm()));