Class: Arver::SSHCommandWrapper

Inherits:
CommandWrapper show all
Defined in:
lib/arver/ssh_command_wrapper.rb

Instance Attribute Summary collapse

Attributes inherited from CommandWrapper

#arguments_array, #command, #output, #return_value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandWrapper

#execute, #run, shellescape, #shellescape, #success?

Instance Attribute Details

#as_rootObject

Returns the value of attribute as_root.



3
4
5
# File 'lib/arver/ssh_command_wrapper.rb', line 3

def as_root
  @as_root
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/arver/ssh_command_wrapper.rb', line 3

def host
  @host
end

#on_bootObject

Returns the value of attribute on_boot.



3
4
5
# File 'lib/arver/ssh_command_wrapper.rb', line 3

def on_boot
  @on_boot
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/arver/ssh_command_wrapper.rb', line 3

def port
  @port
end

#userObject

Returns the value of attribute user.



3
4
5
# File 'lib/arver/ssh_command_wrapper.rb', line 3

def user
  @user
end

Class Method Details

.create(cmd, args, host, as_root = false, on_boot = false) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/arver/ssh_command_wrapper.rb', line 5

def self.create( cmd, args, host, as_root = false, on_boot = false)
  c = SSHCommandWrapper.new
  c.host= host
  c.as_root= as_root
  c.command= cmd
  c.arguments_array= args
  c.on_boot = on_boot
  c
end

.is_system_running?(partition) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/arver/ssh_command_wrapper.rb', line 23

def self.is_system_running?(partition)
  wr = Arver::SSHCommandWrapper.create("systemctl", ["is-system-running"], partition.parent, true, true)
  wr.execute
  wr.success? && !['initializing','starting'].include?(wr.output.chomp)
end

Instance Method Details

#escaped_commandObject



15
16
17
18
19
20
21
# File 'lib/arver/ssh_command_wrapper.rb', line 15

def escaped_command
  addr = (on_boot ? host.boot_address : nil) || host.address
  user = on_boot ? 'root' : host.username
  port = on_boot ? '22' : host.port
  sudo = if as_root && on_boot && host.username != "root" then "sudo" else "" end
  "ssh -p #{shellescape(port)} #{shellescape(user)}@#{shellescape(addr)} #{sudo} #{super}" 
end