Class: QEMU::Command

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

Defined Under Namespace

Classes: Disk, Disks

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alsa_adc_devObject

Returns the value of attribute alsa_adc_dev.



73
74
75
# File 'lib/qemu/command.rb', line 73

def alsa_adc_dev
  @alsa_adc_dev
end

#alsa_dac_devObject

Returns the value of attribute alsa_dac_dev.



73
74
75
# File 'lib/qemu/command.rb', line 73

def alsa_dac_dev
  @alsa_dac_dev
end

#audio_driverObject

Returns the value of attribute audio_driver.



68
69
70
# File 'lib/qemu/command.rb', line 68

def audio_driver
  @audio_driver
end

#disksObject (readonly)

Returns the value of attribute disks.



12
13
14
# File 'lib/qemu/command.rb', line 12

def disks
  @disks
end

#mac_addressObject

Returns the value of attribute mac_address.



46
47
48
# File 'lib/qemu/command.rb', line 46

def mac_address
  @mac_address
end

#memoryObject

Returns the value of attribute memory.



10
11
12
# File 'lib/qemu/command.rb', line 10

def memory
  @memory
end

#monitorObject

Returns the value of attribute monitor.



55
56
57
# File 'lib/qemu/command.rb', line 55

def monitor
  @monitor
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/qemu/command.rb', line 4

def name
  @name
end

#sound_hardwareObject

Returns the value of attribute sound_hardware.



67
68
69
# File 'lib/qemu/command.rb', line 67

def sound_hardware
  @sound_hardware
end

#telnet_portObject

Returns the value of attribute telnet_port.



56
57
58
# File 'lib/qemu/command.rb', line 56

def telnet_port
  @telnet_port
end

#vde_optionsObject

Returns the value of attribute vde_options.



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

def vde_options
  @vde_options
end

#vncObject

Returns the value of attribute vnc.



53
54
55
# File 'lib/qemu/command.rb', line 53

def vnc
  @vnc
end

Instance Method Details

#commandObject



103
104
105
# File 'lib/qemu/command.rb', line 103

def command
  "/usr/bin/kvm"
end

#command_argumentsObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/qemu/command.rb', line 75

def command_arguments
  [].tap do |args|
    args << "-m" << "#{memory}m" if memory
    disks.each_with_index do |disk, index|
      args << "-drive" << disk.qemu_drive(index)
    end
    args << "-net" << "nic,macaddr=#{mac_address}"
    unless vde_options.empty?
      args << "-net" << "vde," + vde_options.map { |k,v| "#{k}=#{v}" }.join(',')
    end
    if vnc
      args << "-vnc" << vnc
    else
      args << "-nographic"
    end
    args << "-monitor" << monitor if monitor
    args << "-soundhw" << sound_hardware if sound_hardware
  end
end

#command_envObject



95
96
97
98
99
100
101
# File 'lib/qemu/command.rb', line 95

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

#daemonObject



112
113
114
# File 'lib/qemu/command.rb', line 112

def daemon
  @daemon ||= Daemon.new :command => command, :name => name, :arguments => command_arguments, :env => command_env
end

#qemu_monitorObject



63
64
65
# File 'lib/qemu/command.rb', line 63

def qemu_monitor
  @qemu_monitor ||= QEMU::Monitor.new :port => telnet_port if telnet_port
end

#runObject



107
108
109
110
# File 'lib/qemu/command.rb', line 107

def run
  shell_env = command_env.map { |k,v| "#{k}=#{v}" }.join(' ')
  system "#{shell_env} #{command} #{command_arguments.join(' ')}"
end