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

Feature #4261: Add labels support for OneFlow services and templates

This commit is contained in:
Carlos Martín 2016-04-27 17:33:49 +02:00
parent 620ec97ef9
commit 0a2d84148c
15 changed files with 172 additions and 8 deletions

View File

@ -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

View File

@ -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,

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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];
},

View File

@ -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) {

View File

@ -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])||'')
];
}
});

View File

@ -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])||'')
];
}
});

View File

@ -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');