[Kimchi-devel] [PATCH 3/3] Verify storage pool set as Template default prior to server starts up
Aline Manera
alinefm at linux.vnet.ibm.com
Mon May 4 15:24:06 UTC 2015
The verification was being done in model/model.py but as it is only related to
storage pools, it was added to model/storagepools.py
This patch also adds a new option 'create_iso_pool' to kimchid, so the user can
choose to create or not the ISO pool during server starts up.
Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
src/kimchi/model/model.py | 44 +--------------------------
src/kimchi/model/storagepools.py | 66 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 43 deletions(-)
diff --git a/src/kimchi/model/model.py b/src/kimchi/model/model.py
index 566be66..40ebc98 100644
--- a/src/kimchi/model/model.py
+++ b/src/kimchi/model/model.py
@@ -1,7 +1,7 @@
#
# Project Kimchi
#
-# Copyright IBM, Corp. 2014
+# Copyright IBM, Corp. 2014-2015
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,14 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import inspect
-import logging
import os
-import sys
-
-import cherrypy
-import libvirt
-import lxml.etree as ET
-from lxml.builder import E
from kimchi.basemodel import BaseModel
from kimchi.model.libvirtconnection import LibvirtConnection
@@ -33,10 +26,6 @@ from kimchi.objectstore import ObjectStore
from kimchi.utils import import_module, listPathModules
-DEFAULT_POOLS = {'default': {'path': '/var/lib/libvirt/images'},
- 'ISO': {'path': '/var/lib/kimchi/isos'}}
-
-
class Model(BaseModel):
def __init__(self, libvirt_uri=None, objstore_loc=None):
@@ -44,10 +33,6 @@ class Model(BaseModel):
self.conn = LibvirtConnection(libvirt_uri)
kargs = {'objstore': self.objstore, 'conn': self.conn}
- if self.conn.isQemuURI():
- for pool_name, pool_arg in DEFAULT_POOLS.iteritems():
- self._default_pool_check(pool_name, pool_arg)
-
this = os.path.basename(__file__)
this_mod = os.path.splitext(this)[0]
@@ -64,30 +49,3 @@ class Model(BaseModel):
models.append(instance(**kargs))
return super(Model, self).__init__(models)
-
- def _default_pool_check(self, pool_name, pool_arg):
- conn = self.conn.get()
- pool = E.pool(E.name(pool_name), type='dir')
- pool.append(E.target(E.path(pool_arg['path'])))
- xml = ET.tostring(pool)
- try:
- pool = conn.storagePoolLookupByName(pool_name)
- except libvirt.libvirtError:
- try:
- pool = conn.storagePoolDefineXML(xml, 0)
- # Add build step to make sure target directory created
- pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW)
- pool.setAutostart(1)
- except libvirt.libvirtError, e:
- cherrypy.log.error("Fatal: Cannot create default pool because "
- "of %s, exit kimchid" % e.message,
- severity=logging.ERROR)
- sys.exit(1)
-
- if pool.isActive() == 0:
- try:
- pool.create(0)
- except libvirt.libvirtError, e:
- err = "Fatal: Default pool cannot be activated, exit kimchid"
- cherrypy.log.error(err, severity=logging.ERROR)
- sys.exit(1)
diff --git a/src/kimchi/model/storagepools.py b/src/kimchi/model/storagepools.py
index b85f3b4..0618314 100644
--- a/src/kimchi/model/storagepools.py
+++ b/src/kimchi/model/storagepools.py
@@ -18,18 +18,28 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import libvirt
+import lxml.etree as ET
+import sys
+from lxml.builder import E
+
+from kimchi.config import config
from kimchi.scan import Scanner
from kimchi.exception import InvalidOperation, MissingParameter
from kimchi.exception import NotFoundError, OperationFailed
from kimchi.model.config import CapabilitiesModel
from kimchi.model.host import DeviceModel
from kimchi.model.libvirtstoragepool import StoragePoolDef
+from kimchi.osinfo import defaults as tmpl_defaults
from kimchi.utils import add_task, kimchi_log, pool_name_from_uri, run_command
from kimchi.xmlutils.utils import xpath_get_text
+DEFAULT_POOLS = {'default': {'path': '/var/lib/libvirt/images'},
+ 'ISO': {'path': '/var/lib/kimchi/isos'}}
+
ISO_POOL_NAME = u'kimchi_isos'
+
POOL_STATE_MAP = {0: 'inactive',
1: 'initializing',
2: 'active',
@@ -57,6 +67,62 @@ class StoragePoolsModel(object):
self.caps = CapabilitiesModel(**kargs)
self.device = DeviceModel(**kargs)
+ if self.conn.isQemuURI():
+ self._check_default_pools()
+
+ def _check_default_pools(self):
+ default_pool = tmpl_defaults['storagepool']
+ default_pool = default_pool.split('/')[2]
+
+ if default_pool != 'default':
+ del DEFAULT_POOLS['default']
+ DEFAULT_POOLS[default_pool] = {}
+
+ if config.get("server", "create_iso_pool") != "true":
+ del DEFAULT_POOLS['ISO']
+
+ error_msg = ("Please, check the configuration in "
+ "/etc/kimchi/template.conf to ensure it has a valid "
+ "storage pool.")
+
+ conn = self.conn.get()
+ for pool_name in DEFAULT_POOLS:
+ try:
+ pool = conn.storagePoolLookupByName(pool_name)
+ except libvirt.libvirtError, e:
+ pool_path = DEFAULT_POOLS[pool_name].get('path')
+ if pool_path is None:
+ msg = "Fatal: Unable to find storage pool %s. " + error_msg
+ kimchi_log.error(msg % pool_name)
+ kimchi_log.error("Details: %s", e.message)
+ sys.exit(1)
+
+ # Try to create the pool
+ pool = E.pool(E.name(pool_name), type='dir')
+ pool.append(E.target(E.path(pool_path)))
+ xml = ET.tostring(pool)
+ try:
+ pool = conn.storagePoolDefineXML(xml, 0)
+ # Add build step to make sure target directory created
+ pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW)
+ pool.setAutostart(1)
+ except libvirt.libvirtError, e:
+ msg = "Fatal: Unable to create storage pool %s. "
+ msg += error_msg
+ kimchi_log.error(msg % pool_name)
+ kimchi_log.error("Details: %s", e.message)
+ sys.exit(1)
+
+ if pool.isActive() == 0:
+ try:
+ pool.create(0)
+ except libvirt.libvirtError, e:
+ msg = "Fatal: Unable to craete storage pool %s. "
+ msg += error_msg
+ kimchi_log.error(msg % pool_name)
+ kimchi_log.error("Details: %s", e.message)
+ sys.exit(1)
+
def get_list(self):
try:
conn = self.conn.get()
--
2.1.0
More information about the Kimchi-devel
mailing list