|
Lines 15-23
Link Here
|
| 15 |
self.readfp(file, filename) |
15 |
self.readfp(file, filename) |
| 16 |
|
16 |
|
| 17 |
config = ShellConfigParser() |
17 |
config = ShellConfigParser() |
| 18 |
config.read('config.mak') |
18 |
config.read('/etc/kvm/config.mak') |
| 19 |
|
19 |
|
| 20 |
external_module = config.get('shell', 'want_module') |
20 |
external_module = config.get('shell', 'want_module') |
|
|
21 |
prefix = config.get('shell', 'prefix') |
| 22 |
kerneldir = config.get('shell', 'kerneldir').replace('build', 'misc') |
| 21 |
privileged = os.getuid() == 0 |
23 |
privileged = os.getuid() == 0 |
| 22 |
|
24 |
|
| 23 |
optparser = optparse.OptionParser() |
25 |
optparser = optparse.OptionParser() |
|
Lines 55-60
Link Here
|
| 55 |
default = not privileged, |
57 |
default = not privileged, |
| 56 |
) |
58 |
) |
| 57 |
|
59 |
|
|
|
60 |
optparser.add_option('--bridge', |
| 61 |
help = 'use this device to build the bridge', |
| 62 |
dest = 'bridge', |
| 63 |
default = None, |
| 64 |
) |
| 65 |
|
| 58 |
optparser.add_option('--mac', |
66 |
optparser.add_option('--mac', |
| 59 |
help = 'use this specific mac addr', |
67 |
help = 'use this specific mac addr', |
| 60 |
dest = 'mac', |
68 |
dest = 'mac', |
|
Lines 119-125
Link Here
|
| 119 |
action = 'store_false', |
127 |
action = 'store_false', |
| 120 |
default = True, |
128 |
default = True, |
| 121 |
dest = 'irqchip', |
129 |
dest = 'irqchip', |
| 122 |
help = 'avoid using in-kernel irqchip', |
130 |
help = 'disable KVM kernel mode PIC/IOAPIC/LAPIC', |
| 123 |
) |
131 |
) |
| 124 |
|
132 |
|
| 125 |
optparser.add_option('-n', '--dry-run', |
133 |
optparser.add_option('-n', '--dry-run', |
|
Lines 148-154
Link Here
|
| 148 |
|
156 |
|
| 149 |
def insert_module(module): |
157 |
def insert_module(module): |
| 150 |
if os.spawnl(os.P_WAIT, '/sbin/insmod', 'insmod', |
158 |
if os.spawnl(os.P_WAIT, '/sbin/insmod', 'insmod', |
| 151 |
'kernel/%s.ko' % (module,)) != 0: |
159 |
kerneldir + '/%s.ko' % (module,)) != 0: |
| 152 |
raise Exception('failed to load kvm module') |
160 |
raise Exception('failed to load kvm module') |
| 153 |
|
161 |
|
| 154 |
def probe_module(module): |
162 |
def probe_module(module): |
|
Lines 183-189
Link Here
|
| 183 |
disk = options.image |
191 |
disk = options.image |
| 184 |
if options.install: |
192 |
if options.install: |
| 185 |
(status, output) = commands.getstatusoutput( |
193 |
(status, output) = commands.getstatusoutput( |
| 186 |
'qemu/qemu-img create -f qcow2 "%s" 30G' % disk) |
194 |
'qemu-img create -f qcow2 "%s" 30G' % disk) |
| 187 |
if status: |
195 |
if status: |
| 188 |
raise Exception, output |
196 |
raise Exception, output |
| 189 |
|
197 |
|
|
Lines 191-204
Link Here
|
| 191 |
if options.install: |
199 |
if options.install: |
| 192 |
bootdisk = 'd' |
200 |
bootdisk = 'd' |
| 193 |
|
201 |
|
|
|
202 |
# kvm always compiles for the x86_64 target |
| 194 |
arch = 'x86_64' |
203 |
arch = 'x86_64' |
| 195 |
|
204 |
|
| 196 |
if arch == 'x86_64': |
205 |
if arch == 'x86_64': |
| 197 |
cmd = 'qemu-system-' + arch |
206 |
cmd = 'kvm-system-' + arch |
| 198 |
else: |
207 |
else: |
| 199 |
cmd = 'qemu' |
208 |
cmd = 'kvm-system-i386' |
| 200 |
|
209 |
|
| 201 |
local_cmd = 'qemu/' + arch + '-softmmu/' + cmd |
210 |
local_cmd = prefix + '/bin/' + cmd |
| 202 |
if os.access(local_cmd, os.F_OK): |
211 |
if os.access(local_cmd, os.F_OK): |
| 203 |
cmd = local_cmd |
212 |
cmd = local_cmd |
| 204 |
else: |
213 |
else: |
|
Lines 226-240
Link Here
|
| 226 |
if not options.irqchip: |
235 |
if not options.irqchip: |
| 227 |
qemu_args += ('-no-kvm-irqchip',) |
236 |
qemu_args += ('-no-kvm-irqchip',) |
| 228 |
|
237 |
|
|
|
238 |
def getmac(interface): |
| 239 |
if os.access('/sbin/ip', os.F_OK): |
| 240 |
for line in commands.getoutput('/sbin/ip link show ' + interface).splitlines(): |
| 241 |
m = re.match(r'.*link/ether (..:..:..:..:..:..).*', line) |
| 242 |
if m: |
| 243 |
mac = m.group(1) |
| 244 |
return mac |
| 245 |
else: |
| 246 |
for line in commands.getoutput('/sbin/ifconfig ' + interface).splitlines(): |
| 247 |
m = re.match(r'.*HWaddr (..:..:..:..:..:..)', line) |
| 248 |
if m: |
| 249 |
mac = m.group(1) |
| 250 |
return mac |
| 251 |
return False |
| 252 |
|
| 229 |
if not options.notap: |
253 |
if not options.notap: |
|
|
254 |
bridge = options.bridge |
| 255 |
if not bridge: |
| 256 |
bridge = 'eth0' |
| 257 |
|
| 230 |
mac = options.mac |
258 |
mac = options.mac |
| 231 |
if not mac: |
259 |
if not mac: |
| 232 |
for line in commands.getoutput('/sbin/ip link show eth0').splitlines(): |
260 |
mac = getmac(bridge) |
| 233 |
m = re.match(r'.*link/ether (..:..:..:..:..:..).*', line) |
|
|
| 234 |
if m: |
| 235 |
mac = m.group(1) |
| 236 |
if not mac: |
261 |
if not mac: |
| 237 |
raise Exception, 'Unable to determine eth0 mac address' |
262 |
raise Exception, 'Unable to determine ' + bridge + ' mac address' |
| 238 |
mac_components = mac.split(':') |
263 |
mac_components = mac.split(':') |
| 239 |
mac_components[0] = 'a0' |
264 |
mac_components[0] = 'a0' |
| 240 |
mac = ':'.join(mac_components) |
265 |
mac = ':'.join(mac_components) |