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.



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

def alsa_adc_dev
  @alsa_adc_dev
end

#alsa_dac_devObject

Returns the value of attribute alsa_dac_dev.



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

def alsa_dac_dev
  @alsa_dac_dev
end

#audio_driverObject

Returns the value of attribute audio_driver.



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

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.



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

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.



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

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.



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

def sound_hardware
  @sound_hardware
end

#telnet_portObject

Returns the value of attribute telnet_port.



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

def telnet_port
  @telnet_port
end

#vde_optionsObject

Returns the value of attribute vde_options.



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

def vde_options
  @vde_options
end

#vncObject

Returns the value of attribute vnc.



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

def vnc
  @vnc
end

Instance Method Details

#commandObject



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

def command
  "/usr/bin/kvm"
end

#command_argumentsObject



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

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



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

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



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

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

#qemu_monitorObject



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

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

#runObject



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

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