Class: QEMU::Command
- Inherits:
-
Object
- Object
- QEMU::Command
- Defined in:
- lib/qemu/command.rb
Defined Under Namespace
Constant Summary collapse
- @@command_system_aliases =
{ "amd64" => "x86_64" }
Instance Attribute Summary collapse
-
#alsa_adc_dev ⇒ Object
Returns the value of attribute alsa_adc_dev.
-
#alsa_dac_dev ⇒ Object
Returns the value of attribute alsa_dac_dev.
-
#architecture ⇒ Object
Returns the value of attribute architecture.
-
#audio_driver ⇒ Object
Returns the value of attribute audio_driver.
-
#disks ⇒ Object
readonly
Returns the value of attribute disks.
-
#mac_address ⇒ Object
Returns the value of attribute mac_address.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#monitor ⇒ Object
Returns the value of attribute monitor.
-
#name ⇒ Object
Returns the value of attribute name.
-
#sound_hardware ⇒ Object
Returns the value of attribute sound_hardware.
-
#telnet_port ⇒ Object
Returns the value of attribute telnet_port.
-
#usb ⇒ Object
Returns the value of attribute usb.
-
#vde_options ⇒ Object
Returns the value of attribute vde_options.
-
#vnc ⇒ Object
Returns the value of attribute vnc.
Instance Method Summary collapse
- #command ⇒ Object
- #command_arguments ⇒ Object
- #command_env ⇒ Object
- #daemon ⇒ Object
- #qemu_monitor ⇒ Object
- #run ⇒ Object
Instance Attribute Details
#alsa_adc_dev ⇒ Object
Returns the value of attribute alsa_adc_dev.
79 80 81 |
# File 'lib/qemu/command.rb', line 79 def alsa_adc_dev @alsa_adc_dev end |
#alsa_dac_dev ⇒ Object
Returns the value of attribute alsa_dac_dev.
79 80 81 |
# File 'lib/qemu/command.rb', line 79 def alsa_dac_dev @alsa_dac_dev end |
#architecture ⇒ Object
Returns the value of attribute architecture.
12 13 14 |
# File 'lib/qemu/command.rb', line 12 def architecture @architecture end |
#audio_driver ⇒ Object
Returns the value of attribute audio_driver.
74 75 76 |
# File 'lib/qemu/command.rb', line 74 def audio_driver @audio_driver end |
#disks ⇒ Object (readonly)
Returns the value of attribute disks.
18 19 20 |
# File 'lib/qemu/command.rb', line 18 def disks @disks end |
#mac_address ⇒ Object
Returns the value of attribute mac_address.
52 53 54 |
# File 'lib/qemu/command.rb', line 52 def mac_address @mac_address end |
#memory ⇒ Object
Returns the value of attribute memory.
10 11 12 |
# File 'lib/qemu/command.rb', line 10 def memory @memory end |
#monitor ⇒ Object
Returns the value of attribute monitor.
61 62 63 |
# File 'lib/qemu/command.rb', line 61 def monitor @monitor end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/qemu/command.rb', line 4 def name @name end |
#sound_hardware ⇒ Object
Returns the value of attribute sound_hardware.
73 74 75 |
# File 'lib/qemu/command.rb', line 73 def sound_hardware @sound_hardware end |
#telnet_port ⇒ Object
Returns the value of attribute telnet_port.
62 63 64 |
# File 'lib/qemu/command.rb', line 62 def telnet_port @telnet_port end |
#usb ⇒ Object
Returns the value of attribute usb.
81 82 83 |
# File 'lib/qemu/command.rb', line 81 def usb @usb end |
#vde_options ⇒ Object
Returns the value of attribute vde_options.
54 55 56 |
# File 'lib/qemu/command.rb', line 54 def end |
#vnc ⇒ Object
Returns the value of attribute vnc.
59 60 61 |
# File 'lib/qemu/command.rb', line 59 def vnc @vnc end |
Instance Method Details
#command ⇒ Object
120 121 122 123 |
# File 'lib/qemu/command.rb', line 120 def command system = @@command_system_aliases.fetch(architecture.to_s, architecture.to_s) "/usr/bin/qemu-system-#{system}" end |
#command_arguments ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/qemu/command.rb', line 83 def command_arguments [].tap do |args| args << "-enable-kvm" args << "-m" << memory.to_s if memory disks.each_with_index do |disk, index| args << "-drive" << disk.qemu_drive(index) end args << "-net" << "nic,macaddr=#{mac_address}" unless .empty? args << "-net" << "vde," + .map { |k,v| "#{k}=#{v}" }.join(',') end if vnc args << "-vnc" << vnc else args << "-nographic" end args << "-usb" if usb args << "-monitor" << monitor if monitor args << "-soundhw" << sound_hardware if sound_hardware end end |
#command_env ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/qemu/command.rb', line 108 def command_env {}.tap do |env| env["QEMU_AUDIO_DRV"] = audio_driver env["QEMU_ALSA_DAC_DEV"] = alsa_dac_dev if alsa_dac_dev env["QEMU_ALSA_ADC_DEV"] = alsa_adc_dev if alsa_adc_dev end end |
#daemon ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/qemu/command.rb', line 130 def daemon @daemon ||= begin QEMU.logger.debug "Prepare daemon with '#{command_arguments.join(' ')}'" Daemon.new :command => command, :name => name, :arguments => command_arguments, :env => command_env end end |
#qemu_monitor ⇒ Object
69 70 71 |
# File 'lib/qemu/command.rb', line 69 def qemu_monitor @qemu_monitor ||= QEMU::Monitor.new :port => telnet_port if telnet_port end |
#run ⇒ Object
125 126 127 128 |
# File 'lib/qemu/command.rb', line 125 def run shell_env = command_env.map { |k,v| "#{k}=#{v}" }.join(' ') system "#{shell_env} #{command} #{command_arguments.join(' ')}" end |