Class: VirtConsole

Inherits:
Object
  • Object
show all
Defined in:
lib/version.rb,
lib/virt_console.rb

Constant Summary collapse

VERSION =
"1.0.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ VirtConsole

Returns a new instance of VirtConsole.



4
5
6
7
# File 'lib/virt_console.rb', line 4

def initialize(hash)
  @path = hash[:path]
  @command = hash[:command]
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/virt_console.rb', line 8

def execute
  sp = SerialPort.open("#{@path}", baud = 9600, data_bits = 8, stop_bits = 1) { |tty|
    tty.sync = true
    line = ""
    Thread.new {
      tty.write @command + "\015"
    }
    until line =~ /^(Execution Completed|Ready|Disk Shrink Completed|Disk Extend Completed)\.$/ do
      line = (tty.readline.chomp!)
      print "#{line}\n"
    end
  print "\n"
  }
end