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
23
24
25
26
# File 'lib/qemu/monitor.rb', line 17

def command(command)
  telnet.tap do |telnet|
    QEMU.logger.debug "Send monitor command '#{command}'"

    response = telnet.cmd(command)
    QEMU.logger.debug "Receive '#{response}'"

    telnet.close
  end
end

#device_add(driver, options = {}) ⇒ Object



40
41
42
# File 'lib/qemu/monitor.rb', line 40

def device_add(driver, options = {})
  command "device_add #{driver},#{options.to_command}"
end

#device_del(id) ⇒ Object



44
45
46
# File 'lib/qemu/monitor.rb', line 44

def device_del(id)
  command "device_del #{id}"
end

#drive_add(name, options = {}) ⇒ Object



48
49
50
# File 'lib/qemu/monitor.rb', line 48

def drive_add(name, options = {})
  command "drive_add #{name} #{options.to_command}"
end

#drive_del(name) ⇒ Object



52
53
54
# File 'lib/qemu/monitor.rb', line 52

def drive_del(name)
  command "drive_del #{name}"
end

#loadvm(name = "default") ⇒ Object



36
37
38
# File 'lib/qemu/monitor.rb', line 36

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

#resetObject



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

def reset
  command "system_reset"
end

#savevm(name = "default") ⇒ Object



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

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