1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

B #5238: Sunstone not to override unmodified templates (#1751)

in VM instantiate
This commit is contained in:
Frederick Borges 2022-02-04 11:36:29 +01:00 committed by GitHub
parent 688e73b388
commit 94574a5f89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -222,6 +222,24 @@ define(function(require) {
});
}
function diffValues(newValues, oldValues){
var diff = [];
if(oldValues && newValues){
oldValues = Array.isArray(oldValues)? oldValues: [oldValues];
newValues = Array.isArray(newValues)? newValues: [newValues];
var oldValuesString = oldValues.map(function(internalValue){
return JSON.stringify(internalValue);
});
newValues.forEach(function (newValue){
if($.inArray(JSON.stringify(newValue),oldValuesString) === -1){
diff.push(newValue);
}
});
}
return diff;
}
function _calculateCost(){
$.each($(".template-row", this.formContext), function(){
var capacity_val = parseFloat( $(".capacity_cost_div .cost_value", $(this)).text() );
@ -273,6 +291,8 @@ define(function(require) {
}
$.each(this.selected_nodes, function(index, template_id) {
var original_tmpl = that.template_objects[index].VMTEMPLATE;
var extra_info = {
"hold": hold
};
@ -287,7 +307,7 @@ define(function(require) {
var disks = DisksResize.retrieve($(".disksContext" + template_id, context));
if (disks.length > 0) {
tmp_json.DISK = disks;
tmp_json.DISK = diffValues(disks, original_tmpl.TEMPLATE.DISK);
}
var networks = NicsSection.retrieve($(".nicsContext" + template_id, context));
@ -361,8 +381,6 @@ define(function(require) {
tmp_json.NIC_ALIAS = alias;
// Replace PCIs of type nic only
var original_tmpl = that.template_objects[index].VMTEMPLATE;
var regular_pcis = [];
if(original_tmpl.TEMPLATE.PCI != undefined){
@ -405,7 +423,18 @@ define(function(require) {
}
capacityContext = $(".capacityContext" + template_id, context);
$.extend(tmp_json, CapacityInputs.retrieveChanges(capacityContext));
capacityRetrieveValues = CapacityInputs.retrieveChanges(capacityContext);
for (const key in capacityRetrieveValues) {
if (capacityRetrieveValues.hasOwnProperty(key)) {
var diff = diffValues(
{[key]: capacityRetrieveValues[key]},
{[key]:original_tmpl.TEMPLATE[key]}
);
if(diff && diff[0] && typeof diff[0] === "object"){
$.extend(tmp_json, diff[0]);
}
}
}
var topology = {}