Search in sources :

Example 1 with Initialization

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;
}
Also used : Initialization(org.ovirt.engine.api.model.Initialization) Configuration(org.ovirt.engine.api.model.Configuration)

Example 2 with Initialization

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");
    }
}
Also used : Initialization(org.ovirt.engine.api.model.Initialization) Configuration(org.ovirt.engine.api.model.Configuration) WebApplicationException(javax.ws.rs.WebApplicationException) Vm(org.ovirt.engine.api.model.Vm) Test(org.junit.Test)

Example 3 with Initialization

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);
}
Also used : Initialization(org.ovirt.engine.api.model.Initialization) Response(javax.ws.rs.core.Response) Configuration(org.ovirt.engine.api.model.Configuration) Vm(org.ovirt.engine.api.model.Vm) Test(org.junit.Test)

Example 4 with Initialization

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);
}
Also used : Initialization(org.ovirt.engine.api.model.Initialization) Response(javax.ws.rs.core.Response) Configuration(org.ovirt.engine.api.model.Configuration) Vm(org.ovirt.engine.api.model.Vm) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 5 with Initialization

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;
}
Also used : V3Initialization(org.ovirt.engine.api.v3.types.V3Initialization) Initialization(org.ovirt.engine.api.model.Initialization) NicConfigurations(org.ovirt.engine.api.model.NicConfigurations)

Aggregations

Initialization (org.ovirt.engine.api.model.Initialization)9 Configuration (org.ovirt.engine.api.model.Configuration)8 Vm (org.ovirt.engine.api.model.Vm)5 Test (org.junit.Test)4 Response (javax.ws.rs.core.Response)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 ImportVmFromConfParameters (org.ovirt.engine.core.common.action.ImportVmFromConfParameters)2 Guid (org.ovirt.engine.core.compat.Guid)2 NicConfigurations (org.ovirt.engine.api.model.NicConfigurations)1 V3Initialization (org.ovirt.engine.api.v3.types.V3Initialization)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 GetVmFromConfigurationQueryParameters (org.ovirt.engine.core.common.queries.GetVmFromConfigurationQueryParameters)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1