Class: QEMU::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/qemu/monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Monitor

Returns a new instance of Monitor.



8
9
10
11
# File 'lib/qemu/monitor.rb', line 8

def initialize(attributes = {})
  attributes = { :host => "localhost", :timeout => 30 }.merge(attributes)
  attributes.each { |k,v| send "#{k}=", v }
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/qemu/monitor.rb', line 6

def host
  @host
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/qemu/monitor.rb', line 6

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



6
7
8
# File 'lib/qemu/monitor.rb', line 6

def timeout
  @timeout
end

Instance Method Details

#command(command) ⇒ Object



17
18
19
20
21
22
# File 'lib/qemu/monitor.rb', line 17

def command(command)
  telnet.tap do |telnet|
    telnet.cmd command
    telnet.close
  end
end

#loadvm(name = "default") ⇒ Object



32
33
34
# File 'lib/qemu/monitor.rb', line 32

def loadvm(name = "default")
  command "loadvm #{name}"
end

#resetObject



24
25
26
# File 'lib/qemu/monitor.rb', line 24

def reset
  command "system_reset"
end

#savevm(name = "default") ⇒ Object



28
29
30
# File 'lib/qemu/monitor.rb', line 28

def savevm(name = "default")
  command "savevm #{name}"
end

#telnetObject



13
14
15
# File 'lib/qemu/monitor.rb', line 13

def telnet
  Net::Telnet::new "Host" => host, "Port" => port, "Timeout" => timeout, "Prompt" => /\(qemu\) /
end