Class: QEMU::Monitor
- Inherits:
-
Object
- Object
- QEMU::Monitor
- Defined in:
- lib/qemu/monitor.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #command(command) ⇒ Object
- #device_add(driver, options = {}) ⇒ Object
- #device_del(id) ⇒ Object
- #drive_add(name, options = {}) ⇒ Object
- #drive_del(name) ⇒ Object
-
#initialize(attributes = {}) ⇒ Monitor
constructor
A new instance of Monitor.
- #loadvm(name = "default") ⇒ Object
- #reset ⇒ Object
- #savevm(name = "default") ⇒ Object
- #telnet ⇒ Object
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
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/qemu/monitor.rb', line 6 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/qemu/monitor.rb', line 6 def port @port end |
#timeout ⇒ Object
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, = {}) command "device_add #{driver},#{.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, = {}) command "drive_add #{name} #{.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 |
#reset ⇒ Object
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 |
#telnet ⇒ Object
13 14 15 |
# File 'lib/qemu/monitor.rb', line 13 def telnet Net::Telnet::new "Host" => host, "Port" => port, "Timeout" => timeout, "Prompt" => /\(qemu\) / end |