Search in sources :

Example 6 with Initialization

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);
}
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 7 with Initialization

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);
    }
}
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) ImportVmFromConfParameters(org.ovirt.engine.core.common.action.ImportVmFromConfParameters)

Example 8 with Initialization

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

Example 9 with Initialization

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));
}
Also used : Initialization(org.ovirt.engine.api.model.Initialization) VM(org.ovirt.engine.core.common.businessentities.VM) GetVmFromConfigurationQueryParameters(org.ovirt.engine.core.common.queries.GetVmFromConfigurationQueryParameters) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Configuration(org.ovirt.engine.api.model.Configuration) ImportVmFromConfParameters(org.ovirt.engine.core.common.action.ImportVmFromConfParameters) Guid(org.ovirt.engine.core.compat.Guid)

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