[Kimchi-devel] [PATCH 2/4] Upgrade to Kimchi 2.0: Script to update objectstore content.

pvital at linux.vnet.ibm.com pvital at linux.vnet.ibm.com
Mon Oct 26 19:16:27 UTC 2015


From: Paulo Vital <pvital at linux.vnet.ibm.com>

With the new structure of Wok and Kimchi, the content of the objectstore file
needs to be updated to reflect the new paths of icon and storagepool present
in template's and VM's information.

This patch adds a script to execute an update of these contents in the
objectstore file during an upgrade from Kimchi 1.5.1 (or previous versions)
to the new Wok and Kimchi 2.0 (or earlier) RPM's.

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 src/wok/plugins/kimchi/Makefile.am                 |  3 +-
 .../plugins/kimchi/contrib/update_objectstore.py   | 64 ++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 src/wok/plugins/kimchi/contrib/update_objectstore.py

diff --git a/src/wok/plugins/kimchi/Makefile.am b/src/wok/plugins/kimchi/Makefile.am
index 8a55b23..cd49c10 100644
--- a/src/wok/plugins/kimchi/Makefile.am
+++ b/src/wok/plugins/kimchi/Makefile.am
@@ -49,10 +49,11 @@ EXTRA_DIST = \
 	VERSION \
 	build-aux/pkg-version \
 	config.py.in \
+	contrib/update_objectstore.py \
 	$(NULL)
 
 
-PEP8_BLACKLIST = *config.py,*i18n.py,*tests/test_config.py
+PEP8_BLACKLIST = *config.py,*i18n.py,*tests/test_config.py,*update_object*.py
 
 I18N_FILES = ./i18n.py \
 	$(NULL)
diff --git a/src/wok/plugins/kimchi/contrib/update_objectstore.py b/src/wok/plugins/kimchi/contrib/update_objectstore.py
new file mode 100644
index 0000000..3d8ec3c
--- /dev/null
+++ b/src/wok/plugins/kimchi/contrib/update_objectstore.py
@@ -0,0 +1,64 @@
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2015
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+import json
+import logging
+import sqlite3
+import sys
+
+from wok.plugins.kimchi import config
+
+
+logging.basicConfig(filename='/var/log/wok/kimchi-upgrade.log',
+                    format='%(levelname)s:%(asctime)s: %(message)s',
+                    datefmt='%Y-%m-%d %H:%M:%S %Z',
+                    level=logging.DEBUG)
+
+def upgrade_paths(item, old_uri, new_uri):
+    total = 0
+    try:
+        conn = sqlite3.connect(config.get_object_store(), timeout=10)
+        cursor = conn.cursor()
+
+        sql = "SELECT id, json FROM objects WHERE type='template' OR type='vm';"
+        cursor.execute(sql)
+        for row in cursor.fetchall():
+            # execute update here
+            template = json.loads(row[1])
+            path = (template[item] if item in template else 'none')
+            if path.startswith(old_uri):
+                path = new_uri + path
+                template[item] = path
+                sql = "UPDATE objects SET json=? WHERE id=?"
+                cursor.execute(sql, (json.dumps(template),row[0]))
+                conn.commit()
+                total += 1
+    except sqlite3.Error, e:
+        if conn:
+            conn.rollback()
+        logging.error("Error %s:", e.args[0])
+        sys.exit(1)
+    finally:
+        if conn:
+            conn.close()
+        logging.info("%d '%s' entries upgraded.", total, item)
+
+
+logging.info("Upgrading Kimchi objectstore to version 2.0.0 ...")
+upgrade_paths('icon', 'images', 'plugins/kimchi/')
+upgrade_paths('storagepool', '/storagepools', '/plugins/kimchi')
-- 
2.4.3




More information about the Kimchi-devel mailing list