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);
}
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;
}
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);
}
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();
}
Aggregations