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

From: Suresh Babu Angadi <sureshab@in.ibm.com> v2-v3: resolved merge conflict 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..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

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 0456476..7dcf435 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 177bd50..89a23af 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 6a9b1d1..2b216cb 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
participants (2)
-
Aline Manera
-
sureshab@linux.vnet.ibm.com