[PATCH v2] [Kimchi 0/2] added 'console' parameter for templates & vms api for s390x

From: Suresh Babu Angadi <sureshab@in.ibm.com> v1-v2: provided detailed commit message and reduced number of patches In case of s390x architecture, console type can be either virtio/sclp. Extended current code to support console configuration in case of s390x this patch set provides option to configure 'console' parameter for templates and vms api when running on 's390x' architecture Suresh Babu Angadi (2): added 'console' parameter to templates api for s390x added 'console' parameter to vms api for s390x API.json | 24 ++++++++++++++--- control/templates.py | 1 + i18n.py | 4 +++ model/templates.py | 6 +++++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++----------------- osinfo.py | 4 +++ xmlutils/serial.py | 5 +++- 7 files changed, 91 insertions(+), 28 deletions(-) -- 2.1.0

From: Suresh Babu Angadi <sureshab@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@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

From: Suresh Babu Angadi <sureshab@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' parameter as optional attribute for s390x which returns current console type attached to guest * made changes in model code to support update of 'console' attribute for guest when running on s390x * added appropriate error codes in i18n.py * added API.json changes to validate 'console' attribute * made changes in xml code generation, default value as 'virtio' Signed-off-by: Suresh Babu Angadi <sureshab@in.ibm.com> --- API.json | 8 +++++- i18n.py | 2 ++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++++----------------- xmlutils/serial.py | 5 +++- 4 files changed, 64 insertions(+), 26 deletions(-) diff --git a/API.json b/API.json index fe5579e..f0861a2 100644 --- a/API.json +++ b/API.json @@ -414,7 +414,13 @@ } }, "cpu_info": { "$ref": "#/kimchitype/cpu_info" }, - "memory": { "$ref": "#/kimchitype/memory" } + "memory": { "$ref": "#/kimchitype/memory" }, + "console": { + "description": "type of the console attached to the guest in s390x architecture", + "type": "string", + "pattern": "^sclp|virtio$", + "error": "KCHVM0088E" + } }, "additionalProperties": false }, diff --git a/i18n.py b/i18n.py index 1684dc4..c46caf4 100644 --- a/i18n.py +++ b/i18n.py @@ -137,6 +137,8 @@ messages = { "KCHVM0084E": _("Error occured while retrieving the Virt Viewer file for virtual machine %(name)s : %(err)s"), "KCHVM0085E": _("Virtual machine title must be a string"), "KCHVM0086E": _("Virtual machine description must be a string"), + "KCHVM0087E": _("console parameter is only supported for s390x/s390 architecture."), + "KCHVM0088E": _("invalid console type, supported types are sclp/virtio."), "KCHVMHDEV0001E": _("VM %(vmid)s does not contain directly assigned host device %(dev_name)s."), "KCHVMHDEV0002E": _("The host device %(dev_name)s is not allowed to directly assign to VM."), diff --git a/model/vms.py b/model/vms.py index b889166..5855a11 100644 --- a/model/vms.py +++ b/model/vms.py @@ -85,7 +85,7 @@ VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users'] # update parameters which are updatable when the VM is offline VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 'memory', 'name', 'users', 'bootorder', 'bootmenu', - 'description', 'title'] + 'description', 'title', 'console'] XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file" XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']" @@ -96,6 +96,7 @@ XPATH_DOMAIN_MEMORY = '/domain/memory' XPATH_DOMAIN_MEMORY_UNIT = '/domain/memory/@unit' XPATH_DOMAIN_UUID = '/domain/uuid' XPATH_DOMAIN_DEV_CPU_ID = '/domain/devices/spapr-cpu-socket/@id' +XPATH_DOMAIN_CONSOLE_TARGET = "/domain/devices/console/target/@type" XPATH_BOOT = 'os/boot/@dev' XPATH_BOOTMENU = 'os/bootmenu/@enable' @@ -109,6 +110,7 @@ XPATH_TITLE = './title' XPATH_TOPOLOGY = './cpu/topology' XPATH_VCPU = './vcpu' XPATH_MAX_MEMORY = './maxMemory' +XPATH_CONSOLE_TARGET = "./devices/console/target" # key: VM name; value: lock object vm_locks = {} @@ -263,6 +265,9 @@ class VMModel(object): return sockets and cores and threads def update(self, name, params): + if platform.machine() not in ['s390x', 's390'] and\ + 'console' in params: + raise InvalidParameter('KCHVM0087E') lock = vm_locks.get(name) if lock is None: lock = threading.Lock() @@ -793,6 +798,19 @@ class VMModel(object): # update <os> return ET.tostring(et) + def _update_s390x_console(self, xml, params): + if xpath_get_text(xml, XPATH_DOMAIN_CONSOLE_TARGET): + # if console is defined, update console + return xml_item_update(xml, XPATH_CONSOLE_TARGET, + params.get('console'), 'type') + # if console is not defined earlier, add console + console = E.console(type="pty") + console.append(E.target(type=params.get('console'), port='0')) + et = ET.fromstring(xml) + devices = et.find('devices') + devices.append(console) + return ET.tostring(et) + def _static_vm_update(self, vm_name, dom, params): old_xml = new_xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE) params = copy.deepcopy(params) @@ -861,6 +879,9 @@ class VMModel(object): if "bootorder" or "bootmenu" in params: new_xml = self._update_bootorder(new_xml, params) + if platform.machine() in ['s390', 's390x'] and params.get('console'): + new_xml = self._update_s390x_console(new_xml, params) + snapshots_info = [] conn = self.conn.get() try: @@ -1303,29 +1324,35 @@ class VMModel(object): bootmenu = "yes" if "yes" in xpath_get_text(xml, XPATH_BOOTMENU) \ else "no" - return {'name': name, - 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), - 'description': "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), - 'state': state, - 'stats': res, - 'uuid': dom.UUIDString(), - 'memory': {'current': memory, 'maxmemory': maxmemory}, - 'cpu_info': cpu_info, - 'screenshot': screenshot, - 'icon': icon, - # (type, listen, port, passwd, passwdValidTo) - 'graphics': {"type": graphics[0], - "listen": graphics[1], - "port": graphics_port, - "passwd": graphics[3], - "passwdValidTo": graphics[4]}, - 'users': users, - 'groups': groups, - 'access': 'full', - 'persistent': True if dom.isPersistent() else False, - 'bootorder': boot, - 'bootmenu': bootmenu - } + vm_info = {'name': name, + 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), + 'description': + "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), + 'state': state, + 'stats': res, + 'uuid': dom.UUIDString(), + 'memory': {'current': memory, 'maxmemory': maxmemory}, + 'cpu_info': cpu_info, + 'screenshot': screenshot, + 'icon': icon, + # (type, listen, port, passwd, passwdValidTo) + 'graphics': {"type": graphics[0], + "listen": graphics[1], + "port": graphics_port, + "passwd": graphics[3], + "passwdValidTo": graphics[4]}, + 'users': users, + 'groups': groups, + 'access': 'full', + 'persistent': True if dom.isPersistent() else False, + 'bootorder': boot, + 'bootmenu': bootmenu + } + if platform.machine() in ['s390', 's390x']: + vm_console = xpath_get_text(xml, XPATH_DOMAIN_CONSOLE_TARGET) + vm_info['console'] = vm_console[0] if vm_console else '' + + return vm_info def _vm_get_disk_paths(self, dom): xml = dom.XMLDesc(0) diff --git a/xmlutils/serial.py b/xmlutils/serial.py index c823ee6..f61eefa 100644 --- a/xmlutils/serial.py +++ b/xmlutils/serial.py @@ -38,6 +38,7 @@ def get_serial_xml(params): </console> For s390x + target type can be sclp/virtio <console type='pty'> <target type='sclp' port='0'/> </console> @@ -50,8 +51,10 @@ def get_serial_xml(params): return ET.tostring(console, encoding='utf-8', pretty_print=True) # for s390x elif params["arch"] in ["s390x"]: + # if params doesn't have console parameter, use virtio as default + console_type = params.get('console', 'virtio') console = E.console(type="pty") - console.append(E.target(type="sclp", port='0')) + console.append(E.target(type=console_type, port='0')) return ET.tostring(console, encoding='utf-8', pretty_print=True) # for x else: -- 2.1.0

