Attempt to boot kvm even when NBD is not available

parent 6f4f3803
#!%(shell_path)s
#!%(python_path)s
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
if [ ! -e "%(disk_path)s" ]
then "%(qemu_img_path)s" create -f qcow2 "%(disk_path)s" %(disk_size)sG
fi
# Echo client program
import os
import socket
import subprocess
# TODO: -net nic,model=virtio, but OS installer has to provide the virtio_net
# module
exec %(qemu_path)s \
-net nic,macaddr=%(mac_address)s \
-net tap,ifname=%(tap_interface)s,script=no,downscript=no \
-smp %(smp_count)s \
-m %(ram_size)s \
-cdrom nbd:[%(nbd_ip)s]:%(nbd_port)s \
-drive file=%(disk_path)s,if=virtio,boot=on \
-vnc %(vnc_ip)s:1,ipv4,password \
-boot menu=on \
-qmp unix:%(socket_path)s,server \
-pidfile %(pid_file_path)s \
-no-kvm
def getSocketStatus(host, port):
s = None
for res in socket.getaddrinfo(host, port,
socket.AF_UNSPEC, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error, msg:
s = None
continue
try:
s.connect(sa)
except socket.error, msg:
s.close()
s = None
continue
break
return s
# create disk if doesn't exist
disk_path = '%(disk_path)s'
if not os.path.exists(disk_path):
subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2',
'%(disk_path)s', '%(disk_size)sG'])
kvm_argument_list = ['%(qemu_path)s',
'-net' 'nic,macaddr=%(mac_address)s',
'-net' 'tap,ifname=%(tap_interface)s,script=no,downscript=no',
'-smp' '%(smp_count)s',
'-m' '%(ram_size)s',
'-drive' 'file=%(disk_path)s,if=virtio,boot=on',
'-vnc' '%(vnc_ip)s:1,ipv4,password',
'-boot' 'menu=on',
'-qmp' 'unix:%(socket_path)s,server',
'-pidfile' '%(pid_file_path)s',
'-no-kvm']
# Try to connect to NBD server
s = getSocketStatus('%(nbd_ip)s', %(nbd_port)s)
if s is None:
# NBD is not available : launch kvm without it
print 'Warning : Nbd is not available.'
os.execv(kvm_argument_list)
else:
# NBD is available
kvm_argument_list.extend(['-cdrom' 'nbd:[%(nbd_ip)s]:%(nbd_port)s'])
os.execv(kvm_argument_list)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment