Search in sources :

Example 1 with Configuration

use of org.ovirt.engine.api.model.Configuration 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 Configuration

use of org.ovirt.engine.api.model.Configuration 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 Configuration

use of org.ovirt.engine.api.model.Configuration 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 Configuration

use of org.ovirt.engine.api.model.Configuration 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 Configuration

use of org.ovirt.engine.api.model.Configuration 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);
}
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)

Aggregations

Configuration (org.ovirt.engine.api.model.Configuration)8 Initialization (org.ovirt.engine.api.model.Initialization)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 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