From b7a136f2a278db22db15937b6ac8233b7430eeab Mon Sep 17 00:00:00 2001 From: Jorge Lobo <47326048+jloboescalona2@users.noreply.github.com> Date: Thu, 6 Jun 2019 13:15:42 +0200 Subject: [PATCH] Bug 3195 remove OPENNEBULA_MANAGED attribute (#3407) * B #3195: remove OPENNEBULA_MANAGED attribute Signed-off-by: Jorge Lobo * B #3195: remove OPENNEBULA_MANAGED attribute Signed-off-by: Jorge Lobo --- .../public/app/opennebula/template.js | 19 ++++++-- .../form-panels/create-common.js | 46 ++++++++++++++++++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/sunstone/public/app/opennebula/template.js b/src/sunstone/public/app/opennebula/template.js index 48ff1aad6c..a6d2a81a3a 100644 --- a/src/sunstone/public/app/opennebula/template.js +++ b/src/sunstone/public/app/opennebula/template.js @@ -15,13 +15,21 @@ /* -------------------------------------------------------------------------- */ define(function(require) { - var OpenNebulaAction = require('./action'); - var Config = require('sunstone-config'); + var OpenNebulaAction = require("./action"); + var Config = require("sunstone-config"); var RESOURCE = "VMTEMPLATE"; + window.lastInfoVmTemplate = {}; var Template = { "resource": RESOURCE, + "setLastResource": function(info={}){ + var data = {}; + if(info && info.data){ + data.data = info.data; + window.lastInfoVmTemplate = data; + } + }, "create" : function(params) { OpenNebulaAction.create(params, RESOURCE); }, @@ -37,6 +45,7 @@ define(function(require) { OpenNebulaAction.list(params, RESOURCE); }, "show" : function(params) { + Template.setLastResource(params); OpenNebulaAction.show(params, RESOURCE); }, "chown" : function(params) { @@ -91,7 +100,7 @@ define(function(require) { }, "isNetworkChangeEnabled": function(template) { if (template.VMTEMPLATE.TEMPLATE.SUNSTONE && - template.VMTEMPLATE.TEMPLATE.SUNSTONE.NETWORK_SELECT == 'NO') { + template.VMTEMPLATE.TEMPLATE.SUNSTONE.NETWORK_SELECT == "NO") { return false; } else { return true; @@ -158,7 +167,7 @@ define(function(require) { return cost; } - } + }; return Template; -}) +}); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js index 65fb3b8d31..f8863192de 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js @@ -206,7 +206,51 @@ define(function(require) { Sunstone.runAction(this.resource+".create", {"vmtemplate": templateJSON}); return false; } else if (this.action == "update") { - Sunstone.runAction(this.resource+".update", this.resourceId, TemplateUtils.templateToString(templateJSON)); + var actionUpdate = this.resource + ".update"; + var resourceId = this.resourceId; + if( + window && + window.lastInfoVmTemplate && + window.lastInfoVmTemplate.data && + templateJSON && + templateJSON.DISK && + templateJSON.HYPERVISOR && + templateJSON.HYPERVISOR === "vcenter" + ){ + params = { + data: window.lastInfoVmTemplate.data, + success: function(request, response){ + if(response){ + var template = response.VMTEMPLATE && response.VMTEMPLATE.TEMPLATE; + if(template && template.DISK){ + var lastDisk = template.DISK; + var newDisk = templateJSON.DISK[0]; + var setNewdisk = function(){ + if(lastDisk.OPENNEBULA_MANAGED && lastDisk.OPENNEBULA_MANAGED === "NO" ){ + newDisk.LAST_IMAGE_DISK = (lastDisk && lastDisk.IMAGE_ID) || (lastDisk && lastDisk.IMAGE); + delete newDisk.OPENNEBULA_MANAGED; + } + }; + if(lastDisk && lastDisk.LAST_IMAGE_DISK){ + if(lastDisk.LAST_IMAGE_DISK === newDisk.IMAGE || lastDisk.LAST_IMAGE_DISK === newDisk.IMAGE_ID){ + newDisk.OPENNEBULA_MANAGED = "NO"; + delete newDisk.LAST_IMAGE_DISK; + }else{ + setNewdisk(); + } + }else{ + setNewdisk(); + } + templateJSON.DISK = [newDisk]; + Sunstone.runAction(actionUpdate, resourceId, TemplateUtils.templateToString(templateJSON)); + } + } + } + }; + OpenNebulaAction.show(params,OpenNebulaTemplate.resource); + }else{ + Sunstone.runAction(actionUpdate, resourceId, TemplateUtils.templateToString(templateJSON)); + } return false; } }