From: Suresh Babu Angadi <sureshab(a)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(a)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..fe5579e 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": "KCHTMPL0041E"
+ }
},
"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": "KCHTMPL0041E"
+ }
},
"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 47c829e..1684dc4 100644
--- a/i18n.py
+++ b/i18n.py
@@ -203,6 +203,8 @@ messages = {
"KCHTMPL0037E": _("Interfaces should be list of interfaces. Each
interface should have name, type and mode(optional, only applicable for interfcae type
'macvtap'."),
"KCHTMPL0038E": _("Interface expects an object with parameters:
'name', 'type' and 'mode'. Name should be name of host network
interface (Ethernet, Bond, VLAN) for type 'macvtap' or the name of host
openvswitch bridge interface for type 'ovs'. Mode (optional) is only applicable
for interface type 'macvtap' to indicates whether packets will be delivered
directly to target device (bridge) or to the external bridge (vepa-capable
bridge)."),
"KCHTMPL0039E": _("Interfaces parameter only supported on s390x or
s390 architecture."),
+ "KCHTMPL0040E": _("console parameter is only supported for s390x/s390
architecture."),
+ "KCHTMPL0041E": _("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 04e6626..faf1fd5 100644
--- a/model/templates.py
+++ b/model/templates.py
@@ -65,6 +65,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("KCHTMPL0040E")
+
# get source_media
source_media = params.pop("source_media")
@@ -229,6 +232,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("KCHTMPL0040E")
+
# Merge graphics settings
graph_args = params.get('graphics')
if graph_args:
diff --git a/osinfo.py b/osinfo.py
index 3e56d97..6069c46 100644
--- a/osinfo.py
+++ b/osinfo.py
@@ -163,6 +163,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