Search in sources :

Example 16 with VmInitNetwork

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

the class CloudInitHandlerMetadataProtocolTest method staticIPv6.

private static Pair<VmInit, String> staticIPv6() {
    final VmInitNetwork underTest = new VmInitNetwork();
    underTest.setName(IFACE_NAME);
    underTest.setIpv6BootProtocol(Ipv6BootProtocol.STATIC_IP);
    underTest.setIpv6Address(IPV6_ADDRESS);
    underTest.setIpv6Prefix(IPV6_PREFIX);
    underTest.setIpv6Gateway(IPV6_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\": \"ipv6\",\n" + "      \"link\": \"iface name\",\n" + "      \"ip_address\": \"ipv6 address\",\n" + "      \"netmask\": \"666\",\n" + "      \"gateway\": \"ipv6 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 17 with VmInitNetwork

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

the class CloudInitHandlerMetadataProtocolTest method noneAndNone.

/**
 * ENI before fix 1464043:
 * payload:
 * "network-interfaces" : "iface eth0 inet none\niface eth0 inet6 none\n" - error:
 * cloud-init-output.log:
 * cloudinit.net.ParserError: Interface eth0 can only be defined once. Re-defined in 'None'.
 *
 * login: impossible
 *
 * -----------------------------------------------------------------------------------------------
 * ENI after fix 1464043:
 * payload:
 * "network-interfaces" : "iface eth0 inet none\n"
 * cloud-init-output.log:
 * ValueError: Unknown subnet type 'none' found for interface 'eth0'
 *
 * /etc/sysconfig/network-scripts/ifcfg-eth0:
 * DEVICE="eth0"
 * BOOTPROTO="dhcp"
 * ONBOOT="yes"
 * TYPE="Ethernet"
 * PERSISTENT_DHCLIENT="yes"
 *
 * login: impossible
 *
 * -----------------------------------------------------------------------------------------------
 * Openstack Metadata Service:
 *
 * payload:
 * {}
 *
 * cloud-init-output.log: ok
 *
 * /etc/sysconfig/network-scripts/ifcfg-eth0
 * BOOTPROTO="dhcp"
 * DEVICE="eth0"
 * ONBOOT="yes"
 * TYPE="Ethernet"
 * PERSISTENT_DHCLIENT="yes"
 *
 * cat console:/etc/sysconfig/network-scripts/ifcfg-eth0 (after reboot)
 * BOOTPROTO=dhcp
 * HWADDR=...
 * DEVICE=eth0
 * ONBOOT=yes
 * TYPE=Ethernet
 * USERCTL=no
 */
private static Pair<VmInit, String> noneAndNone() {
    VmInit vmInit = new VmInit();
    VmInitNetwork underTest = new VmInitNetwork();
    underTest.setStartOnBoot(true);
    vmInit.setNetworks(Collections.singletonList(underTest));
    return new Pair<>(vmInit, null);
}
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 18 with VmInitNetwork

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

the class CloudInitHandlerMetadataProtocolTest method staticIPv4AndIPv6.

private static Pair<VmInit, String> staticIPv4AndIPv6() {
    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.setIpv6BootProtocol(Ipv6BootProtocol.STATIC_IP);
    underTest.setIpv6Address(IPV6_ADDRESS);
    underTest.setIpv6Prefix(IPV6_PREFIX);
    underTest.setIpv6Gateway(IPV6_GATEWAY);
    underTest.setStartOnBoot(true);
    VmInit vmInit = new VmInit();
    vmInit.setNetworks(Collections.singletonList(underTest));
    String expectedOutput = "{\n" + "  \"links\": [\n" + "    {\n" + "      \"name\": \"iface name\",\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"vif\"\n" + "    }\n" + "  ],\n" + "  \"networks\": [\n" + "    {\n" + "      \"netmask\": \"ipv4 netmask\",\n" + "      \"link\": \"iface name\",\n" + "      \"id\": \"iface name\",\n" + "      \"ip_address\": \"ipv4 address\",\n" + "      \"type\": \"ipv4\",\n" + "      \"gateway\": \"ipv4 gateway\"\n" + "    },\n" + "    {\n" + "      \"netmask\": \"666\",\n" + "      \"link\": \"iface name\",\n" + "      \"id\": \"iface name\",\n" + "      \"ip_address\": \"ipv6 address\",\n" + "      \"type\": \"ipv6\",\n" + "      \"gateway\": \"ipv6 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 19 with VmInitNetwork

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

the class CloudInitHandlerMetadataProtocolTest method dnsServersOnly.

private static Pair<VmInit, String> dnsServersOnly() {
    VmInit vmInit = new VmInit();
    VmInitNetwork underTest = new VmInitNetwork();
    underTest.setStartOnBoot(true);
    vmInit.setNetworks(Collections.singletonList(underTest));
    vmInit.setDnsSearch("search1 search2");
    vmInit.setDnsServers("nameserver1 nameserver2 nameserver3");
    String expectedOutput = "{\n" + "  \"services\": [\n" + "    {\n" + "      \"address\": \"nameserver1\",\n" + "      \"type\": \"dns\"\n" + "    },\n" + "    {\n" + "      \"address\": \"nameserver2\",\n" + "      \"type\": \"dns\"\n" + "    },\n" + "    {\n" + "      \"address\": \"nameserver3\",\n" + "      \"type\": \"dns\"\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 20 with VmInitNetwork

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

the class VmInitToOpenStackMetadataAdapter method asMap.

/**
 * Convert a network configuration bean to an
 * Openstack Metadata Service format consumed by cloud-init
 */
public Map<String, Object> asMap(VmInit vmInit) {
    if (vmInit == null) {
        return null;
    }
    List<VmInitNetwork> vmInitNetworks = vmInit.getNetworks();
    List<Map<String, Object>> links = null;
    List<Map<String, Object>> networks = null;
    if (vmInitNetworks != null) {
        links = new LinkedList<>();
        networks = new LinkedList<>();
        for (VmInitNetwork vmInitNetwork : vmInitNetworks) {
            if (!isStartOnBoot(vmInitNetwork)) {
                throw new IllegalArgumentException("'Start on boot' must be true");
            }
            boolean addLink = false;
            Map<String, Object> networkIPv4 = mapIPv4(vmInitNetwork);
            addDnsData(vmInit, networkIPv4);
            if (networkIPv4 != null) {
                networks.add(networkIPv4);
                addLink = true;
            }
            Map<String, Object> networkIPv6 = mapIPv6(vmInitNetwork);
            addDnsData(vmInit, networkIPv6);
            if (networkIPv6 != null) {
                networks.add(networkIPv6);
                addLink = true;
            }
            if (addLink) {
                links.add(mapVifLink(vmInitNetwork));
            }
        }
    }
    List<Map<String, Object>> services = mapServices(vmInit);
    Map<String, Object> networkData = new HashMap<>();
    if (!isEmpty(links)) {
        networkData.put("links", links);
    }
    if (!isEmpty(networks)) {
        networkData.put("networks", networks);
    }
    if (!isEmpty(services)) {
        networkData.put("services", services);
    }
    return networkData;
}
Also used : HashMap(java.util.HashMap) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)23 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)13 Pair (org.ovirt.engine.core.common.utils.Pair)10 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 Ipv4BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 AuthorizedKey (org.ovirt.engine.api.model.AuthorizedKey)1 File (org.ovirt.engine.api.model.File)1 Host (org.ovirt.engine.api.model.Host)1 Nic (org.ovirt.engine.api.model.Nic)1 NicConfiguration (org.ovirt.engine.api.model.NicConfiguration)1 User (org.ovirt.engine.api.model.User)1 Ipv6BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol)1 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)1 HostAddressValidation (org.ovirt.engine.ui.uicommonweb.validation.HostAddressValidation)1 HostnameValidation (org.ovirt.engine.ui.uicommonweb.validation.HostnameValidation)1