use of org.ovirt.engine.core.common.businessentities.VmInitNetwork 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);
}
use of org.ovirt.engine.core.common.businessentities.VmInitNetwork 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);
}
use of org.ovirt.engine.core.common.businessentities.VmInitNetwork in project ovirt-engine by oVirt.
the class CloudInitHandlerTest method createVmInitNetwork.
private VmInitNetwork createVmInitNetwork() {
final VmInitNetwork vmInitNetwork = new VmInitNetwork();
vmInitNetwork.setName(IFACE_NAME);
vmInitNetwork.setBootProtocol(Ipv4BootProtocol.STATIC_IP);
vmInitNetwork.setIp(IPV4_ADDRESS);
vmInitNetwork.setNetmask(IPV4_NETMASK);
vmInitNetwork.setGateway(IPV4_GATEWAY);
// vmInitNetwork.setIpv6Gateway(IPV6_GATEWAY);
return vmInitNetwork;
}
use of org.ovirt.engine.core.common.businessentities.VmInitNetwork in project ovirt-engine by oVirt.
the class VmInitToOpenStackMetadataAdapter method validate.
public List<EngineMessage> validate(VmInit vmInit) {
if (vmInit == null || vmInit.getNetworks() == null) {
return null;
}
List<EngineMessage> msgs = new LinkedList<>();
List<VmInitNetwork> vmInitNetworks = vmInit.getNetworks();
for (VmInitNetwork vmInitNetwork : vmInitNetworks) {
if (!isStartOnBoot(vmInitNetwork)) {
msgs.add(EngineMessage.VALIDATION_CLOUD_INIT_START_ON_BOOT_INVALID);
}
if (isStaticIPv4AndAddressMissing(vmInitNetwork)) {
msgs.add(EngineMessage.VALIDATION_CLOUD_INIT_STATIC_IPV4_ADDRESS_MISSING);
}
if (isStaticIPv6AndAddressMissing(vmInitNetwork)) {
msgs.add(EngineMessage.VALIDATION_CLOUD_INIT_STATIC_IPV6_ADDRESS_MISSING);
}
if (isAutoConfIPv6(vmInitNetwork)) {
msgs.add(EngineMessage.VALIDATION_CLOUD_INIT_IPV6_AUTOCONF_UNSUPPORTED);
}
}
return msgs;
}
use of org.ovirt.engine.core.common.businessentities.VmInitNetwork in project ovirt-engine by oVirt.
the class VmMapper method map.
@Mapping(from = CloudInit.class, to = VmInit.class)
public static VmInit map(CloudInit model, VmInit template) {
VmInit entity = template != null ? template : new VmInit();
if (model.isSetHost() && model.getHost().isSetAddress()) {
entity.setHostname(model.getHost().getAddress());
}
if (model.isSetAuthorizedKeys() && model.getAuthorizedKeys().isSetAuthorizedKeys() && !model.getAuthorizedKeys().getAuthorizedKeys().isEmpty()) {
StringBuilder keys = new StringBuilder();
for (AuthorizedKey authKey : model.getAuthorizedKeys().getAuthorizedKeys()) {
if (keys.length() > 0) {
keys.append("\n");
}
keys.append(authKey.getKey());
}
entity.setAuthorizedKeys(keys.toString());
}
if (model.isSetRegenerateSshKeys()) {
entity.setRegenerateKeys(model.isRegenerateSshKeys());
}
if (model.isSetNetworkConfiguration()) {
if (model.getNetworkConfiguration().isSetNics()) {
List<VmInitNetwork> interfaces = new ArrayList<>();
for (Nic iface : model.getNetworkConfiguration().getNics().getNics()) {
VmInitNetwork vmInitInterface = new VmInitNetwork();
if (iface.isSetName()) {
vmInitInterface.setName(iface.getName());
}
interfaces.add(vmInitInterface);
if (iface.isSetBootProtocol()) {
Ipv4BootProtocol protocol = Ipv4BootProtocolMapper.map(iface.getBootProtocol());
vmInitInterface.setBootProtocol(protocol);
if (protocol != Ipv4BootProtocol.DHCP && iface.isSetNetwork() && iface.getNetwork().isSetIp()) {
if (iface.getNetwork().getIp().isSetAddress()) {
vmInitInterface.setIp(iface.getNetwork().getIp().getAddress());
}
if (iface.getNetwork().getIp().isSetNetmask()) {
vmInitInterface.setNetmask(iface.getNetwork().getIp().getNetmask());
}
if (iface.getNetwork().getIp().isSetGateway()) {
vmInitInterface.setGateway(iface.getNetwork().getIp().getGateway());
}
}
if (iface.isSetOnBoot() && iface.isOnBoot()) {
vmInitInterface.setStartOnBoot(true);
}
}
}
entity.setNetworks(interfaces);
}
if (model.getNetworkConfiguration().isSetDns()) {
if (model.getNetworkConfiguration().getDns().isSetServers() && model.getNetworkConfiguration().getDns().getServers().isSetHosts() && !model.getNetworkConfiguration().getDns().getServers().getHosts().isEmpty()) {
List<String> dnsServers = new ArrayList<>();
for (Host host : model.getNetworkConfiguration().getDns().getServers().getHosts()) {
if (host.isSetAddress()) {
dnsServers.add(host.getAddress());
}
}
entity.setDnsServers(String.join(" ", dnsServers));
}
if (model.getNetworkConfiguration().getDns().isSetSearchDomains() && model.getNetworkConfiguration().getDns().getSearchDomains().isSetHosts() && !model.getNetworkConfiguration().getDns().getSearchDomains().getHosts().isEmpty()) {
List<String> searchDomains = new ArrayList<>();
for (Host host : model.getNetworkConfiguration().getDns().getSearchDomains().getHosts()) {
if (host.isSetAddress()) {
searchDomains.add(host.getAddress());
}
}
entity.setDnsSearch(String.join(" ", searchDomains));
}
}
}
if (model.isSetTimezone() && model.getTimezone() != null) {
entity.setTimeZone(model.getTimezone());
}
if (model.isSetUsers()) {
for (User user : model.getUsers().getUsers()) {
String userName = user.getUserName();
if (StringUtils.equals(userName, "root")) {
entity.setUserName(userName);
String userPassword = user.getPassword();
if (userPassword != null) {
entity.setRootPassword(userPassword);
}
}
}
}
// for RunOnce backward compatibility.
if (model.isSetFiles() && model.getFiles().isSetFiles() && !model.getFiles().getFiles().isEmpty()) {
File file = model.getFiles().getFiles().get(0);
entity.setCustomScript(file.getContent());
}
return entity;
}
Aggregations