module Splash::Sequences

Splash Commands module/namespace

Public Instance Methods

list_seq(options = {}) click to toggle source
# File lib/splash/sequences.rb, line 80
def list_seq(options = {})
  list = get_config.sequences
  unless list.empty?
    acase = { :case =>  :quiet_exit , :more => "List configured sequences"}
    acase[:data] = list
    return acase
  else
    return { :case => :not_found, :more => 'No sequences configured' }
  end
end
run_seq(params = {}) click to toggle source
# File lib/splash/sequences.rb, line 15
def run_seq(params = {})
  list = get_config.sequences
  name = params[:name].to_sym
  acase = {}
  seq_res = []
  log = get_logger
  log.info "beginnning Sequence execution : #{name}"
  session = (params[:session])? params[:session] : get_session
  if list.include? name then
    seq_options = (list[name][:options].nil?)? {} : list[name][:options]
    list[name][:definition].each do |step|
      log.info "STEP : #{step[:step]}",session
      if step[:on_host].nil? then
        if get_config.commands.select{|cmd| cmd[:name] == step[:command]}.count > 0 then
          command =  CommandWrapper::new(step[:command].to_s)
          step[:callback] = true if step[:callback].nil?
          step[:trace] = true if step[:trace].nil?
          step[:notify] = true if step[:notify].nil?
          step[:session] = session
          acase = command.call_and_notify step
        else
          log.error "Commmand #{step[:command]} not found, for STEP : #{step[:step]}", session
          acase =  splash_return :not_found
        end
      else
        log.info "Remote execution of #{step[:command]} on #{step[:on_host]}", session
        begin
          transport = get_default_client
          if transport.class == Hash  and transport.include? :case then
            return transport
          else
            acase = transport.execute({ :verb => :execute_command,
                                      payload: {:name => step[:command].to_s},
                                     :return_to => "splash.#{Socket.gethostname}.return",
                                     :queue => "splash.#{step[:on_host]}.input" })
            log.receive "return with exitcode #{acase[:exit_code]}", session
          end
        rescue Interrupt
          acase = { case: :interrupt, more: "Remote command exection", exit_code: 33}
        end

       end
       seq_res.push acase[:exit_code]
       continue = (seq_options[:continue].nil?)? true : seq_options[:continue]
       if acase[:exit_code] > 0 and continue == false then
         acase[:more] = "Break execution on error, continue = false"
         break
       end
    end
  else
    return  { :case => :not_found, :more => "Sequence #{name} not configured" }
  end

  if seq_res.select {|res| res > 0}.count == seq_res.count then
    acase =  { case: :status_ko, more: "all execution failed" }
  elsif seq_res.select {|res| res > 0}.count > 0 then
    acase =  { case: :status_ko, more: "some execution failed" }
  else
    acase =  { case: :status_ok, more: "all execution successed" }
  end
  acase[:more] << " with remote call interrupt" if seq_res.include?(33)
  return acase
end
schedule_seq(options = {}) click to toggle source
# File lib/splash/sequences.rb, line 103
def schedule_seq(options = {})
  acase = { :case => :quiet_exit,  :more => "schedule" }
  return acase

end
show_seq(options = {}) click to toggle source
# File lib/splash/sequences.rb, line 91
def show_seq(options = {})
  list = get_config.sequences
  name = options[:name].to_sym
  if list.include? name then
    acase = { :case => :quiet_exit, :more => "Show specific sequence : #{name}"}
    acase[:data] = list[name]
  else
    return { :case => :not_found, :more => "Sequence #{name} not configured" }
  end
  return acase
end