[Kimchi-devel] [PATCH] [Kimchi 3/4] Bug fix #1091: Allow to set disk performance options per guest and template

Ramon Medeiros posted 4 patches 7 years ago
[Kimchi-devel] [PATCH] [Kimchi 3/4] Bug fix #1091: Allow to set disk performance options per guest and template
Posted by Ramon Medeiros 7 years ago
Allow templates to set and update io, cache and bus of the disks.

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com>
---
 API.json            | 15 +++++++++++++++
 docs/API.md         |  3 +++
 model/vmstorages.py |  4 +++-
 vmtemplate.py       | 19 ++++++++++++++++++-
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/API.json b/API.json
index abe980c..bae9c9c 100644
--- a/API.json
+++ b/API.json
@@ -658,6 +658,21 @@
                                         "error": "KCHTMPL0015E"
                                     }
                                 }
+                            },
+                            "cache": {
+                                "description": "Cache options",
+                                "type": "string",
+                                "pattern": "^(none|writethrough|writeback|directsync|unsafe|default)$"
+                            },
+                            "io": {
+                                "description": "I/O options",
+                                "type": "string",
+                                "pattern": "^(native|threads|default)$"
+                            },
+                            "bus": {
+                                "description": "Bus disk",
+                                "type": "string",
+                                "pattern": "^(scsi|virtio|ide)$"
                             }
                         }
                     },
diff --git a/docs/API.md b/docs/API.md
index 1aa7308..2312002 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -344,6 +344,9 @@ Represents a snapshot of the Virtual Machine's primary monitor.
         * format: Format of the image. Valid formats: qcow, qcow2, qed, raw, vmdk, vpc
         * pool: Storage pool information
             * name: URI of the storagepool where disk will be created
+        * io: Set io flag
+        * cache: Set cache flag
+        * bus: Set bus flag
     * graphics *(optional)*: The graphics paramenters of this template
         * type: The type of graphics. It can be VNC or spice or None.
             * vnc: Graphical display using the Virtual Network
diff --git a/model/vmstorages.py b/model/vmstorages.py
index 007e88c..bf55300 100644
--- a/model/vmstorages.py
+++ b/model/vmstorages.py
@@ -91,7 +91,9 @@ class VMStoragesModel(object):
                 raise InvalidParameter("KCHVMSTOR0019E")
 
         dom = VMModel.get_vm(vm_name, self.conn)
-        params['bus'] = _get_device_bus(params['type'], dom)
+
+        if params.get('bus') is None:
+            params['bus'] = _get_device_bus(params['type'], dom)
 
         if is_s390x() and params['type'] == 'disk' and 'dir_path' in params:
             if 'format' not in params:
diff --git a/vmtemplate.py b/vmtemplate.py
index 1acd4db..3f37d1a 100644
--- a/vmtemplate.py
+++ b/vmtemplate.py
@@ -1,7 +1,7 @@
 #
 # Project Kimchi
 #
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -144,6 +144,12 @@ class VMTemplate(object):
 
                 keys = sorted(disk_info.keys())
 
+                # remove optional parameters
+                optional = ["bus", "io", "cache"]
+                for opt in optional:
+                    if opt in keys:
+                        keys.remove(opt)
+
                 if ((keys != sorted(basic_disk)) and
                         (keys != sorted(ro_disk)) and
                         (keys != sorted(base_disk))):
@@ -253,6 +259,7 @@ class VMTemplate(object):
         return xml
 
     def _get_disks_xml(self, vm_uuid):
+        optional = ["io", "cache"]
         base_disk_params = {'type': 'disk', 'disk': 'file',
                             'bus': self.info['disk_bus']}
         logical_disk_params = {'format': 'raw'}
@@ -267,6 +274,16 @@ class VMTemplate(object):
             params = dict(base_disk_params)
             params['format'] = disk['format']
             params['index'] = index
+
+            # bus passed: overwrite
+            if disk.get("bus") is not None:
+                params["bus"] = disk.get("bus")
+
+            # add optionals
+            for opt in optional:
+                if disk.get(opt) is not None:
+                    params[opt] = disk[opt]
+
             if disk.get('pool'):
                 params.update(locals().get('%s_disk_params' %
                                            disk['pool']['type'], {}))
-- 
2.9.3

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel