Search in sources :

Example 31 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class CloudInitHandlerTest method setUp.

@Before
public void setUp() {
    vmInit = new VmInit();
    underTest = new CloudInitHandler(vmInit, CloudInitHandler.NetConfigSourceProtocol.ENI);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) Before(org.junit.Before)

Example 32 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class InitializationMapper method map.

@Mapping(from = Initialization.class, to = VmInit.class)
public static VmInit map(Initialization model, VmInit template) {
    VmInit entity = template != null ? template : new VmInit();
    boolean someSubTagSet = false;
    if (model.isSetHostName()) {
        someSubTagSet = true;
        entity.setHostname(model.getHostName());
    }
    if (model.isSetDomain()) {
        someSubTagSet = true;
        entity.setDomain(model.getDomain());
    }
    if (model.isSetTimezone()) {
        someSubTagSet = true;
        entity.setTimeZone(model.getTimezone());
    }
    if (model.isSetAuthorizedSshKeys()) {
        someSubTagSet = true;
        entity.setAuthorizedKeys(model.getAuthorizedSshKeys());
    }
    if (model.isSetRegenerateSshKeys()) {
        someSubTagSet = true;
        entity.setRegenerateKeys(model.isRegenerateSshKeys());
    }
    if (model.isSetDnsServers()) {
        someSubTagSet = true;
        entity.setDnsServers(model.getDnsServers());
    }
    if (model.isSetDnsSearch()) {
        someSubTagSet = true;
        entity.setDnsSearch(model.getDnsSearch());
    }
    if (model.isSetWindowsLicenseKey()) {
        someSubTagSet = true;
        entity.setWinKey(model.getWindowsLicenseKey());
    }
    if (model.isSetRootPassword()) {
        someSubTagSet = true;
        entity.setRootPassword(model.getRootPassword());
    }
    if (model.isSetCustomScript()) {
        someSubTagSet = true;
        entity.setCustomScript(model.getCustomScript());
    }
    if (model.isSetNicConfigurations()) {
        someSubTagSet = true;
        List<VmInitNetwork> networks = new ArrayList<>();
        for (NicConfiguration nic : model.getNicConfigurations().getNicConfigurations()) {
            networks.add(map(nic, null));
        }
        entity.setNetworks(networks);
    }
    if (model.isSetInputLocale()) {
        someSubTagSet = true;
        entity.setInputLocale(model.getInputLocale());
    }
    if (model.isSetUiLanguage()) {
        someSubTagSet = true;
        entity.setUiLanguage(model.getUiLanguage());
    }
    if (model.isSetSystemLocale()) {
        someSubTagSet = true;
        entity.setSystemLocale(model.getSystemLocale());
    }
    if (model.isSetUserLocale()) {
        someSubTagSet = true;
        entity.setUserLocale(model.getUserLocale());
    }
    if (model.isSetUserName()) {
        someSubTagSet = true;
        entity.setUserName(model.getUserName());
    }
    if (model.isSetActiveDirectoryOu()) {
        someSubTagSet = true;
        entity.setActiveDirectoryOU(model.getActiveDirectoryOu());
    }
    if (model.isSetOrgName()) {
        someSubTagSet = true;
        entity.setOrgName(model.getOrgName());
    }
    if (model.isSetCloudInit()) {
        someSubTagSet = true;
        VmMapper.map(model.getCloudInit(), entity);
    }
    if (!someSubTagSet) {
        return null;
    }
    return entity;
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) ArrayList(java.util.ArrayList) NicConfiguration(org.ovirt.engine.api.model.NicConfiguration)

Example 33 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class AddVmCommand method addVmInit.

private void addVmInit() {
    final VmInit vmInit = getParameters().getVmStaticData().getVmInit();
    if (vmInit == null) {
        return;
    }
    if (vmInit.isPasswordAlreadyStored()) {
        final VmInit originalVmInit = loadOriginalVmInitWithRootPassword();
        if (originalVmInit != null) {
            vmInit.setPasswordAlreadyStored(false);
            vmInit.setRootPassword(originalVmInit.getRootPassword());
        }
    }
    vmHandler.addVmInitToDB(vmInit);
}
Also used : VmInit(org.ovirt.engine.core.common.businessentities.VmInit)

Example 34 with VmInit

use of org.ovirt.engine.core.common.businessentities.VmInit in project ovirt-engine by oVirt.

the class VmInitModel method init.