Looks good, a minor comment. On 09/13/2016 01:29 PM, sureshab@linux.vnet.ibm.com wrote:
From: Suresh Babu Angadi <sureshab@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' parameter as optional attribute for s390x which returns current console type attached to guest * made changes in model code to support update of 'console' attribute for guest when running on s390x * added appropriate error codes in i18n.py * added API.json changes to validate 'console' attribute * made changes in xml code generation, default value as 'virtio'
Signed-off-by: Suresh Babu Angadi <sureshab@in.ibm.com> --- API.json | 8 +++++- i18n.py | 2 ++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++++----------------- xmlutils/serial.py | 5 +++- 4 files changed, 64 insertions(+), 26 deletions(-)
diff --git a/API.json b/API.json index fe5579e..f0861a2 100644 --- a/API.json +++ b/API.json @@ -414,7 +414,13 @@ } }, "cpu_info": { "$ref": "#/kimchitype/cpu_info" }, - "memory": { "$ref": "#/kimchitype/memory" } + "memory": { "$ref": "#/kimchitype/memory" }, + "console": { + "description": "type of the console attached to the guest in s390x architecture", + "type": "string", + "pattern": "^sclp|virtio$", + "error": "KCHVM0088E" + } }, "additionalProperties": false }, diff --git a/i18n.py b/i18n.py index 1684dc4..c46caf4 100644 --- a/i18n.py +++ b/i18n.py @@ -137,6 +137,8 @@ messages = { "KCHVM0084E": _("Error occured while retrieving the Virt Viewer file for virtual machine %(name)s : %(err)s"), "KCHVM0085E": _("Virtual machine title must be a string"), "KCHVM0086E": _("Virtual machine description must be a string"), + "KCHVM0087E": _("console parameter is only supported for s390x/s390 architecture."), + "KCHVM0088E": _("invalid console type, supported types are sclp/virtio."),
"KCHVMHDEV0001E": _("VM %(vmid)s does not contain directly assigned host device %(dev_name)s."), "KCHVMHDEV0002E": _("The host device %(dev_name)s is not allowed to directly assign to VM."), diff --git a/model/vms.py b/model/vms.py index b889166..5855a11 100644 --- a/model/vms.py +++ b/model/vms.py @@ -85,7 +85,7 @@ VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users'] # update parameters which are updatable when the VM is offline VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 'memory', 'name', 'users', 'bootorder', 'bootmenu', - 'description', 'title'] + 'description', 'title', 'console']
XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file" XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']" @@ -96,6 +96,7 @@ XPATH_DOMAIN_MEMORY = '/domain/memory' XPATH_DOMAIN_MEMORY_UNIT = '/domain/memory/@unit' XPATH_DOMAIN_UUID = '/domain/uuid' XPATH_DOMAIN_DEV_CPU_ID = '/domain/devices/spapr-cpu-socket/@id' +XPATH_DOMAIN_CONSOLE_TARGET = "/domain/devices/console/target/@type"
XPATH_BOOT = 'os/boot/@dev' XPATH_BOOTMENU = 'os/bootmenu/@enable' @@ -109,6 +110,7 @@ XPATH_TITLE = './title' XPATH_TOPOLOGY = './cpu/topology' XPATH_VCPU = './vcpu' XPATH_MAX_MEMORY = './maxMemory' +XPATH_CONSOLE_TARGET = "./devices/console/target"
# key: VM name; value: lock object vm_locks = {} @@ -263,6 +265,9 @@ class VMModel(object): return sockets and cores and threads
def update(self, name, params): + if platform.machine() not in ['s390x', 's390'] and\ + 'console' in params: + raise InvalidParameter('KCHVM0087E') lock = vm_locks.get(name) if lock is None: lock = threading.Lock() @@ -793,6 +798,19 @@ class VMModel(object): # update <os> return ET.tostring(et)
+ def _update_s390x_console(self, xml, params): + if xpath_get_text(xml, XPATH_DOMAIN_CONSOLE_TARGET): + # if console is defined, update console + return xml_item_update(xml, XPATH_CONSOLE_TARGET, + params.get('console'), 'type') + # if console is not defined earlier, add console + console = E.console(type="pty") + console.append(E.target(type=params.get('console'), port='0')) + et = ET.fromstring(xml) + devices = et.find('devices') + devices.append(console) + return ET.tostring(et) + def _static_vm_update(self, vm_name, dom, params): old_xml = new_xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE) params = copy.deepcopy(params) @@ -861,6 +879,9 @@ class VMModel(object): if "bootorder" or "bootmenu" in params: new_xml = self._update_bootorder(new_xml, params)
+ if platform.machine() in ['s390', 's390x'] and params.get('console'): + new_xml = self._update_s390x_console(new_xml, params) + snapshots_info = [] conn = self.conn.get() try: @@ -1303,29 +1324,35 @@ class VMModel(object): bootmenu = "yes" if "yes" in xpath_get_text(xml, XPATH_BOOTMENU) \ else "no"
- return {'name': name, - 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), - 'description': "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), - 'state': state, - 'stats': res, - 'uuid': dom.UUIDString(), - 'memory': {'current': memory, 'maxmemory': maxmemory}, - 'cpu_info': cpu_info, - 'screenshot': screenshot, - 'icon': icon, - # (type, listen, port, passwd, passwdValidTo) - 'graphics': {"type": graphics[0], - "listen": graphics[1], - "port": graphics_port, - "passwd": graphics[3], - "passwdValidTo": graphics[4]}, - 'users': users, - 'groups': groups, - 'access': 'full', - 'persistent': True if dom.isPersistent() else False, - 'bootorder': boot, - 'bootmenu': bootmenu - } + vm_info = {'name': name, + 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), + 'description': + "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), + 'state': state, + 'stats': res, + 'uuid': dom.UUIDString(), + 'memory': {'current': memory, 'maxmemory': maxmemory}, + 'cpu_info': cpu_info, + 'screenshot': screenshot, + 'icon': icon, + # (type, listen, port, passwd, passwdValidTo) + 'graphics': {"type": graphics[0], + "listen": graphics[1], + "port": graphics_port, + "passwd": graphics[3], + "passwdValidTo": graphics[4]}, + 'users': users, + 'groups': groups, + 'access': 'full', + 'persistent': True if dom.isPersistent() else False, + 'bootorder': boot, + 'bootmenu': bootmenu + } + if platform.machine() in ['s390', 's390x']: + vm_console = xpath_get_text(xml, XPATH_DOMAIN_CONSOLE_TARGET) + vm_info['console'] = vm_console[0] if vm_console else '' in case console is not set, do we need to have that key in vm_info as blank or we should not have the key itself. + + return vm_info
def _vm_get_disk_paths(self, dom): xml = dom.XMLDesc(0) diff --git a/xmlutils/serial.py b/xmlutils/serial.py index c823ee6..f61eefa 100644 --- a/xmlutils/serial.py +++ b/xmlutils/serial.py @@ -38,6 +38,7 @@ def get_serial_xml(params): </console>
For s390x + target type can be sclp/virtio <console type='pty'> <target type='sclp' port='0'/> </console> @@ -50,8 +51,10 @@ def get_serial_xml(params): return ET.tostring(console, encoding='utf-8', pretty_print=True) # for s390x elif params["arch"] in ["s390x"]: + # if params doesn't have console parameter, use virtio as default + console_type = params.get('console', 'virtio') console = E.console(type="pty") - console.append(E.target(type="sclp", port='0')) + console.append(E.target(type=console_type, port='0')) return ET.tostring(console, encoding='utf-8', pretty_print=True) # for x else:

