use of org.ovirt.engine.api.model.Initialization in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method testAddFromConfigurationNamedCluster.
@Test
public void testAddFromConfigurationNamedCluster() throws Exception {
setUriInfo(setUpBasicUriExpectations());
setUpGetPayloadExpectations(1, 2);
setUpGetBallooningExpectations(1, 2);
setUpGetGraphicsExpectations(1);
setUpGetCertuficateExpectations(1, 2);
setUpGetConsoleExpectations(2);
setUpGetVmOvfExpectations(2);
setUpGetVirtioScsiExpectations(2);
setUpGetSoundcardExpectations(2);
setUpGetRngDeviceExpectations(2);
Vm model = createModel(null);
org.ovirt.engine.core.common.businessentities.VM returnedVM = getEntity(2);
model.setInitialization(new Initialization());
model.getInitialization().setConfiguration(new Configuration());
model.getInitialization().getConfiguration().setData("asdasdasd");
model.getInitialization().getConfiguration().setType(org.ovirt.engine.api.model.ConfigurationType.OVF);
model.setCluster(new org.ovirt.engine.api.model.Cluster());
model.getCluster().setName(NAMES[1]);
setUpEntityQueryExpectations(QueryType.GetClusterByName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { NAMES[1] }, setUpCluster(GUIDS[1]));
setUpGetEntityExpectations(QueryType.GetVmFromConfiguration, GetVmFromConfigurationQueryParameters.class, new String[] { "VmConfiguration", "ConfigurationType" }, new Object[] { model.getInitialization().getConfiguration().getData(), ConfigurationType.OVF }, returnedVM);
setUpCreationExpectations(ActionType.ImportVmFromConfiguration, ImportVmFromConfParameters.class, new String[] { "Vm", "ClusterId" }, new Object[] { returnedVM, GUIDS[1] }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, returnedVM);
Response response = collection.add(model);
assertEquals(201, response.getStatus());
assertTrue(response.getEntity() instanceof Vm);
verifyModel((Vm) response.getEntity(), 2);
}
use of org.ovirt.engine.api.model.Initialization in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method testBadAddFromConfiguration.
private void testBadAddFromConfiguration(boolean valid, boolean success, String detail) throws Exception {
Vm model = createModel(null);
org.ovirt.engine.core.common.businessentities.VM returnedVM = getEntity(2);
model.setInitialization(new Initialization());
model.getInitialization().setConfiguration(new Configuration());
model.getInitialization().getConfiguration().setData("asdasdasd");
model.getInitialization().getConfiguration().setType(org.ovirt.engine.api.model.ConfigurationType.OVF);
setUpGetEntityExpectations(QueryType.GetVmFromConfiguration, GetVmFromConfigurationQueryParameters.class, new String[] { "VmConfiguration", "ConfigurationType" }, new Object[] { model.getInitialization().getConfiguration().getData(), ConfigurationType.OVF }, returnedVM);
setUriInfo(setUpActionExpectations(ActionType.ImportVmFromConfiguration, ImportVmFromConfParameters.class, new String[] { "Vm", "ClusterId" }, new Object[] { returnedVM, Guid.createGuidFromString(model.getCluster().getId()) }, valid, success));
try {
collection.add(model);
fail("expected WebApplicationException");
} catch (WebApplicationException wae) {
verifyFault(wae, detail);
}
}
use of org.ovirt.engine.api.model.Initialization in project ovirt-engine by oVirt.
the class SnapshotMapper method map.
public static Snapshot map(String configuration, ConfigurationType type, Snapshot snapshot) {
snapshot.setInitialization(new Initialization());
snapshot.getInitialization().setConfiguration(new Configuration());
snapshot.getInitialization().getConfiguration().setData(configuration);
snapshot.getInitialization().getConfiguration().setType(type);
return snapshot;
}
use of org.ovirt.engine.api.model.Initialization in project ovirt-engine by oVirt.
the class BackendVmsResource method importVmFromConfiguration.
public Response importVmFromConfiguration(Vm vm) {
Initialization initialization = vm.getInitialization();
Configuration config = initialization.getConfiguration();
org.ovirt.engine.core.common.businessentities.VM vmConfiguration = getEntity(org.ovirt.engine.core.common.businessentities.VM.class, QueryType.GetVmFromConfiguration, new GetVmFromConfigurationQueryParameters(VmMapper.map(config.getType(), null), config.getData().trim()), "");
VmMapper.map(vm, vmConfiguration.getStaticData());
Guid clusterId = namedCluster(vm) ? getCluster(vm).getId() : asGuid(vm.getCluster().getId());
ImportVmFromConfParameters parameters = new ImportVmFromConfParameters();
parameters.setVm(vmConfiguration);
parameters.setClusterId(clusterId);
if (initialization.isSetRegenerateIds()) {
parameters.setImportAsNewEntity(initialization.isRegenerateIds());
}
return performCreate(ActionType.ImportVmFromConfiguration, parameters, new QueryIdResolver<Guid>(QueryType.GetVmByVmId, IdQueryParameters.class));
}
Aggregations