public void init(final VmBase vm) {
    getWindowsSysprepTimeZoneEnabled().setEntity(false);
    getRegenerateKeysEnabled().setEntity(false);
    getTimeZoneEnabled().setEntity(false);
    getNetworkEnabled().setEntity(false);
    getAttachmentEnabled().setEntity(false);
    getCloudInitPasswordSet().setEntity(false);
    getCloudInitPasswordSet().setIsChangeable(false);
    getSysprepPasswordSet().setEntity(false);
    getSysprepPasswordSet().setIsChangeable(false);
    getWindowsHostname().setEntity("");
    getSysprepOrgName().setEntity("");
    getInputLocale().setEntity("");
    getUiLanguage().setEntity("");
    getSystemLocale().setEntity("");
    getUserLocale().setEntity("");
    getSysprepScript().setEntity("");
    getHostname().setEntity("");
    getUserName().setEntity("");
    getCloudInitRootPassword().setEntity("");
    getCloudInitRootPasswordVerification().setEntity("");
    getSysprepAdminPassword().setEntity("");
    getSysprepAdminPasswordVerification().setEntity("");
    getAuthorizedKeys().setEntity("");
    getRegenerateKeysEnabled().setEntity(false);
    getCustomScript().setEntity("");
    getActiveDirectoryOU().setEntity("");
    Map<String, String> timezones = TimeZoneType.GENERAL_TIMEZONE.getTimeZoneList();
    getTimeZoneList().setItems(timezones.entrySet());
    getTimeZoneList().setSelectedItem(Linq.firstOrNull(timezones.entrySet(), // $NON-NLS-1$
    item -> item.getValue().startsWith("(GMT) Greenwich")));
    Map<String, String> windowsTimezones = TimeZoneType.WINDOWS_TIMEZONE.getTimeZoneList();
    getWindowsSysprepTimeZone().setItems(windowsTimezones.entrySet());
    getWindowsSysprepTimeZone().setSelectedItem(Linq.firstOrNull(windowsTimezones.entrySet(), // $NON-NLS-1$
    item -> item.getValue().startsWith("(GMT) Greenwich")));
    isWindowsOS = vm != null ? AsyncDataProvider.getInstance().isWindowsOsType(vm.getOsId()) : true;
    getIpv4BootProtocolList().setItems(Arrays.asList(Ipv4BootProtocol.values()));
    getIpv4BootProtocolList().setSelectedItem(Ipv4BootProtocol.NONE);
    // only add values which are supported by cloud-init. autoconf ('stateless address autconfiguration') is not supported by cloud-init 0.7.9
    getIpv6BootProtocolList().setItems(Arrays.asList(Ipv6BootProtocol.NONE, Ipv6BootProtocol.DHCP, Ipv6BootProtocol.STATIC_IP));
    getIpv6BootProtocolList().setSelectedItem(Ipv6BootProtocol.NONE);
    VmInit vmInit = (vm != null) ? vm.getVmInit() : null;
    if (vmInit != null) {
        if (!StringHelper.isNullOrEmpty(vmInit.getHostname())) {
            getHostname().setEntity(vmInit.getHostname());
            getWindowsHostname().setEntity(vmInit.getHostname());
        }
        if (!StringHelper.isNullOrEmpty(vmInit.getOrgName())) {
            getSysprepOrgName().setEntity(vmInit.getOrgName());
        }
        updateSysprepDomain(vmInit.getDomain());
        if (!StringHelper.isNullOrEmpty(vmInit.getInputLocale())) {
            getInputLocale().setEntity(vmInit.getInputLocale());
        }
        if (!StringHelper.isNullOrEmpty(vmInit.getUiLanguage())) {
            getUiLanguage().setEntity(vmInit.getUiLanguage());
        }
        if (!StringHelper.isNullOrEmpty(vmInit.getSystemLocale())) {
            getSystemLocale().setEntity(vmInit.getSystemLocale());
        }
        if (!StringHelper.isNullOrEmpty(vmInit.getUserLocale())) {
            getUserLocale().setEntity(vmInit.getUserLocale());
        }
        final String tz = vmInit.getTimeZone();
        if (!StringHelper.isNullOrEmpty(tz)) {
            if (AsyncDataProvider.getInstance().isWindowsOsType(vm.getOsId())) {
                getWindowsSysprepTimeZoneEnabled().setEntity(true);
                selectTimeZone(getWindowsSysprepTimeZone(), windowsTimezones, tz);
            } else {
                getTimeZoneEnabled().setEntity(true);
                selectTimeZone(getTimeZoneList(), timezones, tz);
            }
        }
        if (!StringHelper.isNullOrEmpty(vmInit.getUserName())) {
            getUserName().setEntity(vmInit.getUserName());
        }
        if (!StringHelper.isNullOrEmpty(vmInit.getRootPassword())) {
            getCloudInitRootPassword().setEntity(vmInit.getRootPassword());
            getCloudInitRootPasswordVerification().setEntity(vmInit.getRootPassword());
            getSysprepAdminPassword().setEntity(vmInit.getRootPassword());
            getSysprepAdminPasswordVerification().setEntity(vmInit.getRootPassword());
        }
        getCloudInitPasswordSet().setEntity(vmInit.isPasswordAlreadyStored());
        getCloudInitPasswordSet().setIsChangeable(vmInit.isPasswordAlreadyStored());
        getSysprepPasswordSet().setEntity(vmInit.isPasswordAlreadyStored());
        getSysprepPasswordSet().setIsChangeable(vmInit.isPasswordAlreadyStored());
        if (!StringHelper.isNullOrEmpty(vmInit.getAuthorizedKeys())) {
            getAuthorizedKeys().setEntity(vmInit.getAuthorizedKeys());
        }
        if (vmInit.getRegenerateKeys() != null) {
            getRegenerateKeysEnabled().setEntity(vmInit.getRegenerateKeys());
        }
        if (!StringHelper.isNullOrEmpty(vmInit.getCustomScript())) {
            if (isWindowsOS) {
                getSysprepScript().setEntity(vmInit.getCustomScript());
            } else {
                getCustomScript().setEntity(vmInit.getCustomScript());
            }
        }
        if (!StringHelper.isNullOrEmpty(vmInit.getActiveDirectoryOU())) {
            getActiveDirectoryOU().setEntity(vmInit.getActiveDirectoryOU());
        }
        initNetworks(vmInit);
    }
    addHostnameListeners();
}
Also used : NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) SubnetMaskValidation(org.ovirt.engine.ui.uicommonweb.validation.SubnetMaskValidation) Arrays(java.util.Arrays) TimeZoneType(org.ovirt.engine.core.common.TimeZoneType) Event(org.ovirt.engine.ui.uicompat.Event) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Ipv6BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol) HostnameValidation(org.ovirt.engine.ui.uicommonweb.validation.HostnameValidation) Map(java.util.Map) Ipv4AddressValidation(org.ovirt.engine.ui.uicommonweb.validation.Ipv4AddressValidation) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) HasEntity(org.ovirt.engine.ui.uicommonweb.models.HasEntity) IpAddressValidation(org.ovirt.engine.ui.uicommonweb.validation.IpAddressValidation) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) Model(org.ovirt.engine.ui.uicommonweb.models.Model) IntegerValidation(org.ovirt.engine.ui.uicommonweb.validation.IntegerValidation) VmInitNetworkNameValidation(org.ovirt.engine.ui.uicommonweb.validation.VmInitNetworkNameValidation) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Linq(org.ovirt.engine.ui.uicommonweb.Linq) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) StringHelper(org.ovirt.engine.core.compat.StringHelper) Ipv4BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol) MatchFieldsValidator(org.ovirt.engine.ui.uicommonweb.validation.MatchFieldsValidator) VmInitNetwork(org.ovirt.engine.core.common.businessentities.VmInitNetwork) Ipv6AddressValidation(org.ovirt.engine.ui.uicommonweb.validation.Ipv6AddressValidation) List(java.util.List) TreeMap(java.util.TreeMap) VmInit(org.ovirt.engine.core.common.businessentities.VmInit) LengthValidation(org.ovirt.engine.ui.uicommonweb.validation.LengthValidation) HostAddressValidation(org.ovirt.engine.ui.uicommonweb.validation.HostAddressValidation) SortedMap(java.util.SortedMap) VmInit(org.ovirt.engine.core.common.businessentities.VmInit)

Aggregations

VmInit (org.ovirt.engine.core.common.businessentities.VmInit)34 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)14 Pair (org.ovirt.engine.core.common.utils.Pair)10 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 Map (java.util.Map)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 Guid (org.ovirt.engine.core.compat.Guid)3 List (java.util.List)2 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)2 Ipv4BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)2 IdsQueryParameters (org.ovirt.engine.core.common.queries.IdsQueryParameters)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)2 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 Before (org.junit.Before)1