On 09/13/2016 01:46 PM, Archana Singh wrote:
Looks good, a minor comment.
On 09/13/2016 01:29 PM, sureshab@linux.vnet.ibm.com wrote:
From: Suresh Babu Angadi <sureshab@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' parameter as optional attribute for s390x which returns current console type attached to guest * made changes in model code to support update of 'console' attribute for guest when running on s390x * added appropriate error codes in i18n.py * added API.json changes to validate 'console' attribute * made changes in xml code generation, default value as 'virtio'
Signed-off-by: Suresh Babu Angadi <sureshab@in.ibm.com> --- API.json | 8 +++++- i18n.py | 2 ++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++++----------------- xmlutils/serial.py | 5 +++- 4 files changed, 64 insertions(+), 26 deletions(-)
diff --git a/API.json b/API.json index fe5579e..f0861a2 100644 --- a/API.json +++ b/API.json @@ -414,7 +414,13 @@ } }, "cpu_info": { "$ref": "#/kimchitype/cpu_info" }, - "memory": { "$ref": "#/kimchitype/memory" } + "memory": { "$ref": "#/kimchitype/memory" }, + "console": { + "description": "type of the console attached to the guest in s390x architecture", + "type": "string", + "pattern": "^sclp|virtio$", + "error": "KCHVM0088E" + } }, "additionalProperties": false }, diff --git a/i18n.py b/i18n.py index 1684dc4..c46caf4 100644 --- a/i18n.py +++ b/i18n.py @@ -137,6 +137,8 @@ messages = { "KCHVM0084E": _("Error occured while retrieving the Virt Viewer file for virtual machine %(name)s : %(err)s"), "KCHVM0085E": _("Virtual machine title must be a string"), "KCHVM0086E": _("Virtual machine description must be a string"), + "KCHVM0087E": _("console parameter is only supported for s390x/s390 architecture."), + "KCHVM0088E": _("invalid console type, supported types are sclp/virtio."),
"KCHVMHDEV0001E": _("VM %(vmid)s does not contain directly assigned host device %(dev_name)s."), "KCHVMHDEV0002E": _("The host device %(dev_name)s is not allowed to directly assign to VM."), diff --git a/model/vms.py b/model/vms.py index b889166..5855a11 100644 --- a/model/vms.py +++ b/model/vms.py @@ -85,7 +85,7 @@ VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users'] # update parameters which are updatable when the VM is offline VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 'memory', 'name', 'users', 'bootorder', 'bootmenu', - 'description', 'title'] + 'description', 'title', 'console']
XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file" XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']" @@ -96,6 +96,7 @@ XPATH_DOMAIN_MEMORY = '/domain/memory' XPATH_DOMAIN_MEMORY_UNIT = '/domain/memory/@unit' XPATH_DOMAIN_UUID = '/domain/uuid' XPATH_DOMAIN_DEV_CPU_ID = '/domain/devices/spapr-cpu-socket/@id' +XPATH_DOMAIN_CONSOLE_TARGET = "/domain/devices/console/target/@type"
XPATH_BOOT = 'os/boot/@dev' XPATH_BOOTMENU = 'os/bootmenu/@enable' @@ -109,6 +110,7 @@ XPATH_TITLE = './title' XPATH_TOPOLOGY = './cpu/topology' XPATH_VCPU = './vcpu' XPATH_MAX_MEMORY = './maxMemory' +XPATH_CONSOLE_TARGET = "./devices/console/target"
# key: VM name; value: lock object vm_locks = {} @@ -263,6 +265,9 @@ class VMModel(object): return sockets and cores and threads
def update(self, name, params): + if platform.machine() not in ['s390x', 's390'] and\ + 'console' in params: + raise InvalidParameter('KCHVM0087E') lock = vm_locks.get(name) if lock is None: lock = threading.Lock() @@ -793,6 +798,19 @@ class VMModel(object): # update <os> return ET.tostring(et)
+ def _update_s390x_console(self, xml, params): + if xpath_get_text(xml, XPATH_DOMAIN_CONSOLE_TARGET): + # if console is defined, update console + return xml_item_update(xml, XPATH_CONSOLE_TARGET, + params.get('console'), 'type') + # if console is not defined earlier, add console + console = E.console(type="pty") + console.append(E.target(type=params.get('console'), port='0')) + et = ET.fromstring(xml) + devices = et.find('devices') + devices.append(console) + return ET.tostring(et) + def _static_vm_update(self, vm_name, dom, params): old_xml = new_xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE) params = copy.deepcopy(params) @@ -861,6 +879,9 @@ class VMModel(object): if "bootorder" or "bootmenu" in params: new_xml = self._update_bootorder(new_xml, params)
+ if platform.machine() in ['s390', 's390x'] and params.get('console'): + new_xml = self._update_s390x_console(new_xml, params) + snapshots_info = [] conn = self.conn.get() try: @@ -1303,29 +1324,35 @@ class VMModel(object): bootmenu = "yes" if "yes" in xpath_get_text(xml, XPATH_BOOTMENU) \ else "no"
- return {'name': name, - 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), - 'description': "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), - 'state': state, - 'stats': res, - 'uuid': dom.UUIDString(), - 'memory': {'current': memory, 'maxmemory': maxmemory}, - 'cpu_info': cpu_info, - 'screenshot': screenshot, - 'icon': icon, - # (type, listen, port, passwd, passwdValidTo) - 'graphics': {"type": graphics[0], - "listen": graphics[1], - "port": graphics_port, - "passwd": graphics[3], - "passwdValidTo": graphics[4]}, - 'users': users, - 'groups': groups, - 'access': 'full', - 'persistent': True if dom.isPersistent() else False, - 'bootorder': boot, - 'bootmenu': bootmenu - } + vm_info = {'name': name, + 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), + 'description': + "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), + 'state': state, + 'stats': res, + 'uuid': dom.UUIDString(), + 'memory': {'current': memory, 'maxmemory': maxmemory}, + 'cpu_info': cpu_info, + 'screenshot': screenshot, + 'icon': icon, + # (type, listen, port, passwd, passwdValidTo) + 'graphics': {"type": graphics[0], + "listen": graphics[1], + "port": graphics_port, + "passwd": graphics[3], + "passwdValidTo": graphics[4]}, + 'users': users, + 'groups': groups, + 'access': 'full', + 'persistent': True if dom.isPersistent() else False, + 'bootorder': boot, + 'bootmenu': bootmenu + } + if platform.machine() in ['s390', 's390x']: + vm_console = xpath_get_text(xml, XPATH_DOMAIN_CONSOLE_TARGET) + vm_info['console'] = vm_console[0] if vm_console else '' in case console is not set, do we need to have that key in vm_info as blank or we should not have the key itself. if running on s390x, we should have it as blank if no console attached to guest. + + return vm_info
def _vm_get_disk_paths(self, dom): xml = dom.XMLDesc(0) diff --git a/xmlutils/serial.py b/xmlutils/serial.py index c823ee6..f61eefa 100644 --- a/xmlutils/serial.py +++ b/xmlutils/serial.py @@ -38,6 +38,7 @@ def get_serial_xml(params): </console>
For s390x + target type can be sclp/virtio <console type='pty'> <target type='sclp' port='0'/> </console> @@ -50,8 +51,10 @@ def get_serial_xml(params): return ET.tostring(console, encoding='utf-8', pretty_print=True) # for s390x elif params["arch"] in ["s390x"]: + # if params doesn't have console parameter, use virtio as default + console_type = params.get('console', 'virtio') console = E.console(type="pty") - console.append(E.target(type="sclp", port='0')) + console.append(E.target(type=console_type, port='0')) return ET.tostring(console, encoding='utf-8', pretty_print=True) # for x else:
-- Regards, Suresh Babu Angadi

