From 198224ad996721adcd8290106beb9a57fec5332b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20de=20Saint=20Martin?= <cedric.dsm@tiolive.com> Date: Mon, 5 Nov 2012 13:56:41 +0100 Subject: [PATCH] Implement disk-type and cpu-count parameters in KVM. --- slapos/recipe/kvm/__init__.py | 10 ++++++++- slapos/recipe/kvm/template/kvm_run.in | 2 +- software/kvm/instance-kvm-input-schema.json | 23 +++++++++++++++++---- software/kvm/instance-kvm.cfg.in | 6 +++++- software/kvm/software.cfg | 2 +- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/slapos/recipe/kvm/__init__.py b/slapos/recipe/kvm/__init__.py index c6033cc921..fbdbcfc2c0 100644 --- a/slapos/recipe/kvm/__init__.py +++ b/slapos/recipe/kvm/__init__.py @@ -33,6 +33,14 @@ class Recipe(GenericBaseRecipe): kvm instance configuration. """ def install(self): + # Sanitize drive type parameter + self.options.setdefault('disk-type', 'virtio') + if not self.options.get('disk-type') in ['ide', 'scsi', 'sd', + 'mtd', 'floppy', 'pflash', 'virtio']: + print 'Warning: "disk-type" parameter is not in allowed values. Using ' \ + '"virtio" value.' + self.options['disk-type'] = 'virtio' + config = dict( tap_interface=self.options['tap'], vnc_ip=self.options['vnc-ip'], @@ -41,6 +49,7 @@ class Recipe(GenericBaseRecipe): nbd_port=self.options['nbd-port'], disk_path=self.options['disk-path'], disk_size=self.options['disk-size'], + disk_type=self.options['disk-type'], mac_address=self.options['mac-address'], smp_count=self.options['smp-count'], ram_size=self.options['ram-size'], @@ -50,7 +59,6 @@ class Recipe(GenericBaseRecipe): shell_path=self.options['shell-path'], qemu_path=self.options['qemu-path'], qemu_img_path=self.options['qemu-img-path'], - # XXX Weak password vnc_passwd=self.options['passwd'] ) diff --git a/slapos/recipe/kvm/template/kvm_run.in b/slapos/recipe/kvm/template/kvm_run.in index ba705b02b5..88444ea410 100644 --- a/slapos/recipe/kvm/template/kvm_run.in +++ b/slapos/recipe/kvm/template/kvm_run.in @@ -36,7 +36,7 @@ kvm_argument_list = ['%(qemu_path)s', '-enable-kvm', '-net', 'nic,macaddr=%(mac_ '-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', + '-drive', 'file=%(disk_path)s,if=%(disk_type)s,boot=on', '-vnc', '%(vnc_ip)s:1,ipv4,password', '-boot', 'menu=on', '-qmp', 'unix:%(socket_path)s,server', diff --git a/software/kvm/instance-kvm-input-schema.json b/software/kvm/instance-kvm-input-schema.json index 260bcad8a1..6f794a69e2 100644 --- a/software/kvm/instance-kvm-input-schema.json +++ b/software/kvm/instance-kvm-input-schema.json @@ -18,8 +18,23 @@ "minimum": 1, "maximum": 80 }, - - + "disk-type": { + "title": "Disk type", + "description": "Type of QEMU disk drive.", + "type": "string", + "default": "virtio", + "enum": ["ide", "scsi", "sd", "mtd", "floppy", "pflash", "virtio"] + }, + + "cpu-count": { + "title": "CPU count", + "description": "Number of CPU cores.", + "type": "integer", + "minimum": 1, + "maximum": 8 + }, + + "nbd-ip": { "title": "NBD hostname", "description": "hostname (or IP) of the NBD server containing the boot image.", @@ -35,8 +50,8 @@ "minimum": 1, "maximum": 65535 }, - - + + "frontend-instance-guid": { "title": "Frontend Instance ID", "description": "Unique identifier of the frontend instance, like \"SOFTINST-11031\".", diff --git a/software/kvm/instance-kvm.cfg.in b/software/kvm/instance-kvm.cfg.in index dfdd7c6b66..695ac05f17 100644 --- a/software/kvm/instance-kvm.cfg.in +++ b/software/kvm/instance-kvm.cfg.in @@ -50,9 +50,10 @@ nbd-port = $${slap-parameter:nbd-port} tap = $${slap-network-information:network-interface} disk-path = $${directory:srv}/virtual.qcow2 disk-size = $${slap-parameter:disk-size} +disk-type = $${slap-parameter:disk-type} socket-path = $${directory:var}/qmp_socket pid-path = $${directory:run}/pid_file -smp-count = 1 +smp-count = $${slap-parameter:cpu-count} ram-size = $${slap-parameter:ram-size} mac-address = $${create-mac:mac-address} runner-path = $${directory:services}/kvm @@ -174,3 +175,6 @@ nbd_ip = $${:nbd-ip} ram-size = 1024 disk-size = 10 +disk-type = virtio + +cpu-count = 1 \ No newline at end of file diff --git a/software/kvm/software.cfg b/software/kvm/software.cfg index 34fcc56204..0fecca4582 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 = 67c1980ba1e70b376f2811602991ff09 +md5sum = aefed0723c79f4d4b9ed977b73e4bac5 output = ${buildout:directory}/template-kvm.cfg mode = 0644 -- 2.30.9