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"));
}
}
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")));
}
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);
}
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);
}
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);
}
Aggregations