From 7b399f9527955c4a68d52d4d7a8a371b80faae0c Mon Sep 17 00:00:00 2001
From: Alain Takoudjou <alain.takoudjou@nexedi.com>
Date: Thu, 10 Jan 2019 15:18:56 +0100
Subject: [PATCH] kvm: fix some parameters propagation, update parameter schema

---
 software/kvm/instance-kvm-cluster-input-schema.json |  4 ++--
 software/kvm/instance-kvm-cluster.cfg.jinja2.in     |  2 +-
 software/kvm/instance-kvm-input-schema.json         |  6 ++++--
 software/kvm/instance-kvm.cfg.jinja2                | 11 +++++------
 software/kvm/software.cfg                           |  8 ++++----
 software/kvm/template/kvm-controller-run.in         |  4 ++--
 software/kvm/template/template-kvm-run.in           |  2 +-
 7 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/software/kvm/instance-kvm-cluster-input-schema.json b/software/kvm/instance-kvm-cluster-input-schema.json
index efb3b1434..1eb73fc84 100644
--- a/software/kvm/instance-kvm-cluster-input-schema.json
+++ b/software/kvm/instance-kvm-cluster-input-schema.json
@@ -242,8 +242,8 @@
               "minimum": 1
             },
             "disk-format": {
-              "title": "Type of external disk drive to create by QEMU.",
-              "description": "Type of QEMU disk drive, to create.",
+              "title": "Disk format.",
+              "description": "Format of QEMU disk drive, to create.",
               "type": "string",
               "default": "qcow2",
               "enum": [
diff --git a/software/kvm/instance-kvm-cluster.cfg.jinja2.in b/software/kvm/instance-kvm-cluster.cfg.jinja2.in
index d0251f72b..cf9b05490 100644
--- a/software/kvm/instance-kvm-cluster.cfg.jinja2.in
+++ b/software/kvm/instance-kvm-cluster.cfg.jinja2.in
@@ -74,7 +74,7 @@ config-cpu-max-count = {{ dumps(kvm_parameter_dict.get('cpu-max-count', 24)) }}
 config-auto-ballooning = {{ dumps(kvm_parameter_dict.get('auto-ballooning', True)) }}
 {{ setconfig('disk-cache', kvm_parameter_dict.get('disk-cache', '')) }}
 {{ setconfig('disk-aio', kvm_parameter_dict.get('disk-aio', '')) }}
-{{ setconfig('cpu-model', kvm_parameter_dict.get('cpu-model', '')) }}
+{{ setconfig('cpu-model', kvm_parameter_dict.get('cpu-model', 'host')) }}
 {{ setconfig('disk-cache', kvm_parameter_dict.get('disk-cache', '')) }}
 {{ setconfig('disk-device-path', kvm_parameter_dict.get('disk-device-path', '')) }}
 
diff --git a/software/kvm/instance-kvm-input-schema.json b/software/kvm/instance-kvm-input-schema.json
index 71c2eb7d5..bc7ad4c31 100644
--- a/software/kvm/instance-kvm-input-schema.json
+++ b/software/kvm/instance-kvm-input-schema.json
@@ -126,7 +126,8 @@
     "cpu-model": {
       "title": "CPU model.",
       "description": "Select the emulated CPU model. Ex: SandyBridge,+erms,+smep,+smx,+vmx",
-      "type": "string"
+      "type": "string",
+      "default": "host"
     },
     "keyboard-layout-language": {
       "title": "Use keyboard layout language",
@@ -166,7 +167,8 @@
         "sv",
         "th",
         "tr"
-      ]
+      ],
+      "default": "fr"
     },
     "nbd-host": {
       "title": "NBD hostname",
diff --git a/software/kvm/instance-kvm.cfg.jinja2 b/software/kvm/instance-kvm.cfg.jinja2
index f6f119763..a57f8ddc0 100644
--- a/software/kvm/instance-kvm.cfg.jinja2
+++ b/software/kvm/instance-kvm.cfg.jinja2
@@ -154,7 +154,7 @@ disk-cache = ${slap-parameter:disk-cache}
 disk-aio = ${slap-parameter:disk-aio}
 auto-ballooning = ${slap-parameter:auto-ballooning}
 machine-options = ${slap-parameter:machine-options}
-cpu-hotplug-slot-size = ${slap-parameter:cpu-model}
+cpu-model = ${slap-parameter:cpu-model}
 
 log-file = ${directory:log}/qemu.log
 
@@ -470,8 +470,8 @@ ipv4-network-info =
 {% endif %}
 {% endif %}
 
-{% if use_tap == 'true' and slap_configuration.get('tap-ipv6-addr', '') != "" -%}
 ipv6-network-info =
+{% if use_tap == 'true' and slap_configuration.get('tap-ipv6-addr', '') != "" -%}
   Use these configurations below to configure IPv6 on interface {{ iface }} in your VM.
   IFACE={{ iface }}
   ${network-config-ipv6:ipv6-add-address}
@@ -502,8 +502,8 @@ command =
   #!/bin/sh
   IFACE={{ iface }}
   #try to be compatible with OS with old names
-  grep eth0 /etc/network/interfaces &> /dev/null && [ \$IFACE = ens3 ] && IFACE=eth0
-  grep eth1 /etc/network/interfaces &> /dev/null && [ \$IFACE = ens4 ] && IFACE=eth1
+  ip a | grep eth0: && [ \$IFACE = ens3 ] && IFACE=eth0
+  ip a | grep eth1: && [ \$IFACE = ens4 ] && IFACE=eth1
   ${:ifconfig}
   ${:route-iface}
   ${:route-network}
@@ -619,7 +619,6 @@ template = {{ ansible_promise_tpl }}
 rendered = ${directory:promises}/ansible_{{ name }}
 extensions = jinja2.ext.do
 context =
-  key host {{ slap_configuration.get('tap-ipv4-addr', '') }}
   raw logs ${directory:public}/ansible
   raw name {{ name }}
 
@@ -661,7 +660,7 @@ disk-cache = writeback
 disk-aio = native
 auto-ballooning = True
 machine-options =
-cpu-model =
+cpu-model = host
 
 nat-rules = 22 80 443
 use-nat = True
diff --git a/software/kvm/software.cfg b/software/kvm/software.cfg
index a8c53cf8e..a01dee6e0 100644
--- a/software/kvm/software.cfg
+++ b/software/kvm/software.cfg
@@ -99,7 +99,7 @@ recipe = hexagonit.recipe.download
 ignore-existing = true
 url = ${:_profile_base_location_}/instance-kvm.cfg.jinja2
 mode = 644
-md5sum = bc7e721577715ae777a963bbe3c3623d
+md5sum = 8ad61964dc1f6df9c7503d67f629bb9e
 download-only = true
 on-update = true
 
@@ -108,7 +108,7 @@ recipe = hexagonit.recipe.download
 ignore-existing = true
 url = ${:_profile_base_location_}/instance-kvm-cluster.cfg.jinja2.in
 mode = 644
-md5sum = 0a3e8fa290b78fa92367c9167077f520
+md5sum = 63fa784d8946d0b6e3fbd6381e1ea9f4
 download-only = true
 on-update = true
 
@@ -186,7 +186,7 @@ ignore-existing = true
 url = ${:_profile_base_location_}/template/template-kvm-run.in
 mode = 644
 filename = template-kvm-run.in
-md5sum = 8d681430f03ae4d35fc64b1625653a22
+md5sum = 9e40246b4bc4f968f0631016c939b014
 download-only = true
 on-update = true
 
@@ -196,7 +196,7 @@ ignore-existing = true
 url = ${:_profile_base_location_}/template/kvm-controller-run.in
 mode = 644
 filename = kvm-controller-run.in
-md5sum = c86cd67bbdd26b7b14b7449a1bbd959b
+md5sum = b96cba47c97f277c857176d69e086a12
 download-only = true
 on-update = true
 
diff --git a/software/kvm/template/kvm-controller-run.in b/software/kvm/template/kvm-controller-run.in
index 0744bc3bc..daf18d854 100644
--- a/software/kvm/template/kvm-controller-run.in
+++ b/software/kvm/template/kvm-controller-run.in
@@ -15,7 +15,7 @@ pid_file = '{{ parameter_dict.get("pid-file") }}'
 vnc_password = '{{ parameter_dict.get("vnc-passwd") }}'
 status_path = '{{ parameter_dict.get("kvm-status-path") }}'
 cpu_amount = {{ parameter_dict.get("cpu-count") }}
-cpu_model = '{{ parameter_dict.get("cpu-model", "qemu64-x86_64-cpu") }}'
+cpu_model = '{{ parameter_dict.get("cpu-model", "qemu64") }}'
 slot_hotplug_size = {{ parameter_dict.get("ram-hotplug-slot-size", 512) }}
 ram_size = {{ parameter_dict.get("ram-size") }}
 enable_device_hotplug = '{{ parameter_dict.get("enable-device-hotplug") }}'.lower()
@@ -48,7 +48,7 @@ def update():
       qemu_wrapper.updateDevice({
         'device': 'cpu',
         'amount': cpu_amount,
-        'model': cpu_model
+        'model': "%s-x86_64-cpu" % cpu_model
       })
       qemu_wrapper.updateDevice({
         'device': 'memory',
diff --git a/software/kvm/template/template-kvm-run.in b/software/kvm/template/template-kvm-run.in
index a96fcf720..842fab27e 100644
--- a/software/kvm/template/template-kvm-run.in
+++ b/software/kvm/template/template-kvm-run.in
@@ -88,7 +88,7 @@ if disk_device_path.startswith("/dev/"):
 smp_count = {{ parameter_dict.get("smp-count") }}
 smp_max_count = {{ parameter_dict.get("smp-max-count") }}
 machine_options = '{{ parameter_dict.get("machine-options", "") }}'.strip()
-cpu_model = '{{ parameter_dict.get("cpu-model", "host") }}'.strip()
+cpu_model = '{{ parameter_dict.get("cpu-model") }}'.strip()
 
 enable_device_hotplug = '{{ parameter_dict.get("enable-device-hotplug") }}'.lower()
 
-- 
2.30.9