Search in sources :

Example 1 with VmInit

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

the class VmInitModel method buildCloudInitParameters.

public VmInit buildCloudInitParameters() {
    VmInit vmInit = new VmInit();
    if (getHostnameEnabled()) {
        vmInit.setHostname(isWindowsOS ? getWindowsHostname().getEntity() : getHostname().getEntity());
    }
    if (isWindowsOS) {
        vmInit.setInputLocale(getInputLocale().getEntity());
        vmInit.setUiLanguage(getUiLanguage().getEntity());
        vmInit.setSystemLocale(getSystemLocale().getEntity());
        vmInit.setUserLocale(getUserLocale().getEntity());
        vmInit.setCustomScript(getSysprepScript().getEntity());
        vmInit.setActiveDirectoryOU(getActiveDirectoryOU().getEntity());
        if (getSysprepPasswordEnabled()) {
            vmInit.setRootPassword(getSysprepAdminPassword().getEntity());
        }
        vmInit.setPasswordAlreadyStored(getSysprepPasswordSet().getEntity());
        vmInit.setOrgName(getSysprepOrgName().getEntity());
    } else {
        vmInit.setCustomScript(getCustomScript().getEntity());
        if (getRootPasswordEnabled()) {
            vmInit.setRootPassword(getCloudInitRootPassword().getEntity());
        }
        vmInit.setPasswordAlreadyStored(getCloudInitPasswordSet().getEntity());
    }
    vmInit.setUserName(getUserName().getEntity());
    vmInit.setAuthorizedKeys(getAuthorizedKeys().getEntity());
    if (getRegenerateKeysEnabled().getEntity()) {
        vmInit.setRegenerateKeys(Boolean.TRUE);
    }
    if (getNetworkEnabled().getEntity()) {
        saveNetworkFields();
        if (!networkMap.isEmpty()) {
            for (Map.Entry<String, VmInitNetwork> entry : networkMap.entrySet()) {
                VmInitNetwork vmInitNetwork = entry.getValue();
                if (vmInitNetwork.getBootProtocol() != Ipv4BootProtocol.STATIC_IP) {
                    vmInitNetwork.setIp(null);
                    vmInitNetwork.setNetmask(null);
                    vmInitNetwork.setGateway(null);
                }
                if (vmInitNetwork.getIpv6BootProtocol() != Ipv6BootProtocol.STATIC_IP) {
                    vmInitNetwork.setIpv6Address(null);
                    vmInitNetwork.setIpv6Prefix(null);
                    vmInitNetwork.setIpv6Gateway(null);
                }
                vmInitNetwork.setStartOnBoot(startOnBootNetworkNames.contains(entry.getKey()));
                vmInitNetwork.setName(entry.getKey());
            }
            vmInit.setNetworks(new ArrayList<>(networkMap.values()));
        }
    }
    vmInit.setDnsServers(getDnsServers().getEntity());
    vmInit.setDnsSearch(getDnsSearchDomains().getEntity());
    return vmInit;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 2 with VmInit

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

the class VmInitModel method buildModelSpecificParameters.

private VmInit buildModelSpecificParameters(boolean isWindows) {
    VmInit vmInit = buildCloudInitParameters();
    if (isWindows && getWindowsSysprepTimeZoneEnabled().getEntity()) {
        Map.Entry<String, String> entry = getWindowsSysprepTimeZone().getSelectedItem();
        vmInit.setTimeZone(entry.getKey());
    } else if (!isWindows && getTimeZoneEnabled().getEntity()) {
        Map.Entry<String, String> entry = getTimeZoneList().getSelectedItem();
        vmInit.setTimeZone(entry.getKey());
    }
    if (isWindows) {
        vmInit.setDomain(getSysprepDomain().getSelectedItem());
    }
    return vmInit;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 3 with VmInit

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

the class CloudInitHandlerMetadataProtocolTest method startOnBootFalse.

@SuppressWarnings("unchecked")
private static Pair startOnBootFalse() {
    VmInit vmInit = new VmInit();
    VmInitNetwork underTest = new VmInitNetwork();
    underTest.setStartOnBoot(false);
    vmInit.setNetworks(Collections.singletonList(underTest));
    return new Pair(vmInit, new IllegalArgumentException("Malformed input", new IllegalArgumentException("'Start on boot' must be true")));
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 4 with VmInit

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

the class CloudInitHandlerMetadataProtocolTest method staticIPv4.

/**
 * ENI after fix 1464043:
 * payload:
 * "network-interfaces" : "iface eth0 inet static\n  address 192.168.122.180\n  netmask 255.255.255.0\n  gateway 192.168.122.1\n"
 *
 * cloud-init-output.log: ok
 *
 * virt-cat img:/etc/sysconfig/network-scripts/ifcfg-eth0:
 * BOOTPROTO=static
 * DEVICE=eth0
 * IPADDR=192.168.122.182
 * NETMASK=255.255.255.0
 * ONBOOT=yes
 * TYPE=Ethernet
 * USERCTL=no
 *
 * ----------------------------------------------------------
 */
private static Pair<VmInit, String> staticIPv4() {
    final VmInitNetwork underTest = new VmInitNetwork();
    underTest.setName(IFACE_NAME);
    underTest.setBootProtocol(Ipv4BootProtocol.STATIC_IP);
    underTest.setIp(IPV4_ADDRESS);
    underTest.setNetmask(IPV4_NETMASK);
    underTest.setGateway(IPV4_GATEWAY);
    underTest.setStartOnBoot(true);
    VmInit vmInit = new VmInit();
    vmInit.setNetworks(Collections.singletonList(underTest));
    String expectedOutput = "{\n" + "  \"links\": [\n" + "    {\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"vif\",\n" + "      \"name\": \"iface name\"\n" + "    }\n" + "  ],\n" + "  \"networks\": [\n" + "    {\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"ipv4\",\n" + "      \"link\": \"iface name\",\n" + "      \"ip_address\": \"ipv4 address\",\n" + "      \"netmask\": \"ipv4 netmask\",\n" + "      \"gateway\": \"ipv4 gateway\"\n" + "    }\n" + "  ]\n" + "}";
    return new Pair<>(vmInit, expectedOutput);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 5 with VmInit

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

the class CloudInitHandlerMetadataProtocolTest method staticIPv6AddressOnly.

/**
 * payload:
 * {"links":[{"name":"eth0","id":"eth0","type":"vif"}],"networks":[{"link":"eth0","id":"eth0","ip_address":"2001:cdba::3257:9652","type":"ipv6"}]}
 *
 * cloud-init-output.log: ok
 * but cannot login to machine (because i dont have ipv6 configured on my local machine?)
 *
 * virt-cat img:/etc/sysconfig/network-scripts/ifcfg-eth0
 * BOOTPROTO=static
 * DEVICE=eth0
 * IPV6ADDR=2001:cdba::3257:9652
 * IPV6INIT=yes
 * ONBOOT=yes
 * TYPE=Ethernet
 * USERCTL=no
 */
private static Pair<VmInit, String> staticIPv6AddressOnly() {
    final VmInitNetwork underTest = new VmInitNetwork();
    underTest.setName(IFACE_NAME);
    underTest.setIpv6BootProtocol(Ipv6BootProtocol.STATIC_IP);
    underTest.setIpv6Address(IPV6_ADDRESS);
    underTest.setStartOnBoot(true);
    VmInit vmInit = new VmInit();
    vmInit.setNetworks(Collections.singletonList(underTest));
    String expectedOutput = "{\n" + "  \"links\": [\n" + "    {\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"vif\",\n" + "      \"name\": \"iface name\"\n" + "    }\n" + "  ],\n" + "  \"networks\": [\n" + "    {\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"ipv6\",\n" + "      \"link\": \"iface name\",\n" + "      \"ip_address\": \"ipv6 address\"\n" + "    }\n" + "  ]\n" + "}";
    return new Pair<>(vmInit, expectedOutput);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Pair(org.ovirt.engine.core.common.utils.Pair)

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