Class: CommandInterfaceHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/proto/command_interface_handler.rb

Instance Method Summary collapse

Instance Method Details

#run_command(cld, command, args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/proto/command_interface_handler.rb', line 2

def run_command(cld, command, args)
      
  cr = CloudThrift::CloudResponse.new
  cr.name = cld.name
  cr.command = command
  resp = begin
    the_cloud = clouds[cld.name]
    if the_cloud
      if command.include?(".")
        command.split(".").inject(the_cloud) do |curr_cloud, cmd|
          if cmd.match(/\((.*)\)/)
            args = $1
            new_cmd = cmd.gsub(args, '').gsub(/\(\)/, '')
            curr_cloud = curr_cloud.send(new_cmd.to_sym, *args)
          else
            curr_cloud = curr_cloud.send(cmd)
          end
        end
      else
        the_cloud.send(command.to_sym, *args)
      end
    else
      "Cloud not found: #{cld.name}"
    end
  rescue Exception => e
    cr.response = "Error: #{e.inspect}"
  end
  
  cr.response = format_response(resp)

  return cr
end