Fix XenServer nested extra configuration (#8698)

This commit is contained in:
Gabriel Pordeus Santos 2024-03-25 07:19:16 -03:00 committed by GitHub
parent 4b4dfef96f
commit adc05f8d59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View File

@ -1972,7 +1972,7 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
// Add configuration settings VM record for User VM instances before creating VM // Add configuration settings VM record for User VM instances before creating VM
Map<String, String> extraConfig = vmSpec.getExtraConfig(); Map<String, String> extraConfig = vmSpec.getExtraConfig();
if (vmSpec.getType().equals(VirtualMachine.Type.User) && MapUtils.isNotEmpty(extraConfig)) { if (vmSpec.getType().equals(VirtualMachine.Type.User) && MapUtils.isNotEmpty(extraConfig)) {
logger.info("Appending user extra configuration settings to VM"); logger.info("Appending user extra configuration settings [{}] to [{}].", extraConfig, vmSpec);
ExtraConfigurationUtility.setExtraConfigurationToVm(conn,vmr, vm, extraConfig); ExtraConfigurationUtility.setExtraConfigurationToVm(conn,vmr, vm, extraConfig);
} }
} }

View File

@ -43,6 +43,7 @@ public class ExtraConfigurationUtility {
String paramValue = configParams.get(paramKey); String paramValue = configParams.get(paramKey);
//Map params //Map params
LOGGER.debug("Applying [{}] configuration as [{}].", paramKey, paramValue);
if (paramKey.contains(":")) { if (paramKey.contains(":")) {
applyConfigWithNestedKeyValue(conn, vm, recordMap, paramKey, paramValue); applyConfigWithNestedKeyValue(conn, vm, recordMap, paramKey, paramValue);
} else { } else {
@ -55,6 +56,11 @@ public class ExtraConfigurationUtility {
return recordMap.containsKey(actualParam); return recordMap.containsKey(actualParam);
} }
private static Map<String, String> putInMap(Map<String, String> map, String key, String value) {
map.put(key, value);
return map;
}
/** /**
* Nested keys contain ":" between the paramKey and need to split into operation param and key * Nested keys contain ":" between the paramKey and need to split into operation param and key
* */ * */
@ -71,26 +77,27 @@ public class ExtraConfigurationUtility {
try { try {
switch (actualParam) { switch (actualParam) {
case "VCPUs_params": case "VCPUs_params":
vm.addToVCPUsParams(conn, keyName, paramValue); vm.setVCPUsParams(conn, putInMap(vm.getVCPUsParams(conn), keyName, paramValue));
break; break;
case "platform": case "platform":
vm.addToOtherConfig(conn, keyName, paramValue); vm.setOtherConfig(conn, putInMap(vm.getOtherConfig(conn), keyName, paramValue));
break; break;
case "HVM_boot_params": case "HVM_boot_params":
vm.addToHVMBootParams(conn, keyName, paramValue); vm.setHVMBootParams(conn, putInMap(vm.getHVMBootParams(conn), keyName, paramValue));
break; break;
case "other_config": case "other_config":
vm.addToOtherConfig(conn, keyName, paramValue); vm.setOtherConfig(conn, putInMap(vm.getOtherConfig(conn), keyName, paramValue));
break; break;
case "xenstore_data": case "xenstore_data":
vm.addToXenstoreData(conn, keyName, paramValue); vm.setXenstoreData(conn, putInMap(vm.getXenstoreData(conn), keyName, paramValue));
break; break;
default: default:
String msg = String.format("Passed configuration %s is not supported", paramKey); String msg = String.format("Passed configuration %s is not supported", paramKey);
LOGGER.warn(msg); LOGGER.warn(msg);
} }
} catch (XmlRpcException | Types.XenAPIException e) { } catch (XmlRpcException | Types.XenAPIException e) {
LOGGER.error("Exception caught while setting VM configuration. exception: " + e.getMessage()); LOGGER.error("Exception caught while setting VM configuration: [{}]", e.getMessage() == null ? e.toString() : e.getMessage());
LOGGER.debug("Exception caught while setting VM configuration", e);
throw new CloudRuntimeException("Exception caught while setting VM configuration", e); throw new CloudRuntimeException("Exception caught while setting VM configuration", e);
} }
} }