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

F #4532: add sched actions at service level (#4534)

Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Alejandro Huertas Herrero 2020-04-15 18:23:36 +02:00 committed by GitHub
parent e573c83c7a
commit 8902e7d5ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 8 deletions

View File

@ -309,7 +309,7 @@ CommandParser::CmdParser.new(ARGV) do
params = {}
params[:period] = options[:period].to_i if options[:period]
params[:number] = options[:number].to_i if options[:number]
params[:args] = options[:args]
params[:args] = options[:args] if options[:args]
json = Service.build_json_action(args[2], params)
client = helper.client(options)
@ -318,4 +318,29 @@ CommandParser::CmdParser.new(ARGV) do
json)
end
end
###
action_desc = <<-EOT.unindent
Perform an action on all the Virtual Machines of a given service.
Actions supported: #{Role::SCHEDULE_ACTIONS.join(',')}
EOT
command [:service, :action],
action_desc,
:service_id,
:vm_action,
:options => [Service::PERIOD, Service::NUMBER, ARGS] do
Service.perform_action(args[0]) do |service_id|
params = {}
params[:period] = options[:period].to_i if options[:period]
params[:number] = options[:number].to_i if options[:number]
params[:args] = options[:args] if options[:args]
json = Service.build_json_action(args[1], params)
client = helper.client(options)
client.post("#{RESOURCE_PATH}/#{service_id}/action", json)
end
end
end

View File

@ -151,6 +151,30 @@ class ServiceLCM
rc
end
# Add shced action to service
#
# @param client [OpenNebula::Client] Client executing action
# @param service_id [Integer] Service ID
# @param action [String] Action to perform
# @param period [Integer] When to execute the action
# @param number [Integer] How many VMs per period
# @param args [String] Action arguments
#
# @return [OpenNebula::Error] Error if any
# rubocop:disable Metrics/ParameterLists
def service_sched_action(client, service_id, action, period, number, args)
# rubocop:enable Metrics/ParameterLists
rc = @srv_pool.get(service_id, client) do |service|
service.roles.each do |_, role|
role.batch_action(action, period, number, args)
end
end
Log.error LOG_COMP, rc.message if OpenNebula.is_error?(rc)
rc
end
# Add shced action to service role
#
# @param client [OpenNebula::Client] Client executing action

View File

@ -297,7 +297,22 @@ post '/service/:id/action' do
# 'Only supported for append')
# end
else
rc = OpenNebula::Error.new("Action #{action['perform']} not supported")
if Role::SCHEDULE_ACTIONS.include?(action['perform'])
# Use defaults only if one of the options is supplied
opts['period'] ||= conf[:action_period]
opts['number'] ||= conf[:action_number]
rc = lcm.service_sched_action(@client,
params[:id],
action['perform'],
opts['period'],
opts['number'],
opts['args'])
else
rc = OpenNebula::Error.new(
"Action #{action['perform']} not supported"
)
end
end
if OpenNebula.is_error?(rc)

View File

@ -345,9 +345,12 @@ define(function(require) {
var roleName = params && params.data && params.data.roleName
var action = params && params.data && params.data.action
var cacheName = params.cacheName ? params.cacheName : resource;
if(id!==undefined && roleName && action && resource){
if(id!==undefined && action && resource){
$.ajax({
url: resource.toLowerCase()+"/"+id+"/role/"+roleName+"/action",
url: roleName?
resource.toLowerCase()+"/"+id+"/role/"+roleName+"/action"
:
resource.toLowerCase()+"/"+id+"/action",
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({action: action}),

View File

@ -23,6 +23,7 @@ the License for the specific language governing permissions and }} {{! limitatio
<div style="display:flex;">
<select id="role_name" class="select_role" name="select_action" style="width: 100%">{{{roles}}}</select>
<input type="number" id="period" placeholder="{{tr 'Period'}}" style="width: 100%">
<input type="number" id="number" placeholder="{{tr 'Number'}}" style="width: 100%">
</div>
<div style="display:flex;">
<input type="number" class="hide" id="diskid" placeholder="{{tr 'Disk Id'}}" style="width: 100%">

View File

@ -92,8 +92,9 @@ define(function(require) {
return role && role.name;
}).map(function(role){
return "<option value='"+role.name+"'>"+role.name+"</option>";
}).join("");
});
optionsRoles.unshift("<option value=''>"+Locale.tr("All Roles")+"</option>");
optionsRoles = optionsRoles.join("");
return TemplateHTML({
actions: optionsActions,
res: RESOURCE,
@ -155,7 +156,7 @@ define(function(require) {
var snap_id = $("#snapid").val();
var disk_id = $("#diskid").val();
if(new_action && role){
if(new_action){
var actionJSON = {};
actionJSON.error = function(e){
Notifier.notifyError((e && e.error && e.error.message) || Locale.tr("Error"));
@ -165,7 +166,6 @@ define(function(require) {
};
actionJSON.data = {};
actionJSON.data.id = that.id;
actionJSON.data.roleName = role;
actionJSON.data.action = {perform: new_action};
actionJSON.data.action.params = {};
if(period!=='' && period!==undefined){
@ -181,6 +181,9 @@ define(function(require) {
actionJSON.data.action.params.args = args;
}
}
if(role!=='' && role!==undefined){
actionJSON.data.roleName = role;
}
Actions.addFlowAction(actionJSON,RESOURCE);
}
return false;