use of org.ovirt.engine.api.model.Initialization in project ovirt-engine by oVirt.
the class VmMapper method map.
public static Vm map(String data, ConfigurationType type, Vm vm) {
Initialization initialization = vm.getInitialization();
if (initialization == null) {
initialization = new Initialization();
vm.setInitialization(initialization);
}
Configuration configuration = initialization.getConfiguration();
if (configuration == null) {
configuration = new Configuration();
initialization.setConfiguration(configuration);
}
configuration.setData(data);
configuration.setType(type);
return vm;
}
use of org.ovirt.engine.api.model.Initialization in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method doTestBadAddFromConfigurationMissingParameters.
@Test
public void doTestBadAddFromConfigurationMissingParameters() throws Exception {
setUriInfo(setUpBasicUriExpectations());
Vm model = createModel(null);
model.setInitialization(new Initialization());
model.getInitialization().setConfiguration(new Configuration());
try {
collection.add(model);
fail("expected WebApplicationException on incomplete parameters");
} catch (WebApplicationException wae) {
verifyIncompleteException(wae, "Vm", "add", "initialization.configuration.type", "initialization.configuration.data");
}
}
use of org.ovirt.engine.api.model.Initialization in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method testAddFromConfiguration.
@Test
public void testAddFromConfiguration() 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);
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", "ImportAsNewEntity" }, new Object[] { returnedVM, Guid.createGuidFromString(model.getCluster().getId()), false }, 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 testAddFromConfigurationWithRegenerateTrue.
@Test
public void testAddFromConfigurationWithRegenerateTrue() throws Exception {
setUriInfo(setUpBasicUriExpectations());
setUpGetPayloadExpectations(1, 3);
setUpGetBallooningExpectations(1, 3);
setUpGetGraphicsExpectations(1);
setUpGetCertuficateExpectations(1, 3);
setUpGetConsoleExpectations(3);
setUpGetVmOvfExpectations(3);
setUpGetVirtioScsiExpectations(3);
setUpGetSoundcardExpectations(3);
setUpGetRngDeviceExpectations(3);
Vm model = createModel(null);
org.ovirt.engine.core.common.businessentities.VM returnedVM = getEntity(2);
model.setInitialization(new Initialization());
model.getInitialization().setRegenerateIds(Boolean.TRUE);
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);
Guid newId = GUIDS[3];
setUpCreationExpectations(ActionType.ImportVmFromConfiguration, ImportVmFromConfParameters.class, new String[] { "Vm", "ClusterId", "ImportAsNewEntity" }, new Object[] { returnedVM, Guid.createGuidFromString(model.getCluster().getId()), true }, true, true, newId, QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { newId }, getEntityWithProvidedId(2, newId));
Response response = collection.add(model);
assertEquals(201, response.getStatus());
assertTrue(response.getEntity() instanceof Vm);
Vm queriedVm = (Vm) response.getEntity();
assertEquals(newId.toString(), queriedVm.getId());
queriedVm.setId(GUIDS[2].toString());
verifyModel((Vm) response.getEntity(), 2);
}
use of org.ovirt.engine.api.model.Initialization in project ovirt-engine by oVirt.
the class V3InitializationInAdapter method adapt.
@Override
public Initialization adapt(V3Initialization from) {
Initialization to = new Initialization();
if (from.isSetActiveDirectoryOu()) {
to.setActiveDirectoryOu(from.getActiveDirectoryOu());
}
if (from.isSetAuthorizedSshKeys()) {
to.setAuthorizedSshKeys(from.getAuthorizedSshKeys());
}
if (from.isSetCloudInit()) {
to.setCloudInit(adaptIn(from.getCloudInit()));
}
if (from.isSetConfiguration()) {
to.setConfiguration(adaptIn(from.getConfiguration()));
}
if (from.isSetCustomScript()) {
to.setCustomScript(from.getCustomScript());
}
if (from.isSetDnsSearch()) {
to.setDnsSearch(from.getDnsSearch());
}
if (from.isSetDnsServers()) {
to.setDnsServers(from.getDnsServers());
}
if (from.isSetDomain()) {
to.setDomain(from.getDomain());
}
if (from.isSetHostName()) {
to.setHostName(from.getHostName());
}
if (from.isSetInputLocale()) {
to.setInputLocale(from.getInputLocale());
}
if (from.isSetNicConfigurations()) {
to.setNicConfigurations(new NicConfigurations());
to.getNicConfigurations().getNicConfigurations().addAll(adaptIn(from.getNicConfigurations().getNicConfigurations()));
}
if (from.isSetOrgName()) {
to.setOrgName(from.getOrgName());
}
if (from.isSetRegenerateIds()) {
to.setRegenerateIds(from.isRegenerateIds());
}
if (from.isSetRegenerateSshKeys()) {
to.setRegenerateSshKeys(from.isRegenerateSshKeys());
}
if (from.isSetRootPassword()) {
to.setRootPassword(from.getRootPassword());
}
if (from.isSetSystemLocale()) {
to.setSystemLocale(from.getSystemLocale());
}
if (from.isSetTimezone()) {
to.setTimezone(from.getTimezone());
}
if (from.isSetUiLanguage()) {
to.setUiLanguage(from.getUiLanguage());
}
if (from.isSetUserLocale()) {
to.setUserLocale(from.getUserLocale());
}
if (from.isSetUserName()) {
to.setUserName(from.getUserName());
}
if (from.isSetWindowsLicenseKey()) {
to.setWindowsLicenseKey(from.getWindowsLicenseKey());
}
return to;
}
Aggregations