Search in sources :

Example 1 with VmInitNetwork

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);
            }
        }
    }
}
Also used : VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork)

Example 2 with VmInitNetwork

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;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 3 with VmInitNetwork

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();
}
Also used : VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork)

Example 4 with VmInitNetwork

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;
}
Also used : Ipv6AddressValidation(org.ovirt.engine.ui.uicommonweb.validation.Ipv6AddressValidation) HostnameValidation(org.ovirt.engine.ui.uicommonweb.validation.HostnameValidation) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Ipv4AddressValidation(org.ovirt.engine.ui.uicommonweb.validation.Ipv4AddressValidation) VmInitNetworkNameValidation(org.ovirt.engine.ui.uicommonweb.validation.VmInitNetworkNameValidation) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) IpAddressValidation(org.ovirt.engine.ui.uicommonweb.validation.IpAddressValidation) MatchFieldsValidator(org.ovirt.engine.ui.uicommonweb.validation.MatchFieldsValidator) NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) HostAddressValidation(org.ovirt.engine.ui.uicommonweb.validation.HostAddressValidation) LengthValidation(org.ovirt.engine.ui.uicommonweb.validation.LengthValidation) SubnetMaskValidation(org.ovirt.engine.ui.uicommonweb.validation.SubnetMaskValidation) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) IntegerValidation(org.ovirt.engine.ui.uicommonweb.validation.IntegerValidation)

Example 5 with VmInitNetwork

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);
        }
    }
}
Also used : VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork)

Aggregations

VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)23 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)13 Pair (org.ovirt.engine.core.common.utils.Pair)10 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 Ipv4BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 AuthorizedKey (org.ovirt.engine.api.model.AuthorizedKey)1 File (org.ovirt.engine.api.model.File)1 Host (org.ovirt.engine.api.model.Host)1 Nic (org.ovirt.engine.api.model.Nic)1 NicConfiguration (org.ovirt.engine.api.model.NicConfiguration)1 User (org.ovirt.engine.api.model.User)1 Ipv6BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol)1 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)1 HostAddressValidation (org.ovirt.engine.ui.uicommonweb.validation.HostAddressValidation)1 HostnameValidation (org.ovirt.engine.ui.uicommonweb.validation.HostnameValidation)1