diff --git a/slapos/recipe/kvm/__init__.py b/slapos/recipe/kvm/__init__.py index fbdbcfc2c072ee99f6c97baa8147f669e1b4d49e..c10e0e7fd32bf22fa71b8226efbe94413024089c 100644 --- a/slapos/recipe/kvm/__init__.py +++ b/slapos/recipe/kvm/__init__.py @@ -45,8 +45,10 @@ class Recipe(GenericBaseRecipe): tap_interface=self.options['tap'], vnc_ip=self.options['vnc-ip'], vnc_port=self.options['vnc-port'], - nbd_ip=self.options['nbd-ip'], + nbd_ip=self.options['nbd-host'], 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_size=self.options['disk-size'], disk_type=self.options['disk-type'], @@ -75,4 +77,3 @@ class Recipe(GenericBaseRecipe): return [runner_path, controller_path] - diff --git a/slapos/recipe/kvm/template/kvm_run.in b/slapos/recipe/kvm/template/kvm_run.in index 88444ea41035674f2e35ebdb86f9666c09cf3db2..ea855561009972f5aa93562fd87bfb28b9fb9e19 100644 --- a/slapos/recipe/kvm/template/kvm_run.in +++ b/slapos/recipe/kvm/template/kvm_run.in @@ -30,26 +30,32 @@ def getSocketStatus(host, port): 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']) + 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', '-smp', '%(smp_count)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', '-boot', 'menu=on', '-qmp', 'unix:%(socket_path)s,server', '-pidfile', '%(pid_file_path)s', ] -# 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('%(qemu_path)s', kvm_argument_list) -else: - # NBD is available - kvm_argument_list.extend(['-cdrom', 'nbd:[%(nbd_ip)s]:%(nbd_port)s']) - os.execv('%(qemu_path)s', kvm_argument_list) +# Try to connect to NBD server (and second nbd if defined) +for nbd_ip, nbd_port in ( + ('%(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 + print 'Warning : Nbd is not available.' + else: + # NBD is available + kvm_argument_list.extend([ + '-drive', + 'file=nbd:[%%s]:%%s,media=cdrom' %% (nbd_ip, nbd_port)]) + +os.execv('%(qemu_path)s', kvm_argument_list) diff --git a/software/kvm/instance-kvm.cfg.in b/software/kvm/instance-kvm.cfg.in index 041cc136f1ac97f858891f89fb47840834b22ead..6669032997ed2e74d27129d531749c7c9275470d 100644 --- a/software/kvm/instance-kvm.cfg.in +++ b/software/kvm/instance-kvm.cfg.in @@ -45,8 +45,10 @@ bytes = 4 recipe = slapos.cookbook:kvm vnc-ip = $${slap-network-information:local-ipv4} vnc-port = 5901 -nbd-ip = $${slap-parameter:nbd-host} +nbd-host = $${slap-parameter:nbd-host} nbd-port = $${slap-parameter:nbd-port} +nbd2-host = $${slap-parameter:nbd2-host} +nbd2-port = $${slap-parameter:nbd2-port} tap = $${slap-network-information:network-interface} disk-path = $${directory:srv}/virtual.qcow2 disk-size = $${slap-parameter:disk-size} @@ -168,6 +170,8 @@ frontend-software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/ta nbd-port = 1024 nbd-host = debian.nbd.vifib.net +nbd2-port = 1024 +nbd2-host = ram-size = 1024 disk-size = 10 diff --git a/software/kvm/software.cfg b/software/kvm/software.cfg index 0fecca4582c692e4e8e4f768a5bed3f2c0883ec1..781edc8336b73a731d86afca6724f1d2794a08d4 100644 --- a/software/kvm/software.cfg +++ b/software/kvm/software.cfg @@ -119,7 +119,7 @@ command = [template-kvm] recipe = slapos.recipe.template url = ${:_profile_base_location_}/instance-kvm.cfg.in -md5sum = aefed0723c79f4d4b9ed977b73e4bac5 +md5sum = 5607cb6b6af58694d55b87411880d368 output = ${buildout:directory}/template-kvm.cfg mode = 0644