Commit c44aff58 authored by Cédric de Saint Martin's avatar Cédric de Saint Martin Committed by Marco Mariani

Implement support for second NBD

parent ecd4b0c6
...@@ -45,8 +45,10 @@ class Recipe(GenericBaseRecipe): ...@@ -45,8 +45,10 @@ class Recipe(GenericBaseRecipe):
tap_interface=self.options['tap'], tap_interface=self.options['tap'],
vnc_ip=self.options['vnc-ip'], vnc_ip=self.options['vnc-ip'],
vnc_port=self.options['vnc-port'], vnc_port=self.options['vnc-port'],
nbd_ip=self.options['nbd-ip'], nbd_ip=self.options['nbd-host'],
nbd_port=self.options['nbd-port'], nbd_port=self.options['nbd-port'],
nbd2_ip=self.options.get('nbd2-host', ''),
nbd2_port=self.options.get('nbd2-port', 1024),
disk_path=self.options['disk-path'], disk_path=self.options['disk-path'],
disk_size=self.options['disk-size'], disk_size=self.options['disk-size'],
disk_type=self.options['disk-type'], disk_type=self.options['disk-type'],
...@@ -75,4 +77,3 @@ class Recipe(GenericBaseRecipe): ...@@ -75,4 +77,3 @@ class Recipe(GenericBaseRecipe):
return [runner_path, controller_path] return [runner_path, controller_path]
...@@ -30,26 +30,32 @@ def getSocketStatus(host, port): ...@@ -30,26 +30,32 @@ def getSocketStatus(host, port):
disk_path = '%(disk_path)s' disk_path = '%(disk_path)s'
if not os.path.exists(disk_path): if not os.path.exists(disk_path):
subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2', subprocess.Popen(['%(qemu_img_path)s', 'create' ,'-f', 'qcow2',
'%(disk_path)s', '%(disk_size)sG']) disk_path, '%(disk_size)sG'])
kvm_argument_list = ['%(qemu_path)s', '-enable-kvm', '-net', 'nic,macaddr=%(mac_address)s', kvm_argument_list = ['%(qemu_path)s',
'-enable-kvm', '-net', 'nic,macaddr=%(mac_address)s',
'-net', 'tap,ifname=%(tap_interface)s,script=no,downscript=no', '-net', 'tap,ifname=%(tap_interface)s,script=no,downscript=no',
'-smp', '%(smp_count)s', '-smp', '%(smp_count)s',
'-m', '%(ram_size)s', '-m', '%(ram_size)s',
'-drive', 'file=%(disk_path)s,if=%(disk_type)s,boot=on', '-drive', 'file=%(disk_path)s,if=%(disk_type)s',
'-vnc', '%(vnc_ip)s:1,ipv4,password', '-vnc', '%(vnc_ip)s:1,ipv4,password',
'-boot', 'menu=on', '-boot', 'menu=on',
'-qmp', 'unix:%(socket_path)s,server', '-qmp', 'unix:%(socket_path)s,server',
'-pidfile', '%(pid_file_path)s', '-pidfile', '%(pid_file_path)s',
] ]
# Try to connect to NBD server # Try to connect to NBD server (and second nbd if defined)
s = getSocketStatus('%(nbd_ip)s', %(nbd_port)s) for nbd_ip, nbd_port in (
if s is None: ('%(nbd_ip)s', %(nbd_port)s), ('%(nbd2_ip)s', %(nbd2_port)s)):
if nbd_ip and nbd_port:
s = getSocketStatus(nbd_ip, nbd_port)
if s is None:
# NBD is not available : launch kvm without it # NBD is not available : launch kvm without it
print 'Warning : Nbd is not available.' print 'Warning : Nbd is not available.'
os.execv('%(qemu_path)s', kvm_argument_list) else:
else:
# NBD is available # NBD is available
kvm_argument_list.extend(['-cdrom', 'nbd:[%(nbd_ip)s]:%(nbd_port)s']) kvm_argument_list.extend([
os.execv('%(qemu_path)s', kvm_argument_list) '-drive',
'file=nbd:[%%s]:%%s,media=cdrom' %% (nbd_ip, nbd_port)])
os.execv('%(qemu_path)s', kvm_argument_list)
...@@ -45,8 +45,10 @@ bytes = 4 ...@@ -45,8 +45,10 @@ bytes = 4
recipe = slapos.cookbook:kvm recipe = slapos.cookbook:kvm
vnc-ip = $${slap-network-information:local-ipv4} vnc-ip = $${slap-network-information:local-ipv4}
vnc-port = 5901 vnc-port = 5901
nbd-ip = $${slap-parameter:nbd-host} nbd-host = $${slap-parameter:nbd-host}
nbd-port = $${slap-parameter:nbd-port} nbd-port = $${slap-parameter:nbd-port}
nbd2-host = $${slap-parameter:nbd2-host}
nbd2-port = $${slap-parameter:nbd2-port}
tap = $${slap-network-information:network-interface} tap = $${slap-network-information:network-interface}
disk-path = $${directory:srv}/virtual.qcow2 disk-path = $${directory:srv}/virtual.qcow2
disk-size = $${slap-parameter:disk-size} disk-size = $${slap-parameter:disk-size}
...@@ -168,6 +170,8 @@ frontend-software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/ta ...@@ -168,6 +170,8 @@ frontend-software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/ta
nbd-port = 1024 nbd-port = 1024
nbd-host = debian.nbd.vifib.net nbd-host = debian.nbd.vifib.net
nbd2-port = 1024
nbd2-host =
ram-size = 1024 ram-size = 1024
disk-size = 10 disk-size = 10
......
...@@ -119,7 +119,7 @@ command = ...@@ -119,7 +119,7 @@ command =
[template-kvm] [template-kvm]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-kvm.cfg.in url = ${:_profile_base_location_}/instance-kvm.cfg.in
md5sum = aefed0723c79f4d4b9ed977b73e4bac5 md5sum = 5607cb6b6af58694d55b87411880d368
output = ${buildout:directory}/template-kvm.cfg output = ${buildout:directory}/template-kvm.cfg
mode = 0644 mode = 0644
......
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