Search in sources :

Example 6 with VmInit

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

Example 7 with VmInit

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

the class CloudInitHandlerMetadataProtocolTest method staticIPv4WithDns.

private static Pair<VmInit, String> staticIPv4WithDns() {
    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));
    vmInit.setDnsSearch("search1 search2");
    vmInit.setDnsServers("nameserver1 nameserver2");
    String expectedOutput = "{\n" + "  \"links\": [\n" + "    {\n" + "      \"name\": \"iface name\",\n" + "      \"id\": \"iface name\",\n" + "      \"type\": \"vif\"\n" + "    }\n" + "  ],\n" + "  \"services\": [\n" + "    {\n" + "      \"address\": \"nameserver1\",\n" + "      \"type\": \"dns\"\n" + "    },\n" + "    {\n" + "      \"address\": \"nameserver2\",\n" + "      \"type\": \"dns\"\n" + "    }\n" + "  ],\n" + "  \"networks\": [\n" + "    {\n" + "      \"netmask\": \"ipv4 netmask\",\n" + "      \"dns_search\": [\n" + "        \"search1\",\n" + "        \"search2\"\n" + "      ],\n" + "      \"link\": \"iface name\",\n" + "      \"id\": \"iface name\",\n" + "      \"ip_address\": \"ipv4 address\",\n" + "      \"type\": \"ipv4\",\n" + "      \"gateway\": \"ipv4 gateway\",\n" + "      \"dns_nameservers\": [\n" + "        \"nameserver1\",\n" + "        \"nameserver2\"\n" + "      ]\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 8 with VmInit

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

the class CloudInitHandlerMetadataProtocolTest method dhcpIPv6.

/**
 * payload:
 * {"links":[{"name":"eth0","id":"eth0","type":"vif"}],"networks":[{"link":"eth0","id":"eth0","type":"dhcp6"}]}
 *
 * 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 img
 *
 * cat vm:/etc/sysconfig/network-scripts/ifcfg-eth0 (after second boot):
 * same as after first boot + HWADDR
 */
private static Pair<VmInit, String> dhcpIPv6() {
    final VmInitNetwork underTest = new VmInitNetwork();
    underTest.setName(IFACE_NAME);
    underTest.setIpv6BootProtocol(Ipv6BootProtocol.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\": \"ipv6_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)

Example 9 with VmInit

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

the class OvfWriter method writeVmInit.

protected void writeVmInit() {
    if (vmBase.getVmInit() != null) {
        VmInit vmInit = vmBase.getVmInit();
        _writer.writeStartElement("VmInit");
        if (vmInit.getHostname() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "hostname", vmInit.getHostname());
        }
        if (vmInit.getDomain() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "domain", vmInit.getDomain());
        }
        if (vmInit.getTimeZone() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "timeZone", vmInit.getTimeZone());
        }
        if (vmInit.getAuthorizedKeys() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "authorizedKeys", vmInit.getAuthorizedKeys());
        }
        if (vmInit.getRegenerateKeys() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "regenerateKeys", vmInit.getRegenerateKeys().toString());
        }
        if (vmInit.getDnsSearch() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "dnsSearch", vmInit.getDnsSearch());
        }
        if (vmInit.getDnsServers() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "dnsServers", vmInit.getDnsServers());
        }
        if (vmInit.getNetworks() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "networks", VmInitUtils.networkListToJson(vmInit.getNetworks()));
        }
        if (vmInit.getWinKey() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "winKey", vmInit.getWinKey());
        }
        if (vmInit.getRootPassword() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "rootPassword", vmInit.getRootPassword());
        }
        if (vmInit.getCustomScript() != null) {
            _writer.writeAttributeString(OVF_PREFIX, getOvfUri(), "customScript", vmInit.getCustomScript());
        }
        _writer.writeEndElement();
    }
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit)

Example 10 with VmInit

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

the class BackendVmsResourceTest method setUpVmInit.

private List<VmInit> setUpVmInit() {
    List<VmInit> vminits = new ArrayList<>(NAMES.length);
    for (int i = 0; i < NAMES.length; i++) {
        VmInit vmInit = mock(VmInit.class);
        vminits.add(vmInit);
    }
    return vminits;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) ArrayList(java.util.ArrayList)

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