use of org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol in project ovirt-engine by oVirt.
the class NetworkInSyncWithVdsNetworkInterfaceTest method initIpv4ConfigurationBootProtocol.
private void initIpv4ConfigurationBootProtocol(boolean sameBootProtocol) {
initIpv4Configuration();
ipv4Address.setBootProtocol(IPV4_BOOT_PROTOCOL);
Ipv4BootProtocol ifaceBootProtocol = sameBootProtocol ? IPV4_BOOT_PROTOCOL : Ipv4BootProtocol.forValue((IPV4_BOOT_PROTOCOL.getValue() + 1) % Ipv4BootProtocol.values().length);
iface.setIpv4BootProtocol(ifaceBootProtocol);
}
use of org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol in project ovirt-engine by oVirt.
the class NetworkAttachmentIpConfigurationValidator method validateIpv4Configuration.
private ValidationResult validateIpv4Configuration(NetworkAttachment networkAttachment) {
IpConfiguration ipConfiguration = networkAttachment.getIpConfiguration();
if (!ipConfiguration.hasIpv4PrimaryAddressSet()) {
return ValidationResult.VALID;
}
IPv4Address iPv4Address = ipConfiguration.getIpv4PrimaryAddress();
String networkName = networkAttachment.getNetworkName();
String nicName = networkAttachment.getNicName();
if (iPv4Address.getBootProtocol() == null) {
return incompleteIpConfigurationValidationResult(EngineMessage.NETWORK_ATTACHMENT_IP_CONFIGURATION_MISSING_BOOT_PROTOCOL, networkName, nicName);
}
Ipv4BootProtocol bootProtocol = iPv4Address.getBootProtocol();
if (bootProtocol == Ipv4BootProtocol.STATIC_IP) {
if (!validStaticIpv4AddressDetails(iPv4Address)) {
return incompleteIpConfigurationValidationResult(EngineMessage.NETWORK_ATTACHMENT_IP_CONFIGURATION_STATIC_BOOT_PROTOCOL_MISSING_IP_ADDRESS_DETAILS, networkName, nicName);
}
} else {
if (!isEmptyIpv4AddressDetails(iPv4Address)) {
return new ValidationResult(EngineMessage.NETWORK_ATTACHMENT_IP_CONFIGURATION_INCOMPATIBLE_BOOT_PROTOCOL_AND_IP_ADDRESS_DETAILS, ReplacementUtils.createSetVariableString(VAR_NETWORK_NAME, networkName), ReplacementUtils.createSetVariableString(VAR_INTERFACE_NAME, nicName), ReplacementUtils.createSetVariableString(VAR_BOOT_PROTOCOL, bootProtocol.getDisplayName()));
}
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol in project ovirt-engine by oVirt.
the class NetworkInterfaceValidator method isValid.
/**
* validate the following:
* <ul>
* <li>an interface must have an address when the boot protocol is static
* </ul>
*/
@Override
public boolean isValid(VdsNetworkInterface iface, ConstraintValidatorContext context) {
Ipv4BootProtocol bootProtocol = iface.getIpv4BootProtocol();
String address = iface.getIpv4Address();
if (bootProtocol != null && bootProtocol == STATIC_IP) {
if (isNullOrEmpty(address)) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("NETWORK_ADDR_MANDATORY_IN_STATIC_IP").addNode("address").addConstraintViolation();
return false;
}
}
if (!isEmpty(iface.getBondName()) && !validateSlave(iface)) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("SLAVE_INTERFACE_IS_MISCONFIGURED").addConstraintViolation();
return false;
}
if (!validateLabel(iface)) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("IMPROPER_INTERFACE_IS_LABELED").addConstraintViolation();
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol 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;
}
use of org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol in project ovirt-engine by oVirt.
the class LogicalNetworkModelParametersHelper method populateIpv4Details.
public static void populateIpv4Details(InterfacePropertiesAccessor interfacePropertiesAccessor, IPv4Address ipv4Address) {
final Ipv4BootProtocol ipv4BootProtocol = interfacePropertiesAccessor.getIpv4BootProtocol();
ipv4Address.setBootProtocol(ipv4BootProtocol);
final boolean staticBootProtocol = Ipv4BootProtocol.STATIC_IP == ipv4BootProtocol;
ipv4Address.setAddress(staticBootProtocol ? interfacePropertiesAccessor.getIpv4Address() : null);
ipv4Address.setNetmask(staticBootProtocol ? interfacePropertiesAccessor.getIpv4Netmask() : null);
ipv4Address.setGateway(staticBootProtocol ? interfacePropertiesAccessor.getIpv4Gateway() : null);
}
Aggregations