Class: SeleniumGrid::AWS::RemoteCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium-grid/examples/ec2/lib/selenium_grid/aws/remote_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, options = {}) ⇒ RemoteCommand

Returns a new instance of RemoteCommand.



7
8
9
# File 'lib/selenium-grid/examples/ec2/lib/selenium_grid/aws/remote_command.rb', line 7

def initialize(command, options={})
  @command, @options = command, options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/selenium-grid/examples/ec2/lib/selenium_grid/aws/remote_command.rb', line 5

def options
  @options
end

Instance Method Details

#executeObject



11
12
13
14
15
# File 'lib/selenium-grid/examples/ec2/lib/selenium_grid/aws/remote_command.rb', line 11

def execute
  puts full_command
  system full_command
  raise "Error with #{full_command}" if 0 != $?        
end

#full_commandObject



17
18
19
20
21
22
23
# File 'lib/selenium-grid/examples/ec2/lib/selenium_grid/aws/remote_command.rb', line 17

def full_command
  cmd = "#{ssh_command} " 
  cmd << "\"su -l #{options[:su]} -c " if options[:su]
  cmd << "'#{remote_command}'"
  cmd << '"' if options[:su]
  cmd
end

#remote_commandObject



33
34
35
36
37
38
39
40
41
# File 'lib/selenium-grid/examples/ec2/lib/selenium_grid/aws/remote_command.rb', line 33

def remote_command
  shell_command = []
  shell_command << "PATH=#{options[:path]}:${PATH}; export PATH;" if options[:path]
  shell_command << "DISPLAY=#{options[:display]}; export DISPLAY;" if options[:display]
  shell_command << "cd '#{options[:pwd]}';" if options[:pwd]
  shell_command << @command
  
  shell_command.join " "
end

#ssh_commandObject



25
26
27
28
29
30
31
# File 'lib/selenium-grid/examples/ec2/lib/selenium_grid/aws/remote_command.rb', line 25

def ssh_command
  shell_command = [ "ssh" ]
  shell_command << "-i '#{options[:keypair]}'" if options[:keypair]
  shell_command << "root@#{options[:host]}"
  
  shell_command.join " "
end