Class: VirtualMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_execution/virtual_machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip_address, username, *args) ⇒ VirtualMachine

Returns a new instance of VirtualMachine.



13
14
15
16
17
18
19
# File 'lib/remote_execution/virtual_machine.rb', line 13

def initialize(ip_address, username, *args)
  @ip_address = ip_address
  @username = username
  args[0].store(:timeout, 5)
  @args = args
  @active = false
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



11
12
13
# File 'lib/remote_execution/virtual_machine.rb', line 11

def active
  @active
end

#argsObject

Returns the value of attribute args.



11
12
13
# File 'lib/remote_execution/virtual_machine.rb', line 11

def args
  @args
end

#ip_addressObject

Returns the value of attribute ip_address.



11
12
13
# File 'lib/remote_execution/virtual_machine.rb', line 11

def ip_address
  @ip_address
end

#log_fileObject

Returns the value of attribute log_file.



11
12
13
# File 'lib/remote_execution/virtual_machine.rb', line 11

def log_file
  @log_file
end

#usernameObject

Returns the value of attribute username.



11
12
13
# File 'lib/remote_execution/virtual_machine.rb', line 11

def username
  @username
end

Instance Method Details

#invoke(commands) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/remote_execution/virtual_machine.rb', line 33

def invoke(commands)
  Net::SSH.start(ip_address, username, *args) do |ssh|
    commands.each do |command|
      print command , "\n"
      s_ssh ssh, command
    end
  end
end

#ssh_test(session, command) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/remote_execution/virtual_machine.rb', line 25

def ssh_test(session,command)
  res = session.exec!(command)
  puts res
  if res!='' and res!="attributes.json\n"
    @active = true
  end
end

#to_sObject



21
22
23
# File 'lib/remote_execution/virtual_machine.rb', line 21

def to_s
  "[IP: #{ip_address}, user: #{username}]"
end