[Kimchi-devel] [PATCH v3] [Kimchi 1/2] added 'console' parameter to templates api for s390x

sureshab at linux.vnet.ibm.com sureshab at linux.vnet.ibm.com
Thu Sep 15 10:13:15 UTC 2016


From: Suresh Babu Angadi <sureshab at in.ibm.com>

In case of s390x architecture, console type can be
either virtio/sclp. Extended current code to support
console configuration in case of s390x

* added 'console'='virtio' in template defaults for s390x
* added 'console' parameter as optional attribute for s390x
  which returns current 'console' attached to template
* made changes in model code to support 'console' attribute
  in case of create/update template when running on s390x
* added appropriate error codes in i18n.py
* added API.json changes to validate 'console' attribute

Signed-off-by: Suresh Babu Angadi <sureshab at in.ibm.com>
---
 API.json             | 16 ++++++++++++++--
 control/templates.py |  1 +
 i18n.py              |  2 ++
 model/templates.py   |  6 ++++++
 osinfo.py            |  4 ++++
 5 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/API.json b/API.json
index 9ad60a2..0456476 100644
--- a/API.json
+++ b/API.json
@@ -671,7 +671,13 @@
                     "items": { "type": "string" }
                 },
                 "graphics": { "$ref": "#/kimchitype/graphics" },
-                "cpu_info": { "$ref": "#/kimchitype/cpu_info" }
+                "cpu_info": { "$ref": "#/kimchitype/cpu_info" },
+                "console": {
+                    "description": "type of the console attached to the guest in s390x architecture",
+                    "type": "string",
+                    "pattern": "^sclp|virtio$",
+                    "error": "KCHTMPL0044E"
+                }
             },
             "additionalProperties": false,
             "error": "KCHAPI0001E"
@@ -844,7 +850,13 @@
                     "items": { "type": "string" }
                 },
                 "graphics": { "$ref": "#/kimchitype/graphics" },
-                "cpu_info": { "$ref": "#/kimchitype/cpu_info" }
+                "cpu_info": { "$ref": "#/kimchitype/cpu_info" },
+                "console": {
+                    "description": "type of the console attached to the guest in s390x architecture",
+                    "type": "string",
+                    "pattern": "^sclp|virtio$",
+                    "error": "KCHTMPL0044E"
+                }
             },
             "additionalProperties": false,
             "error": "KCHAPI0001E"
diff --git a/control/templates.py b/control/templates.py
index 0406c6b..ca36be3 100644
--- a/control/templates.py
+++ b/control/templates.py
@@ -76,5 +76,6 @@ class Template(Resource):
         }
         if os.uname()[4] in ['s390x', 's390']:
             info['interfaces'] = self.info.get('interfaces', [])
+            info['console'] = self.info.get('console', '')
 
         return info
diff --git a/i18n.py b/i18n.py
index b6533d4..177bd50 100644
--- a/i18n.py
+++ b/i18n.py
@@ -206,6 +206,8 @@ messages = {
     "KCHTMPL0040E": _("Storage without libvirt pool is not supported on this architecture"),
     "KCHTMPL0041E": _("Error while creating the virtual disk for the guest. Details: %(err)s"),
     "KCHTMPL0042E": _("When setting template disks without libvirt, following parameters are required: 'index', 'format', 'path', 'size'"),
+    "KCHTMPL0043E": _("console parameter is only supported for s390x/s390 architecture."),
+    "KCHTMPL0044E": _("invalid console type, supported types are sclp/virtio."),
 
     "KCHPOOL0001E": _("Storage pool %(name)s already exists"),
     "KCHPOOL0002E": _("Storage pool %(name)s does not exist"),
diff --git a/model/templates.py b/model/templates.py
index a5d17af..1bd49e6 100644
--- a/model/templates.py
+++ b/model/templates.py
@@ -67,6 +67,9 @@ class TemplatesModel(object):
         interfaces = params.get('interfaces', [])
         validate_interfaces(interfaces)
 
+        if os.uname()[4] not in ['s390x', 's390'] and 'console' in params:
+            raise InvalidParameter("KCHTMPL0043E")
+
         # get source_media
         source_media = params.pop("source_media")
 
@@ -231,6 +234,9 @@ class TemplateModel(object):
         interfaces = params.get('interfaces', [])
         validate_interfaces(interfaces)
 
+        if os.uname()[4] not in ['s390x', 's390'] and 'console' in params:
+            raise InvalidParameter("KCHTMPL0043E")
+
         # Merge graphics settings
         graph_args = params.get('graphics')
         if graph_args:
diff --git a/osinfo.py b/osinfo.py
index 021b53d..bc6205b 100644
--- a/osinfo.py
+++ b/osinfo.py
@@ -169,6 +169,10 @@ def _get_tmpl_defaults():
     tmpl_defaults['processor']['maxvcpus'] = 1
     tmpl_defaults['graphics'] = {'type': 'vnc', 'listen': '127.0.0.1'}
 
+    # for s390x architecture, set default console as sclp
+    if host_arch in ['s390x', 's390']:
+        tmpl_defaults['console'] = 'virtio'
+
     default_config = ConfigObj(tmpl_defaults)
 
     # Load template configuration file
-- 
2.1.0




More information about the Kimchi-devel mailing list