Class: Bcome::Ssh::ScriptExec

Inherits:
Object
  • Object
show all
Defined in:
lib/objects/ssh/script_exec.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, path_to_script) ⇒ ScriptExec

Returns a new instance of ScriptExec.



12
13
14
15
16
17
# File 'lib/objects/ssh/script_exec.rb', line 12

def initialize(server, path_to_script)
  @server = server
  @path_to_script = path_to_script
  @ssh_driver = server.ssh_driver
  @output_string = ''
end

Class Method Details

.execute(server, path_to_script) ⇒ Object



6
7
8
9
# File 'lib/objects/ssh/script_exec.rb', line 6

def execute(server, path_to_script)
  executor = new(server, path_to_script)
  executor.execute
end

Instance Method Details

#executeObject



19
20
21
22
23
# File 'lib/objects/ssh/script_exec.rb', line 19

def execute
  command = execute_command
  pretty_print(command)
  command
end

#execute_commandObject



25
26
27
28
29
30
31
# File 'lib/objects/ssh/script_exec.rb', line 25

def execute_command
  raise Bcome::Exception::OrchestrationScriptDoesNotExist, @path_to_script unless File.exist?(@path_to_script)

  execute_script_command = "#{@ssh_driver.ssh_command} \"bash -s\" < #{@path_to_script}"
  command = ::Bcome::Command::Local.run(execute_script_command)
  command
end

#output_append(output_string) ⇒ Object



40
41
42
# File 'lib/objects/ssh/script_exec.rb', line 40

def output_append(output_string)
  @output_string += "#{@output_string}#{output_string}"
end

#pretty_print(command) ⇒ Object



33
34
35
36
37
38
# File 'lib/objects/ssh/script_exec.rb', line 33

def pretty_print(command)
  output_append("\n(#{@server.namespace})$".terminal_prompt + "> ./#{@path_to_script} - \s#{command.pretty_result}\n")
  output_append(command.stdout) # append stderr
  output_append "\nSTDERR: #{command.stderr}" if command.failed?
  puts "\n\n#{@output_string}\n\n"
end