Reviewed by: Archana Singh <archus@linux.vnet.ibm.com> On 09/13/2016 02:00 PM, Suresh Babu Angadi wrote:
On 09/13/2016 01:46 PM, Archana Singh wrote:
Looks good, a minor comment.
On 09/13/2016 01:29 PM, sureshab@linux.vnet.ibm.com wrote:
From: Suresh Babu Angadi <sureshab@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' parameter as optional attribute for s390x which returns current console type attached to guest * made changes in model code to support update of 'console' attribute for guest when running on s390x * added appropriate error codes in i18n.py * added API.json changes to validate 'console' attribute * made changes in xml code generation, default value as 'virtio'
Signed-off-by: Suresh Babu Angadi <sureshab@in.ibm.com> --- API.json | 8 +++++- i18n.py | 2 ++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++++----------------- xmlutils/serial.py | 5 +++- 4 files changed, 64 insertions(+), 26 deletions(-)
diff --git a/API.json b/API.json index fe5579e..f0861a2 100644 --- a/API.json +++ b/API.json @@ -414,7 +414,13 @@ } }, "cpu_info": { "$ref": "#/kimchitype/cpu_info" }, - "memory": { "$ref": "#/kimchitype/memory" } + "memory": { "$ref": "#/kimchitype/memory" }, + "console": { + "description": "type of the console attached to the guest in s390x architecture", + "type": "string", + "pattern": "^sclp|virtio$", + "error": "KCHVM0088E" + } }, "additionalProperties": false }, diff --git a/i18n.py b/i18n.py index 1684dc4..c46caf4 100644 --- a/i18n.py +++ b/i18n.py @@ -137,6 +137,8 @@ messages = { "KCHVM0084E": _("Error occured while retrieving the Virt Viewer file for virtual machine %(name)s : %(err)s"), "KCHVM0085E": _("Virtual machine title must be a string"), "KCHVM0086E": _("Virtual machine description must be a string"), + "KCHVM0087E": _("console parameter is only supported for s390x/s390 architecture."), + "KCHVM0088E": _("invalid console type, supported types are sclp/virtio."),
"KCHVMHDEV0001E": _("VM %(vmid)s does not contain directly assigned host device %(dev_name)s."), "KCHVMHDEV0002E": _("The host device %(dev_name)s is not allowed to directly assign to VM."), diff --git a/model/vms.py b/model/vms.py index b889166..5855a11 100644 --- a/model/vms.py +++ b/model/vms.py @@ -85,7 +85,7 @@ VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users'] # update parameters which are updatable when the VM is offline VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 'memory', 'name', 'users', 'bootorder', 'bootmenu', - 'description', 'title'] + 'description', 'title', 'console']
XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file" XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']" @@ -96,6 +96,7 @@ XPATH_DOMAIN_MEMORY = '/domain/memory' XPATH_DOMAIN_MEMORY_UNIT = '/domain/memory/@unit' XPATH_DOMAIN_UUID = '/domain/uuid' XPATH_DOMAIN_DEV_CPU_ID = '/domain/devices/spapr-cpu-socket/@id' +XPATH_DOMAIN_CONSOLE_TARGET = "/domain/devices/console/target/@type"
XPATH_BOOT = 'os/boot/@dev' XPATH_BOOTMENU = 'os/bootmenu/@enable' @@ -109,6 +110,7 @@ XPATH_TITLE = './title' XPATH_TOPOLOGY = './cpu/topology' XPATH_VCPU = './vcpu' XPATH_MAX_MEMORY = './maxMemory' +XPATH_CONSOLE_TARGET = "./devices/console/target"
# key: VM name; value: lock object vm_locks = {} @@ -263,6 +265,9 @@ class VMModel(object): return sockets and cores and threads
def update(self, name, params): + if platform.machine() not in ['s390x', 's390'] and\ + 'console' in params: + raise InvalidParameter('KCHVM0087E') lock = vm_locks.get(name) if lock is None: lock = threading.Lock() @@ -793,6 +798,19 @@ class VMModel(object): # update <os> return ET.tostring(et)
+ def _update_s390x_console(self, xml, params): + if xpath_get_text(xml, XPATH_DOMAIN_CONSOLE_TARGET): + # if console is defined, update console + return xml_item_update(xml, XPATH_CONSOLE_TARGET, + params.get('console'), 'type') + # if console is not defined earlier, add console + console = E.console(type="pty") + console.append(E.target(type=params.get('console'), port='0')) + et = ET.fromstring(xml) + devices = et.find('devices') + devices.append(console) + return ET.tostring(et) + def _static_vm_update(self, vm_name, dom, params): old_xml = new_xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE) params = copy.deepcopy(params) @@ -861,6 +879,9 @@ class VMModel(object): if "bootorder" or "bootmenu" in params: new_xml = self._update_bootorder(new_xml, params)
+ if platform.machine() in ['s390', 's390x'] and params.get('console'): + new_xml = self._update_s390x_console(new_xml, params) + snapshots_info = [] conn = self.conn.get() try: @@ -1303,29 +1324,35 @@ class VMModel(object): bootmenu = "yes" if "yes" in xpath_get_text(xml, XPATH_BOOTMENU) \ else "no"
- return {'name': name, - 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), - 'description': "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), - 'state': state, - 'stats': res, - 'uuid': dom.UUIDString(), - 'memory': {'current': memory, 'maxmemory': maxmemory}, - 'cpu_info': cpu_info, - 'screenshot': screenshot, - 'icon': icon, - # (type, listen, port, passwd, passwdValidTo) - 'graphics': {"type": graphics[0], - "listen": graphics[1], - "port": graphics_port, - "passwd": graphics[3], - "passwdValidTo": graphics[4]}, - 'users': users, - 'groups': groups, - 'access': 'full', - 'persistent': True if dom.isPersistent() else False, - 'bootorder': boot, - 'bootmenu': bootmenu - } + vm_info = {'name': name, + 'title': "".join(xpath_get_text(xml, XPATH_TITLE)), + 'description': + "".join(xpath_get_text(xml, XPATH_DESCRIPTION)), + 'state': state, + 'stats': res, + 'uuid': dom.UUIDString(), + 'memory': {'current': memory, 'maxmemory': maxmemory}, + 'cpu_info': cpu_info, + 'screenshot': screenshot, + 'icon': icon, + # (type, listen, port, passwd, passwdValidTo) + 'graphics': {"type": graphics[0], + "listen": graphics[1], + "port": graphics_port, + "passwd": graphics[3], + "passwdValidTo": graphics[4]}, + 'users': users, + 'groups': groups, + 'access': 'full', + 'persistent': True if dom.isPersistent() else False, + 'bootorder': boot, + 'bootmenu': bootmenu + } + if platform.machine() in ['s390', 's390x']: + vm_console = xpath_get_text(xml, XPATH_DOMAIN_CONSOLE_TARGET) + vm_info['console'] = vm_console[0] if vm_console else '' in case console is not set, do we need to have that key in vm_info as blank or we should not have the key itself. if running on s390x, we should have it as blank if no console attached to guest. + + return vm_info
def _vm_get_disk_paths(self, dom): xml = dom.XMLDesc(0) diff --git a/xmlutils/serial.py b/xmlutils/serial.py index c823ee6..f61eefa 100644 --- a/xmlutils/serial.py +++ b/xmlutils/serial.py @@ -38,6 +38,7 @@ def get_serial_xml(params): </console>
For s390x + target type can be sclp/virtio <console type='pty'> <target type='sclp' port='0'/> </console> @@ -50,8 +51,10 @@ def get_serial_xml(params): return ET.tostring(console, encoding='utf-8', pretty_print=True) # for s390x elif params["arch"] in ["s390x"]: + # if params doesn't have console parameter, use virtio as default + console_type = params.get('console', 'virtio') console = E.console(type="pty") - console.append(E.target(type="sclp", port='0')) + console.append(E.target(type=console_type, port='0')) return ET.tostring(console, encoding='utf-8', pretty_print=True) # for x else:

Reviewed by: Archana Singh <archus@linux.vnet.ibm.com> On 09/13/2016 01:29 PM, sureshab@linux.vnet.ibm.com wrote:
From: Suresh Babu Angadi <sureshab@in.ibm.com>
v1-v2: provided detailed commit message and reduced number of patches
In case of s390x architecture, console type can be either virtio/sclp. Extended current code to support console configuration in case of s390x
this patch set provides option to configure 'console' parameter for templates and vms api when running on 's390x' architecture
Suresh Babu Angadi (2): added 'console' parameter to templates api for s390x added 'console' parameter to vms api for s390x
API.json | 24 ++++++++++++++--- control/templates.py | 1 + i18n.py | 4 +++ model/templates.py | 6 +++++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++----------------- osinfo.py | 4 +++ xmlutils/serial.py | 5 +++- 7 files changed, 91 insertions(+), 28 deletions(-)

Hi Suresh, I was not able to apply those patches on top of next branch. Could you rebase and resend, please? Regards, Aline Manera On 09/13/2016 04:59 AM, sureshab@linux.vnet.ibm.com wrote:
From: Suresh Babu Angadi <sureshab@in.ibm.com>
v1-v2: provided detailed commit message and reduced number of patches
In case of s390x architecture, console type can be either virtio/sclp. Extended current code to support console configuration in case of s390x
this patch set provides option to configure 'console' parameter for templates and vms api when running on 's390x' architecture
Suresh Babu Angadi (2): added 'console' parameter to templates api for s390x added 'console' parameter to vms api for s390x
API.json | 24 ++++++++++++++--- control/templates.py | 1 + i18n.py | 4 +++ model/templates.py | 6 +++++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++----------------- osinfo.py | 4 +++ xmlutils/serial.py | 5 +++- 7 files changed, 91 insertions(+), 28 deletions(-)

Hi Aline, I am able to apply both patches to next branch. * s d58c089 [origin/next] Introducing s390x UI Interfaces module for Edit Guest under virtualization remotes/origin/HEAD -> origin/master remotes/origin/gh-pages 33b97bc Aug 31 meeting remotes/origin/master 77ddaa6 remote iso listing for s390x remotes/origin/next d58c089 Introducing s390x UI Interfaces module for Edit Guest under virtualization [archana@archanasingh kimchi]$ sudo git am ~/Documents/f_drive/tmp-delete/\[Kimchi-devel\]\ \[PATCH\ v2\]\ \[Kimchi\ 1_2\]\ added\ \'console\'\ parameter\ to\ templates\ api\ for\ s390x.eml Applying: added 'console' parameter to templates api for s390x [archana@archanasingh kimchi]$ sudo git am ~/Documents/f_drive/tmp-delete/\[Kimchi-devel\]\ \[PATCH\ v2\]\ \[Kimchi\ 2_2\]\ added\ \'console\'\ parameter\ to\ vms\ api\ for\ s390x.eml Applying: added 'console' parameter to vms api for s390x Thanks, Archana On 09/15/2016 03:08 AM, Aline Manera wrote:
Hi Suresh,
I was not able to apply those patches on top of next branch.
Could you rebase and resend, please?
Regards, Aline Manera
On 09/13/2016 04:59 AM, sureshab@linux.vnet.ibm.com wrote:
From: Suresh Babu Angadi <sureshab@in.ibm.com>
v1-v2: provided detailed commit message and reduced number of patches
In case of s390x architecture, console type can be either virtio/sclp. Extended current code to support console configuration in case of s390x
this patch set provides option to configure 'console' parameter for templates and vms api when running on 's390x' architecture
Suresh Babu Angadi (2): added 'console' parameter to templates api for s390x added 'console' parameter to vms api for s390x
API.json | 24 ++++++++++++++--- control/templates.py | 1 + i18n.py | 4 +++ model/templates.py | 6 +++++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++----------------- osinfo.py | 4 +++ xmlutils/serial.py | 5 +++- 7 files changed, 91 insertions(+), 28 deletions(-)
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel

On 09/15/2016 08:42 AM, Archana Singh wrote:
Hi Aline,
I am able to apply both patches to next branch.
* s d58c089 [origin/next] Introducing s390x UI Interfaces module for Edit Guest under virtualization remotes/origin/HEAD -> origin/master remotes/origin/gh-pages 33b97bc Aug 31 meeting remotes/origin/master 77ddaa6 remote iso listing for s390x remotes/origin/next d58c089 Introducing s390x UI Interfaces module for Edit Guest under virtualization
[archana@archanasingh kimchi]$ sudo git am ~/Documents/f_drive/tmp-delete/\[Kimchi-devel\]\ \[PATCH\ v2\]\ \[Kimchi\ 1_2\]\ added\ \'console\'\ parameter\ to\ templates\ api\ for\ s390x.eml Applying: added 'console' parameter to templates api for s390x [archana@archanasingh kimchi]$ sudo git am ~/Documents/f_drive/tmp-delete/\[Kimchi-devel\]\ \[PATCH\ v2\]\ \[Kimchi\ 2_2\]\ added\ \'console\'\ parameter\ to\ vms\ api\ for\ s390x.eml Applying: added 'console' parameter to vms api for s390x
Thanks,
Archana
On 09/15/2016 03:08 AM, Aline Manera wrote:
Hi Suresh,
I was not able to apply those patches on top of next branch.
Could you rebase and resend, please?
Regards, Aline Manera Hello Aline and Archana, I have sent v3 patch as v2 doesn't apply on next branch because of conflict in i18n.py.
On 09/13/2016 04:59 AM, sureshab@linux.vnet.ibm.com wrote:
From: Suresh Babu Angadi <sureshab@in.ibm.com>
v1-v2: provided detailed commit message and reduced number of patches
In case of s390x architecture, console type can be either virtio/sclp. Extended current code to support console configuration in case of s390x
this patch set provides option to configure 'console' parameter for templates and vms api when running on 's390x' architecture
Suresh Babu Angadi (2): added 'console' parameter to templates api for s390x added 'console' parameter to vms api for s390x
API.json | 24 ++++++++++++++--- control/templates.py | 1 + i18n.py | 4 +++ model/templates.py | 6 +++++ model/vms.py | 75 +++++++++++++++++++++++++++++++++++----------------- osinfo.py | 4 +++ xmlutils/serial.py | 5 +++- 7 files changed, 91 insertions(+), 28 deletions(-)
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Regards, Suresh Babu Angadi
participants (4)
-
Aline Manera
-
Archana Singh
-
Suresh Babu Angadi
-
sureshab@linux.vnet.ibm.com