Class: Aspera::Cli::Plugins::Console

Inherits:
BasicAuthPlugin show all
Defined in:
lib/aspera/cli/plugins/console.rb

Constant Summary collapse

ACTIONS =
[:transfer,:nagios_check]

Constants inherited from Aspera::Cli::Plugin

Aspera::Cli::Plugin::ALL_OPS, Aspera::Cli::Plugin::GLOBAL_OPS, Aspera::Cli::Plugin::INSTANCE_OPS

Instance Method Summary collapse

Methods inherited from BasicAuthPlugin

#basic_auth_api

Methods inherited from Aspera::Cli::Plugin

#config, #entity_action, #entity_command, #format, #options, #transfer

Constructor Details

#initialize(env) ⇒ Console

Returns a new instance of Console.



8
9
10
11
12
13
14
15
# File 'lib/aspera/cli/plugins/console.rb', line 8

def initialize(env)
  super(env)
  self.options.add_opt_date(:filter_from,"only after date")
  self.options.add_opt_date(:filter_to,"only before date")
  self.options.set_option(:filter_from,Manager.time_to_string(Time.now - 3*3600))
  self.options.set_option(:filter_to,Manager.time_to_string(Time.now))
  self.options.parse_options!
end

Instance Method Details

#execute_actionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/aspera/cli/plugins/console.rb', line 19

def execute_action
  api_console=basic_auth_api('api')
  command=self.options.get_next_command(ACTIONS)
  case command
  when :nagios_check
    nagios=Nagios.new
    begin
      api_console.read('ssh_keys')
      nagios.add_ok('console api','accessible')
    rescue => e
      nagios.add_critical('console api',e.to_s)
    end
    return nagios.result
  when :transfer
    command=self.options.get_next_command([ :current, :smart ])
    case command
    when :smart
      command=self.options.get_next_command([:list,:submit])
      case command
      when :list
        return {:type=>:object_list,:data=>api_console.read('smart_transfers')[:data]}
      when :submit
        smart_id = self.options.get_next_argument("smart_id")
        params = self.options.get_next_argument("transfer parameters")
        return {:type=>:object_list,:data=>api_console.create('smart_transfers/'+smart_id,params)[:data]}
      end
    when :current
      command=self.options.get_next_command([ :list ])
      case command
      when :list
        return {:type=>:object_list,
          :data=>api_console.read('transfers',{
          'from'=>self.options.get_option(:filter_from,:mandatory),
          'to'=>self.options.get_option(:filter_to,:mandatory)
          })[:data],
          :fields=>['id','contact','name','status']}
      end
    end
  end
end