diff --git a/src/flow/lib/models/service.rb b/src/flow/lib/models/service.rb index 128446cd76..d1e94051bc 100644 --- a/src/flow/lib/models/service.rb +++ b/src/flow/lib/models/service.rb @@ -403,6 +403,18 @@ module OpenNebula return @body['shutdown_action'] end + # Replaces the raw template contents + # + # @param template [String] New template contents, in the form KEY = VAL + # @param append [true, false] True to append new attributes instead of + # replace the whole template + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def update_raw(template_raw, append=false) + super(template_raw, append) + end + private # @param [Logger::Severity] severity diff --git a/src/flow/lib/models/service_template.rb b/src/flow/lib/models/service_template.rb index b21c7c810d..b4105a1a14 100644 --- a/src/flow/lib/models/service_template.rb +++ b/src/flow/lib/models/service_template.rb @@ -198,14 +198,44 @@ module OpenNebula @body.to_json end - def update(template_json) + # Replaces the template contents + # + # @param template_json [String] New template contents + # @param append [true, false] True to append new attributes instead of + # replace the whole template + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def update(template_json, append=false) template = JSON.parse(template_json) + if(append) + rc = info() + + if(OpenNebula.is_error?(rc)) + return rc + end + + template = @body.merge(template) + end + ServiceTemplate.validate(template) super(template.to_json) end + # Replaces the raw template contents + # + # @param template [String] New template contents, in the form KEY = VAL + # @param append [true, false] True to append new attributes instead of + # replace the whole template + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def update_raw(template_raw, append=false) + super(template_raw, append) + end + def self.validate(template) validator = Validator::Validator.new( :default_values => true, diff --git a/src/flow/oneflow-server.rb b/src/flow/oneflow-server.rb index 0b1c6bb37d..e870d78c23 100644 --- a/src/flow/oneflow-server.rb +++ b/src/flow/oneflow-server.rb @@ -247,6 +247,22 @@ post '/service/:id/action' do end when 'rename' service.rename(opts['name']) + when 'update' + if opts && opts['template_raw'] + if (opts['append'] == true) + rc = service.update_raw( + opts['template_raw'], + (opts['append'] == true)) + + status 204 + else + OpenNebula::Error.new("Action #{action['perform']}: " << + "Only supported for append") + end + else + OpenNebula::Error.new("Action #{action['perform']}: " << + "You have to provide a raw template") + end else OpenNebula::Error.new("Action #{action['perform']} not supported") end @@ -499,11 +515,20 @@ post '/service_template/:id/action' do when 'update' if opts && opts['template_json'] begin - rc = service_template.update(opts['template_json']) + rc = service_template.update( + opts['template_json'], + (opts['append'] == true)) + status 204 rescue Validator::ParseException, JSON::ParserError OpenNebula::Error.new($!.message) end + elsif opts && opts['template_raw'] + rc = service_template.update_raw( + opts['template_raw'], + (opts['append'] == true)) + + status 204 else OpenNebula::Error.new("Action #{action['perform']}: " << "You have to provide a template") diff --git a/src/oca/ruby/opennebula/document.rb b/src/oca/ruby/opennebula/document.rb index 223a59099c..30802fe1db 100644 --- a/src/oca/ruby/opennebula/document.rb +++ b/src/oca/ruby/opennebula/document.rb @@ -134,6 +134,21 @@ module OpenNebula super(DOCUMENT_METHODS[:update], new_template, append ? 1 : 0) end + # Replaces the raw template contents + # + # @param template [String] New template contents, in the form KEY = VAL + # @param append [true, false] True to append new attributes instead of + # replace the whole template + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def update_raw(template_raw, append=false) + rc = check_type() + return rc if OpenNebula.is_error?(rc) + + return call(DOCUMENT_METHODS[:update], @pe_id, template_raw, append ? 1 : 0) + end + # Changes the owner/group # # @param [Integer] uid the new owner id. Set to -1 to leave the current one diff --git a/src/oca/ruby/opennebula/document_json.rb b/src/oca/ruby/opennebula/document_json.rb index 305c11988f..d089f36da8 100644 --- a/src/oca/ruby/opennebula/document_json.rb +++ b/src/oca/ruby/opennebula/document_json.rb @@ -70,6 +70,18 @@ module OpenNebula super(text, append) end + # Replaces the raw template contents + # + # @param template [String] New template contents, in the form KEY = VAL + # @param append [true, false] True to append new attributes instead of + # replace the whole template + # + # @return [nil, OpenNebula::Error] nil in case of success, Error + # otherwise + def update_raw(template_raw, append=false) + super(template_raw, append) + end + # Generates a json representing the object # # @param [true, false] pretty_generate diff --git a/src/sunstone/etc/sunstone-views/admin.yaml b/src/sunstone/etc/sunstone-views/admin.yaml index 56d3137ea8..06f258bc0c 100644 --- a/src/sunstone/etc/sunstone-views/admin.yaml +++ b/src/sunstone/etc/sunstone-views/admin.yaml @@ -192,6 +192,7 @@ tabs: - 2 # Owner - 3 # Group - 4 # Name + #- 5 # Labels actions: ServiceTemplate.refresh: true ServiceTemplate.create_dialog: true @@ -323,6 +324,7 @@ tabs: - 3 # Group - 4 # Name - 5 # State + #- 6 # Labels actions: Service.refresh: true Service.chown: true diff --git a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml index be109db7a1..e5bdb1a1d0 100644 --- a/src/sunstone/etc/sunstone-views/admin_vcenter.yaml +++ b/src/sunstone/etc/sunstone-views/admin_vcenter.yaml @@ -192,6 +192,7 @@ tabs: - 2 # Owner - 3 # Group - 4 # Name + #- 5 # Labels actions: ServiceTemplate.refresh: true ServiceTemplate.create_dialog: true @@ -323,6 +324,7 @@ tabs: - 3 # Group - 4 # Name - 5 # State + #- 6 # Labels actions: Service.refresh: true Service.chown: true diff --git a/src/sunstone/etc/sunstone-views/groupadmin.yaml b/src/sunstone/etc/sunstone-views/groupadmin.yaml index a9f0842525..2b54e3ad26 100644 --- a/src/sunstone/etc/sunstone-views/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/groupadmin.yaml @@ -191,6 +191,7 @@ tabs: - 2 # Owner - 3 # Group - 4 # Name + #- 5 # Labels actions: ServiceTemplate.refresh: true ServiceTemplate.create_dialog: false @@ -322,6 +323,7 @@ tabs: #- 3 # Group - 4 # Name - 5 # State + #- 6 # Labels actions: Service.refresh: true Service.chown: true diff --git a/src/sunstone/etc/sunstone-views/groupadmin_vcenter.yaml b/src/sunstone/etc/sunstone-views/groupadmin_vcenter.yaml index 3fa9259f50..98989b15aa 100644 --- a/src/sunstone/etc/sunstone-views/groupadmin_vcenter.yaml +++ b/src/sunstone/etc/sunstone-views/groupadmin_vcenter.yaml @@ -193,6 +193,7 @@ tabs: - 2 # Owner - 3 # Group - 4 # Name + #- 5 # Labels actions: ServiceTemplate.refresh: true ServiceTemplate.create_dialog: false @@ -324,6 +325,7 @@ tabs: #- 3 # Group - 4 # Name - 5 # State + #- 6 # Labels actions: Service.refresh: true Service.chown: true diff --git a/src/sunstone/etc/sunstone-views/user.yaml b/src/sunstone/etc/sunstone-views/user.yaml index 9436ff7597..69c6cc25d0 100644 --- a/src/sunstone/etc/sunstone-views/user.yaml +++ b/src/sunstone/etc/sunstone-views/user.yaml @@ -195,6 +195,7 @@ tabs: - 2 # Owner - 3 # Group - 4 # Name + #- 5 # Labels actions: ServiceTemplate.refresh: true ServiceTemplate.create_dialog: true @@ -326,6 +327,7 @@ tabs: - 3 # Group - 4 # Name - 5 # State + #- 6 # Labels actions: Service.refresh: true Service.chown: false diff --git a/src/sunstone/public/app/opennebula/service.js b/src/sunstone/public/app/opennebula/service.js index 86cd0955b1..52665e99fd 100644 --- a/src/sunstone/public/app/opennebula/service.js +++ b/src/sunstone/public/app/opennebula/service.js @@ -89,6 +89,23 @@ define(function(require) { var action_obj = params.data.extra_param; OpenNebulaAction.simple_action(params, RESOURCE, "rename", action_obj, PATH); }, + "append": function(params) { + params.cache_name = CACHE_NAME; + + var action_obj = {}; + + try { + JSON.parse(params.data.extra_param); + action_obj["template_json"] = params.data.extra_param; + } + catch(err) { + action_obj["template_raw"] = params.data.extra_param; + } + + action_obj["append"] = true; + + OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj, PATH); + }, "stateStr" : function(stateId) { return STATES_STR[stateId]; }, diff --git a/src/sunstone/public/app/opennebula/servicetemplate.js b/src/sunstone/public/app/opennebula/servicetemplate.js index cd679d78fc..b2a6a31be8 100644 --- a/src/sunstone/public/app/opennebula/servicetemplate.js +++ b/src/sunstone/public/app/opennebula/servicetemplate.js @@ -35,7 +35,39 @@ define(function(require) { }, "update": function(params) { params.cache_name = CACHE_NAME; - var action_obj = {"template_json" : params.data.extra_param}; + + var action_obj = {}; + + try { + JSON.parse(params.data.extra_param); + action_obj["template_json"] = params.data.extra_param; + } + catch(err) { + action_obj["template_raw"] = params.data.extra_param; + } + + OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj, PATH); + }, + "append": function(params) { + params.cache_name = CACHE_NAME; + + var action_obj = {}; + + try { + JSON.parse(params.data.extra_param); + action_obj["template_json"] = params.data.extra_param; + } + catch(err) { + action_obj["template_raw"] = params.data.extra_param; + } + + action_obj["append"] = true; + + OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj, PATH); + }, + "update_labels": function(params) { + params.cache_name = CACHE_NAME; + var action_obj = {"template_raw" : params.data.extra_param, append : true}; OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj, PATH); }, "del": function(params) { diff --git a/src/sunstone/public/app/tabs/oneflow-services-tab/datatable.js b/src/sunstone/public/app/tabs/oneflow-services-tab/datatable.js index 0949c36615..4a02e3ed93 100644 --- a/src/sunstone/public/app/tabs/oneflow-services-tab/datatable.js +++ b/src/sunstone/public/app/tabs/oneflow-services-tab/datatable.js @@ -23,6 +23,7 @@ define(function(require) { var SunstoneConfig = require('sunstone-config'); var Locale = require('utils/locale'); var OpenNebulaService = require('opennebula/service'); + var LabelsUtils = require('utils/labels/utils'); /* CONSTANTS @@ -31,6 +32,8 @@ define(function(require) { var RESOURCE = "Service"; var XML_ROOT = "DOCUMENT"; var TAB_NAME = require('./tabId'); + var LABELS_COLUMN = 6; + var TEMPLATE_ATTR = 'TEMPLATE'; /* CONSTRUCTOR @@ -42,6 +45,7 @@ define(function(require) { this.dataTableId = dataTableId; this.resource = RESOURCE; this.xmlRoot = XML_ROOT; + this.labelsColumn = LABELS_COLUMN; this.dataTableOptions = { "bAutoWidth": false, @@ -60,7 +64,8 @@ define(function(require) { Locale.tr("Owner") , Locale.tr("Group"), Locale.tr("Name"), - Locale.tr("State") + Locale.tr("State"), + Locale.tr("Labels") ]; this.selectOptions = { @@ -96,7 +101,8 @@ define(function(require) { element.UNAME, element.GNAME, element.NAME, - OpenNebulaService.stateStr(element.TEMPLATE.BODY.state) + OpenNebulaService.stateStr(element.TEMPLATE.BODY.state), + (LabelsUtils.labelsStr(element[TEMPLATE_ATTR])||'') ]; } }); diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/datatable.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/datatable.js index 38d6f1b242..c6960aa213 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/datatable.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/datatable.js @@ -22,6 +22,7 @@ define(function(require) { var TabDataTable = require('utils/tab-datatable'); var SunstoneConfig = require('sunstone-config'); var Locale = require('utils/locale'); + var LabelsUtils = require('utils/labels/utils'); /* CONSTANTS @@ -30,6 +31,8 @@ define(function(require) { var RESOURCE = "ServiceTemplate"; var XML_ROOT = "DOCUMENT"; var TAB_NAME = require('./tabId'); + var LABELS_COLUMN = 5; + var TEMPLATE_ATTR = 'TEMPLATE'; /* CONSTRUCTOR @@ -41,6 +44,7 @@ define(function(require) { this.dataTableId = dataTableId; this.resource = RESOURCE; this.xmlRoot = XML_ROOT; + this.labelsColumn = LABELS_COLUMN; this.dataTableOptions = { "bAutoWidth": false, @@ -58,7 +62,8 @@ define(function(require) { Locale.tr("ID") , Locale.tr("Owner") , Locale.tr("Group"), - Locale.tr("Name") + Locale.tr("Name"), + Locale.tr("Labels") ]; this.selectOptions = { @@ -93,7 +98,8 @@ define(function(require) { element.ID, element.UNAME, element.GNAME, - element.NAME + element.NAME, + (LabelsUtils.labelsStr(element[TEMPLATE_ATTR])||'') ]; } }); diff --git a/src/sunstone/public/app/tabs/templates-tab/datatable.js b/src/sunstone/public/app/tabs/templates-tab/datatable.js index cb3653c907..3253183cbc 100644 --- a/src/sunstone/public/app/tabs/templates-tab/datatable.js +++ b/src/sunstone/public/app/tabs/templates-tab/datatable.js @@ -25,7 +25,6 @@ define(function(require) { var OpenNebula = require('opennebula'); var Locale = require('utils/locale'); var Humanize = require('utils/humanize'); - var Tree = require('utils/labels/tree'); var Notifier = require('utils/notifier'); var LabelsUtils = require('utils/labels/utils');