Search in sources :

Example 21 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class OvfReader method readGeneralData.

protected void readGeneralData(XmlNode content) {
    vmBase.setVmInit(new VmInit());
    consumeReadProperty(content, DESCRIPTION, val -> vmBase.setDescription(val));
    consumeReadProperty(content, COMMENT, val -> vmBase.setComment(val));
    consumeReadProperty(content, DOMAIN, val -> vmBase.getVmInit().setDomain(val));
    consumeReadProperty(content, CREATION_DATE, val -> vmBase.setCreationDate(OvfParser.utcDateStringToLocalDate(val)));
    consumeReadProperty(content, EXPORT_DATE, val -> vmBase.setExportDate(OvfParser.utcDateStringToLocalDate(val)));
    consumeReadProperty(content, DEFAULT_BOOT_SEQUENCE, val -> vmBase.setDefaultBootSequence(BootSequence.forValue(Integer.parseInt(val))));
    consumeReadProperty(content, INITRD_URL, val -> vmBase.setInitrdUrl(val));
    consumeReadProperty(content, KERNEL_URL, val -> vmBase.setKernelUrl(val));
    consumeReadProperty(content, KERNEL_PARAMS, val -> vmBase.setKernelParams(val));
    consumeReadProperty(content, GENERATION, val -> vmBase.setDbGeneration(Long.parseLong(val)), () -> vmBase.setDbGeneration(1L));
    XmlNode node = selectSingleNode(content, CUSTOM_COMPATIBILITY_VERSION);
    if (node != null) {
        vmBase.setCustomCompatibilityVersion(new Version(node.innerText));
    }
    // the originating ENGINE version
    Version originVersion = new Version(getVersion());
    node = selectSingleNode(content, CLUSTER_COMPATIBILITY_VERSION);
    if (node != null) {
        originVersion = new Version(node.innerText);
    }
    vmBase.setClusterCompatibilityVersionOrigin(originVersion);
    // Note: the fetching of 'default display type' should happen before reading
    // the hardware section
    consumeReadProperty(content, getDefaultDisplayTypeStringRepresentation(), val -> vmBase.setDefaultDisplayType(DisplayType.forValue(Integer.parseInt(val))));
    // after reading the hardware section, if graphics device is still absent, add a default one
    addDefaultGraphicsDevice();
    fixDiskVmElements();
    // due to dependency on vmBase.getOsId() must be read AFTER readOsSection
    consumeReadProperty(content, TIMEZONE, val -> vmBase.setTimeZone(val), () -> {
        if (osRepository.isWindows(vmBase.getOsId())) {
            vmBase.setTimeZone(Config.getValue(ConfigValues.DefaultWindowsTimeZone));
        } else {
            vmBase.setTimeZone(Config.getValue(ConfigValues.DefaultGeneralTimeZone));
        }
    });
    consumeReadProperty(content, ORIGIN, val -> vmBase.setOrigin(OriginType.forValue(Integer.parseInt(val))));
    consumeReadProperty(content, VM_TYPE, val -> vmBase.setVmType(VmType.forValue(Integer.parseInt(val))));
    consumeReadProperty(content, RESUME_BEHAVIOR, val -> vmBase.setResumeBehavior(VmResumeBehavior.valueOf(val)));
    consumeReadProperty(content, IS_SMARTCARD_ENABLED, val -> vmBase.setSmartcardEnabled(Boolean.parseBoolean(val)));
    consumeReadProperty(content, NUM_OF_IOTHREADS, val -> vmBase.setNumOfIoThreads(Integer.parseInt(val)));
    consumeReadProperty(content, DELETE_PROTECTED, val -> vmBase.setDeleteProtected(Boolean.parseBoolean(val)));
    consumeReadProperty(content, SSO_METHOD, val -> vmBase.setSsoMethod(SsoMethod.fromString(val)));
    consumeReadProperty(content, TUNNEL_MIGRATION, val -> vmBase.setTunnelMigration(Boolean.parseBoolean(val)));
    consumeReadProperty(content, VNC_KEYBOARD_LAYOUT, val -> vmBase.setVncKeyboardLayout(val));
    consumeReadProperty(content, MIN_ALLOCATED_MEMORY, val -> vmBase.setMinAllocatedMem(Integer.parseInt(val)));
    consumeReadProperty(content, IS_STATELESS, val -> vmBase.setStateless(Boolean.parseBoolean(val)));
    consumeReadProperty(content, IS_RUN_AND_PAUSE, val -> vmBase.setRunAndPause(Boolean.parseBoolean(val)));
    consumeReadProperty(content, CREATED_BY_USER_ID, val -> vmBase.setCreatedByUserId(Guid.createGuidFromString(val)));
    consumeReadProperty(content, MIGRATION_DOWNTIME, val -> vmBase.setMigrationDowntime(Integer.parseInt(val)));
    consumeReadProperty(content, MIGRATION_SUPPORT, val -> vmBase.setMigrationSupport(MigrationSupport.forValue(Integer.parseInt(val))));
    // TODO dedicated to multiple hosts
    readDedicatedHostsList();
    consumeReadProperty(content, SERIAL_NUMBER_POLICY, val -> vmBase.setSerialNumberPolicy(SerialNumberPolicy.forValue(Integer.parseInt(val))));
    consumeReadProperty(content, CUSTOM_SERIAL_NUMBER, val -> vmBase.setCustomSerialNumber(val));
    consumeReadProperty(content, AUTO_STARTUP, val -> vmBase.setAutoStartup(Boolean.parseBoolean(val)));
    consumeReadProperty(content, PRIORITY, val -> vmBase.setPriority(Integer.parseInt(val)));
    consumeReadProperty(content, IS_BOOT_MENU_ENABLED, val -> vmBase.setBootMenuEnabled(Boolean.parseBoolean(val)));
    consumeReadProperty(content, IS_SPICE_FILE_TRANSFER_ENABLED, val -> vmBase.setSpiceFileTransferEnabled(Boolean.parseBoolean(val)));
    consumeReadProperty(content, IS_SPICE_COPY_PASTE_ENABLED, val -> vmBase.setSpiceCopyPasteEnabled(Boolean.parseBoolean(val)));
    consumeReadProperty(content, ALLOW_CONSOLE_RECONNECT, val -> vmBase.setAllowConsoleReconnect(Boolean.parseBoolean(val)));
    consumeReadProperty(content, CONSOLE_DISCONNECT_ACTION, val -> vmBase.setConsoleDisconnectAction(ConsoleDisconnectAction.fromString(val)));
    consumeReadProperty(content, IS_AUTO_CONVERGE, val -> vmBase.setAutoConverge(Boolean.parseBoolean(val)));
    consumeReadProperty(content, IS_MIGRATE_COMPRESSED, val -> vmBase.setMigrateCompressed(Boolean.parseBoolean(val)));
    consumeReadProperty(content, MIGRATION_POLICY_ID, val -> vmBase.setMigrationPolicyId(Guid.createGuidFromString(val)));
    consumeReadProperty(content, CUSTOM_EMULATED_MACHINE, val -> vmBase.setCustomEmulatedMachine(val));
    consumeReadProperty(content, CUSTOM_CPU_NAME, val -> vmBase.setCustomCpuName(val));
    consumeReadProperty(content, PREDEFINED_PROPERTIES, val -> vmBase.setPredefinedProperties(val));
    consumeReadProperty(content, USER_DEFINED_PROPERTIES, val -> vmBase.setUserDefinedProperties(val));
    consumeReadProperty(content, MAX_MEMORY_SIZE_MB, val -> vmBase.setMaxMemorySizeMb(Integer.parseInt(val)));
    vmBase.setCustomProperties(VmPropertiesUtils.getInstance().customProperties(vmBase.getPredefinedProperties(), vmBase.getUserDefinedProperties()));
    consumeReadProperty(content, VM_LEASE, val -> vmBase.setLeaseStorageDomainId(new Guid(val)));
    readVmInit(content);
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) VmInit(org.ovirt.engine.core.common.businessentities.VmInit) Version(org.ovirt.engine.core.compat.Version) Guid(org.ovirt.engine.core.compat.Guid)

