diff --git a/src/flow/lib/LifeCycleManager.rb b/src/flow/lib/LifeCycleManager.rb index b06a0fd319..c9f561cc6c 100644 --- a/src/flow/lib/LifeCycleManager.rb +++ b/src/flow/lib/LifeCycleManager.rb @@ -858,13 +858,24 @@ class ServiceLCM rc = @srv_pool.get(service_id, client) do |service| service.remove_role(role_name) - service.set_state(Service::STATE['RUNNING']) + if service.all_roles_done? + rc = service.delete_networks - rc = service.update + if rc && !rc.empty? + Log.info LOG_COMP, 'Error trying to delete '\ + "Virtual Networks #{rc}" + end - return rc if OpenNebula.is_error?(rc) + service.delete + else + service.set_state(Service::STATE['RUNNING']) - @wd.add_service(service) if service.all_roles_running? + rc = service.update + + return rc if OpenNebula.is_error?(rc) + + @wd.add_service(service) if service.all_roles_running? + end end Log.error LOG_COMP, rc.message if OpenNebula.is_error?(rc) diff --git a/src/sunstone/models/sunstone_guac.rb b/src/sunstone/models/sunstone_guac.rb index c009d52c79..b824bd2ae8 100644 --- a/src/sunstone/models/sunstone_guac.rb +++ b/src/sunstone/models/sunstone_guac.rb @@ -26,9 +26,9 @@ require 'openssl' require 'sunstone_remotes' if !ONE_LOCATION - VAR_LOCATION = '/var/lib/one/' + VAR_LOCATION ||= '/var/lib/one/' else - VAR_LOCATION = ONE_LOCATION + '/var/' + VAR_LOCATION ||= ONE_LOCATION + '/var/' end FIREEDGE_KEY = VAR_LOCATION + '/.one/fireedge_key' diff --git a/src/sunstone/public/app/opennebula/role.js b/src/sunstone/public/app/opennebula/role.js index f39fd33e72..dd9de2d3bf 100644 --- a/src/sunstone/public/app/opennebula/role.js +++ b/src/sunstone/public/app/opennebula/role.js @@ -189,6 +189,44 @@ define(function(require) { } }); }, + "remove" : function(params) { + var request = OpenNebulaHelper.request(RESOURCE, "remove", params.data.id); + + $.ajax({ + url: PATH + "/" + String(params.data.id) + "/role_action", + type: "POST", + dataType: "json", + contentType: "application/json; charset=utf-8", + data: JSON.stringify(params.data.extra_param), + success: function(response) { + return params.success ? params.success(request, response) : null; + }, + error: function(response) { + response.status === 201 + ? params.success ? params.success(request, response) : null + : params.error ? params.error(request, OpenNebulaError(response)) : null; + } + }); + }, + "add" : function(params) { + var request = OpenNebulaHelper.request(RESOURCE, "add", params.data.id); + + $.ajax({ + url: PATH + "/" + String(params.data.id) + "/role_action", + type: "POST", + dataType: "json", + contentType: "application/json; charset=utf-8", + data: JSON.stringify(params.data.extra_param), + success: function(response) { + return params.success ? params.success(request, response) : null; + }, + error: function(response) { + response.status === 201 + ? params.success ? params.success(request, response) : null + : params.error ? params.error(request, OpenNebulaError(response)) : null; + } + }); + }, } return Role; diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab.js b/src/sunstone/public/app/tabs/oneflow-services-tab.js index 0c0a695656..a18c668338 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab.js +++ b/src/sunstone/public/app/tabs/oneflow-services-tab.js @@ -26,6 +26,7 @@ define(function(require) { var _dialogs = [ require('./oneflow-services-tab/dialogs/scale'), + require('./oneflow-services-tab/dialogs/add'), ]; var _panels = [ diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/actions.js b/src/sunstone/public/app/tabs/oneflow-services-tab/actions.js index 8a1d2dcc5f..b08109016b 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab/actions.js +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/actions.js @@ -29,6 +29,8 @@ define(function(require) { var ROLES_PANEL_ID = require('./panels/roles/panelId'); var SCALE_DIALOG_ID = require('./dialogs/scale/dialogId'); + var ADD_DIALOG_ID = require('./dialogs/add/dialogId'); + var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId'); var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); var UPDATE_DIALOG_ID = require('./form-panels/update/formPanelId'); @@ -317,6 +319,84 @@ define(function(require) { notify: true }, + "Role.remove_dialog" : { + type: "custom", + call: function(){ + params = roleElement(); + + if(!params.serviceId || !params.roleName) { + Notifier.onError("Select one role"); + return; + } + + var obj = { + "action": { + "perform":"remove_role", + "params" : { + "role" : params.roleName + } + } + } + + Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({ + header : Locale.tr("Confirm"), + headerTabId: TAB_ID, + body : "", + question : Locale.tr("Are you sure you want to delete the role") + " " + params.roleName + "?", + buttons : [ + Locale.tr("Confirm"), + ], + submit : [ + function(){ + Sunstone.getDialog(CONFIRM_DIALOG_ID).hide(); + Sunstone.runAction('Role.remove', params.serviceId, obj); + return false; + } + ] + }); + Sunstone.getDialog(CONFIRM_DIALOG_ID).reset(); + Sunstone.getDialog(CONFIRM_DIALOG_ID).show(); + } + }, + + "Role.remove" : { + type: "single", + call: OpenNebulaRole.remove, + callback : function() { + Sunstone.getDialog(CONFIRM_DIALOG_ID).hide(); + roleCallback(); + }, + error: function(request, response) { + Sunstone.getDialog(CONFIRM_DIALOG_ID).hide(); + Notifier.onError(request, response); + }, + notify: true + }, + + "Role.add" : { + type: "single", + call: OpenNebulaRole.add, + callback : function() { + Sunstone.getDialog(ADD_DIALOG_ID).hide(); + roleCallback(); + }, + error: function(request, response) { + Sunstone.getDialog(ADD_DIALOG_ID).hide(); + Notifier.onError(request, response); + }, + notify: true + }, + + "Role.add_dialog" : { + type: "custom", + call: function(){ + params = roleElement(); + + Sunstone.getDialog(ADD_DIALOG_ID).reset(); + Sunstone.getDialog(ADD_DIALOG_ID).show(); + } + }, + //-------------------------------------------------------------------------- "RoleVM.deploy" : { diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add.js b/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add.js new file mode 100644 index 0000000000..5b3c813a82 --- /dev/null +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/dialogs/add.js @@ -0,0 +1,124 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./add/html'); + var Sunstone = require('sunstone'); + var Notifier = require('utils/notifier'); + var Locale = require('utils/locale'); + var Tips = require('utils/tips'); + var RoleTab = require('tabs/oneflow-services-tab/utils/role-tab'); + var OpenNebulaRole = require("opennebula/role"); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./add/dialogId'); + var TAB_ID = require('../tabId'); + + /* + CONSTRUCTOR + */ + + function Dialog() { + this.dialogId = DIALOG_ID; + + BaseDialog.call(this); + } + + Dialog.DIALOG_ID = DIALOG_ID; + Dialog.prototype = Object.create(BaseDialog.prototype); + Dialog.prototype.constructor = Dialog; + Dialog.prototype.html = _html; + Dialog.prototype.onShow = _onShow; + Dialog.prototype.setup = _setup; + Dialog.prototype.setParams = _setParams; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'dialogId': this.dialogId + }); + } + + function _onShow(context) { + this.setNames( {tabId: TAB_ID} ); + } + + function _setup(context) { + var that = this; + + var html_role_id = "newRole"; + + var role = new RoleTab(html_role_id) + + var role_section = $("