use of org.ovirt.engine.core.common.businessentities.VmInitNetwork in project ovirt-engine by oVirt.
the class VmInitModel method saveNetworkFields.
/* Save displayed network properties */
private void saveNetworkFields() {
if (lastSelectedNetworkName != null) {
VmInitNetwork vmInitNetwork = networkMap.get(lastSelectedNetworkName);
if (vmInitNetwork != null) {
vmInitNetwork.setBootProtocol(getIpv4BootProtocolList().getSelectedItem());
vmInitNetwork.setIp(getNetworkIpAddress().getEntity());
vmInitNetwork.setNetmask(getNetworkNetmask().getEntity());
vmInitNetwork.setGateway(getNetworkGateway().getEntity());
vmInitNetwork.setIpv6BootProtocol(getIpv6BootProtocolList().getSelectedItem());
vmInitNetwork.setIpv6Address(getNetworkIpv6Address().getEntity());
vmInitNetwork.setIpv6Prefix(getNetworkIpv6Prefix().getEntity());
vmInitNetwork.setIpv6Gateway(getNetworkIpv6Gateway().getEntity());
if (getNetworkStartOnBoot().getEntity() != null && getNetworkStartOnBoot().getEntity()) {
startOnBootNetworkNames.add(lastSelectedNetworkName);
} else {
startOnBootNetworkNames.remove(lastSelectedNetworkName);
}
}
}
}
use of org.ovirt.engine.core.common.businessentities.VmInitNetwork in project ovirt-engine by oVirt.
the class VmInitModel method buildCloudInitParameters.
public VmInit buildCloudInitParameters() {
VmInit vmInit = new VmInit();
if (getHostnameEnabled()) {
vmInit.setHostname(isWindowsOS ? getWindowsHostname().getEntity() : getHostname().getEntity());
}
if (isWindowsOS) {
vmInit.setInputLocale(getInputLocale().getEntity());
vmInit.setUiLanguage(getUiLanguage().getEntity());
vmInit.setSystemLocale(getSystemLocale().getEntity());
vmInit.setUserLocale(getUserLocale().getEntity());
vmInit.setCustomScript(getSysprepScript().getEntity());
vmInit.setActiveDirectoryOU(getActiveDirectoryOU().getEntity());
if (getSysprepPasswordEnabled()) {
vmInit.setRootPassword(getSysprepAdminPassword().getEntity());
}
vmInit.setPasswordAlreadyStored(getSysprepPasswordSet().getEntity());
vmInit.setOrgName(getSysprepOrgName().getEntity());
} else {
vmInit.setCustomScript(getCustomScript().getEntity());
if (getRootPasswordEnabled()) {
vmInit.setRootPassword(getCloudInitRootPassword().getEntity());
}
vmInit.setPasswordAlreadyStored(getCloudInitPasswordSet().getEntity());
}
vmInit.setUserName(getUserName().getEntity());
vmInit.setAuthorizedKeys(getAuthorizedKeys().getEntity());
if (getRegenerateKeysEnabled().getEntity()) {
vmInit.setRegenerateKeys(Boolean.TRUE);
}
if (getNetworkEnabled().getEntity()) {
saveNetworkFields();
if (!networkMap.isEmpty()) {
for (Map.Entry<String, VmInitNetwork> entry : networkMap.entrySet()) {
VmInitNetwork vmInitNetwork = entry.getValue();
if (vmInitNetwork.getBootProtocol() != Ipv4BootProtocol.STATIC_IP) {
vmInitNetwork.setIp(null);
vmInitNetwork.setNetmask(null);
vmInitNetwork.setGateway(null);
}
if (vmInitNetwork.getIpv6BootProtocol() != Ipv6BootProtocol.STATIC_IP) {
vmInitNetwork.setIpv6Address(null);
vmInitNetwork.setIpv6Prefix(null);
vmInitNetwork.setIpv6Gateway(null);
}
vmInitNetwork.setStartOnBoot(startOnBootNetworkNames.contains(entry.getKey()));
vmInitNetwork.setName(entry.getKey());
}
vmInit.setNetworks(new ArrayList<>(networkMap.values()));
}
}
vmInit.setDnsServers(getDnsServers().getEntity());
vmInit.setDnsSearch(getDnsSearchDomains().getEntity());
return vmInit;
}
use of org.ovirt.engine.core.common.businessentities.VmInitNetwork in project ovirt-engine by oVirt.
the class VmInitModel method initNetworks.
private void initNetworks(VmInit vmInit) {
if (vmInit.getDnsServers() != null) {
getDnsServers().setEntity(vmInit.getDnsServers());
}
if (vmInit.getDnsSearch() != null) {
getDnsSearchDomains().setEntity(vmInit.getDnsSearch());
}
if (vmInit.getNetworks() == null || vmInit.getNetworks().size() == 0) {
return;
}
networkMap = new TreeMap<>();
startOnBootNetworkNames = new HashSet<>();
lastSelectedNetworkName = null;
for (VmInitNetwork network : vmInit.getNetworks()) {
if (network.getName() == null) {
continue;
}
networkMap.put(network.getName(), network);
if (network.getStartOnBoot() != null && network.getStartOnBoot()) {
startOnBootNetworkNames.add(network.getName());
}
}
if (networkMap.size() != 0) {
lastSelectedNetworkName = networkMap.keySet().iterator().next();
getNetworkEnabled().setEntity(true);
} else {
getNetworkEnabled().setEntity(false);
}
// update silently - do not listen to events
getNetworkList().getSelectedItemChangedEvent().removeListener(this);
getNetworkList().setItems(new ArrayList<>(networkMap.keySet()));
getNetworkList().setSelectedItem(lastSelectedNetworkName);
getNetworkList().getSelectedItemChangedEvent().addListener(this);
getNetworkSelectedName().getEntityChangedEvent().removeListener(this);
getNetworkSelectedName().setEntity(getNetworkList().getSelectedItem());
getNetworkSelectedName().getEntityChangedEvent().addListener(this);
updateNetworkDisplay();
}
use of org.ovirt.engine.core.common.businessentities.VmInitNetwork in project ovirt-engine by oVirt.
the class VmInitModel method validate.
public boolean validate() {
getHostname().setIsValid(true);
getWindowsHostname().setIsValid(true);
getSysprepAdminPassword().setIsValid(true);
getSysprepAdminPasswordVerification().setIsValid(true);
getCloudInitRootPassword().setIsValid(true);
getCloudInitRootPasswordVerification().setIsValid(true);
if (this.isWindowsOS) {
if (getSysprepPasswordEnabled()) {
getSysprepAdminPassword().validateEntity(new IValidation[] { new NotEmptyValidation(), new MatchFieldsValidator(getSysprepAdminPassword().getEntity(), getSysprepAdminPasswordVerification().getEntity()) });
}
} else {
if (getRootPasswordEnabled()) {
getCloudInitRootPassword().validateEntity(new IValidation[] { new NotEmptyValidation(), new MatchFieldsValidator(getCloudInitRootPassword().getEntity(), getCloudInitRootPasswordVerification().getEntity()) });
}
}
if (getHostnameEnabled()) {
if (this.isWindowsOS) {
getWindowsHostname().validateEntity(new IValidation[] { new HostnameValidation(), new LengthValidation(AsyncDataProvider.getInstance().getMaxVmNameLengthSysprep()) });
} else {
getHostname().validateEntity(new IValidation[] { new HostnameValidation(), new LengthValidation(AsyncDataProvider.getInstance().getMaxVmNameLength()) });
}
}
getSysprepDomain().setIsValid(true);
if (getDomainEnabled()) {
getSysprepDomain().setIsValid(new HostAddressValidation().validate(getSysprepDomain().getSelectedItem()).getSuccess());
}
getAuthorizedKeys().setIsValid(true);
getTimeZoneList().setIsValid(true);
if (getTimeZoneEnabled().getEntity()) {
getTimeZoneList().validateSelectedItem(new IValidation[] { new NotEmptyValidation() });
}
boolean networkIsValid = true;
getNetworkList().setIsValid(true);
getNetworkIpAddress().setIsValid(true);
getNetworkNetmask().setIsValid(true);
getNetworkGateway().setIsValid(true);
getNetworkIpv6Address().setIsValid(true);
getNetworkIpv6Prefix().setIsValid(true);
getNetworkIpv6Gateway().setIsValid(true);
boolean dnsIsValid = true;
getDnsServers().setIsValid(true);
getDnsSearchDomains().setIsValid(true);
if (getNetworkEnabled().getEntity()) {
saveNetworkFields();
for (Map.Entry<String, VmInitNetwork> entry : networkMap.entrySet()) {
String name = entry.getKey();
VmInitNetwork vmInitNetwork = entry.getValue();
if (vmInitNetwork.getBootProtocol() == Ipv4BootProtocol.STATIC_IP) {
if (!validateHidden(getNetworkList(), name, null, new IValidation[] { new VmInitNetworkNameValidation(), new NotEmptyValidation() }) || !validateHidden(getNetworkIpAddress(), vmInitNetwork.getIp(), null, new IValidation[] { new Ipv4AddressValidation() }) || !validateHidden(getNetworkNetmask(), vmInitNetwork.getNetmask(), null, new IValidation[] { new SubnetMaskValidation() }) || !validateHidden(getNetworkGateway(), vmInitNetwork.getGateway(), null, new IValidation[] { new Ipv4AddressValidation(true) })) {
getNetworkList().setSelectedItem(name);
networkIsValid = false;
break;
}
}
if (vmInitNetwork.getIpv6BootProtocol() == Ipv6BootProtocol.STATIC_IP) {
if (!validateHidden(getNetworkList(), name, null, new IValidation[] { new VmInitNetworkNameValidation(), new NotEmptyValidation() }) || !validateHidden(getNetworkIpv6Address(), vmInitNetwork.getIpv6Address(), null, new IValidation[] { new Ipv6AddressValidation() }) || !validateHidden(getNetworkIpv6Prefix(), vmInitNetwork.getIpv6Prefix(), null, new IValidation[] { new IntegerValidation(0, 128) }) || !validateHidden(getNetworkIpv6Gateway(), vmInitNetwork.getIpv6Gateway(), null, new IValidation[] { new Ipv6AddressValidation(true) })) {
getNetworkList().setSelectedItem(name);
networkIsValid = false;
break;
}
}
}
if (!networkMap.isEmpty()) {
if (getDnsServers().getEntity() != null) {
for (String server : tokenizeString(getDnsServers().getEntity())) {
if (!validateHidden(getDnsServers(), server, dnsServerListMessage, new IValidation[] { new IpAddressValidation() })) {
dnsIsValid = false;
break;
}
}
}
if (getDnsSearchDomains().getEntity() != null) {
for (String domain : tokenizeString(getDnsSearchDomains().getEntity())) {
if (!validateHidden(getDnsSearchDomains(), domain, null, new IValidation[] { new HostnameValidation() })) {
dnsIsValid = false;
break;
}
}
}
}
}
return getHostname().getIsValid() && getWindowsHostname().getIsValid() && getSysprepDomain().getIsValid() && getAuthorizedKeys().getIsValid() && getTimeZoneList().getIsValid() && getCloudInitRootPassword().getIsValid() && getSysprepAdminPassword().getIsValid() && networkIsValid && dnsIsValid;
}
use of org.ovirt.engine.core.common.businessentities.VmInitNetwork in project ovirt-engine by oVirt.
the class VmInitModel method networkSelectedName_SelectionChanged.
private void networkSelectedName_SelectionChanged() {
String oldName = getNetworkList().getSelectedItem();
String newName = getNetworkSelectedName().getEntity();
if (oldName != null && newName != null && !newName.trim().equals(oldName)) {
VmInitNetwork vmInitNetwork = networkMap.get(oldName);
newName = newName.trim();
if (newName.isEmpty() || networkMap.containsKey(newName)) {
getNetworkSelectedName().setEntity(oldName);
} else {
networkMap.remove(oldName);
networkMap.put(newName, vmInitNetwork);
getNetworkList().setItems(new ArrayList<>(networkMap.keySet()));
getNetworkList().setSelectedItem(newName);
}
}
}
Aggregations