Example 22 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class OvfReader method readVmInit.

private void readVmInit(XmlNode content) {
    XmlNode node = selectSingleNode(content, "VmInit");
    VmInit vmInit = vmBase.getVmInit();
    vmInit.setId(vmBase.getId());
    if (node != null) {
        if (node.attributes.get("ovf:hostname") != null) {
            vmInit.setHostname(node.attributes.get("ovf:hostname").getValue());
        }
        if (node.attributes.get("ovf:domain") != null) {
            vmInit.setDomain(node.attributes.get("ovf:domain").getValue());
        }
        if (node.attributes.get("ovf:timeZone") != null) {
            vmInit.setTimeZone(node.attributes.get("ovf:timeZone").getValue());
        }
        if (node.attributes.get("ovf:authorizedKeys") != null) {
            vmInit.setAuthorizedKeys(node.attributes.get("ovf:authorizedKeys").getValue());
        }
        if (node.attributes.get("ovf:regenerateKeys") != null) {
            vmInit.setRegenerateKeys(Boolean.parseBoolean(node.attributes.get("ovf:regenerateKeys").getValue()));
        }
        if (node.attributes.get("ovf:dnsServers") != null) {
            vmInit.setDnsServers(node.attributes.get("ovf:dnsServers").getValue());
        }
        if (node.attributes.get("ovf:dnsSearch") != null) {
            vmInit.setDnsSearch(node.attributes.get("ovf:dnsSearch").getValue());
        }
        if (node.attributes.get("ovf:networks") != null) {
            vmInit.setNetworks(VmInitUtils.jsonNetworksToList(node.attributes.get("ovf:networks").getValue()));
        }
        if (node.attributes.get("ovf:winKey") != null) {
            vmInit.setWinKey(node.attributes.get("ovf:winKey").getValue());
        }
        if (node.attributes.get("ovf:rootPassword") != null) {
            vmInit.setRootPassword(node.attributes.get("ovf:rootPassword").getValue());
        }
        if (node.attributes.get("ovf:customScript") != null) {
            vmInit.setCustomScript(node.attributes.get("ovf:customScript").getValue());
        }
    }
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) VmInit(org.ovirt.engine.core.common.businessentities.VmInit)

Example 23 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmInitDaoTest method testSave.

@Test
public void testSave() {
    addVmInit();
    VmInit result = vmInitDao.get(EXISTING_VM);
    assertNotNull(result);
    assertEquals("hostname", result.getHostname());
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) Test(org.junit.Test)

Example 24 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmInitDaoTest method addVmInit.

private void addVmInit() {
    VmInit init = new VmInit();
    init.setId(EXISTING_VM);
    init.setHostname("hostname");
    vmInitDao.save(init);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit)

Example 25 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmInitDaoTest method testGet.

@Test
public void testGet() {
    VmInit result = vmInitDao.get(EXISTING_VM);
    assertNotNull(result != null);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) Test(org.junit.Test)

Aggregations

VmInit (org.ovirt.engine.core.common.businessentities.VmInit)34 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)14 Pair (org.ovirt.engine.core.common.utils.Pair)10 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Map (java.util.Map)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 Guid (org.ovirt.engine.core.compat.Guid)3 List (java.util.List)2 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)2 Ipv4BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)2 IdsQueryParameters (org.ovirt.engine.core.common.queries.IdsQueryParameters)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)2 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 Before (org.junit.Before)1