Search in sources :

Example 6 with VmInitNetwork

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

the class CloudInitHandler method storeNetworkAsEni.

private void storeNetworkAsEni() throws UnsupportedEncodingException {
    StringBuilder output = new StringBuilder();
    if (vmInit.getNetworks() != null) {
        List<VmInitNetwork> networks = vmInit.getNetworks();
        for (VmInitNetwork iface : networks) {
            if (Boolean.TRUE.equals(iface.getStartOnBoot())) {
                output.append("auto ").append(iface.getName()).append("\n");
            }
            storeIpv4(iface, output);
            // As of cloud-init 0.7.1, you can't set DNS servers without also setting NICs
            if (vmInit.getDnsServers() != null) {
                output.append("  dns-nameservers").append(" ").append(vmInit.getDnsServers());
                output.append("\n");
            }
            if (vmInit.getDnsSearch() != null) {
                output.append("  dns-search").append(" ").append(vmInit.getDnsSearch());
                output.append("\n");
            }
        // bugzilla.redhat.com/1464043:
        // muting configuration of IPv6 until a proper solution is found
        // storeIpv6(iface, output);
        }
    }
    interfaces = output.toString();
    if (!interfaces.isEmpty()) {
        // Workaround for cloud-init 0.6.3, which requires the "network-interfaces"
        // meta-data entry instead of the "network_config" file reference
        metaData.put("network-interfaces", interfaces);
        // Cloud-init will translate this as needed for ifcfg-based systems
        storeNextFile(CloudInitFileMode.NETWORK, "/etc/network/interfaces", interfaces.getBytes("US-ASCII"));
    }
}
Also used : VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork)

Example 7 with VmInitNetwork

use of org.ovirt.engine.core.common.businessentities.VmInitNetwork 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 8 with VmInitNetwork

use of org.ovirt.engine.core.common.businessentities.VmInitNetwork 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 9 with VmInitNetwork

use of org.ovirt.engine.core.common.businessentities.VmInitNetwork 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)

Example 10 with VmInitNetwork

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

the class CloudInitHandlerMetadataProtocolTest method dhcpIPv4.

/**
 * ENI after fix 1464043:
 * payload:
 * "network-interfaces" : "iface eth0 inet dhcp\n"
 *
 * cloud-init-output.log: ok
 *
 * virt-cat img:/etc/sysconfig/network-scripts/ifcfg-eth0:
 * BOOTPROTO=dhcp
 * DEVICE=eth0
 * ONBOOT=yes
 * TYPE=Ethernet
 * USERCTL=no
 *
 * cat vm:/etc/sysconfig/network-scripts/ifcfg-eth0:
 * same as in virt-cat of img + HWADDR
 *
 * -----------------------------------------------------------------------------------------------
 * openstack metadata
 *
 * payload:
 *{"links":[{"name":"eth0","id":"eth0","type":"vif"}],"networks":[{"link":"eth0","id":"eth0","type":"dhcp4"}]}
 *
 * cloud-init-output.log: ok
 * final behavior: first boot - got ip from dhcp
 *
 * virt-cat img:/etc/sysconfig/network-scripts/ifcfg-eth0:
 * BOOTPROTO=dhcp
 * DEVICE=eth0
 * ONBOOT=yes
 * TYPE=Ethernet
 * USERCTL=no
 *
 * cat vm:/etc/sysconfig/network-scripts/ifcfg-eth0 (after first boot):
 * same as in virt-cat of img
 *
 * cat vm:/etc/sysconfig/network-scripts/ifcfg-eth0 (after second boot):
 * same as after first boot + HWADDR
 */
private static Pair<VmInit, String> dhcpIPv4() {
    final VmInitNetwork underTest = new VmInitNetwork();
    underTest.setName(IFACE_NAME);
    underTest.setBootProtocol(Ipv4BootProtocol.DHCP);
    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_dhcp\",\n" + "      \"link\": \"iface name\"\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

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