
From: Aline Manera <alinefm@br.ibm.com> The model implementation for config and its sub-resources were added to model_/config.py It is needed to create a temporary module named model_ as there is already a model.py in Kimchi code. It will be rename later when removing model.py Signed-off-by: Aline Manera <alinefm@br.ibm.com> --- src/kimchi/basemodel.py | 8 ++++ src/kimchi/model_/config.py | 87 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 src/kimchi/model_/config.py diff --git a/src/kimchi/basemodel.py b/src/kimchi/basemodel.py index 285e86d..0058dc2 100644 --- a/src/kimchi/basemodel.py +++ b/src/kimchi/basemodel.py @@ -45,3 +45,11 @@ class BaseModel(object): for member_name in callables: m = getattr(model_instance, member_name, None) setattr(self, '%s_%s' % (method_prefix, member_name), m) + + +class Singleton(type): + _instances = {} + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) + return cls._instances[cls] diff --git a/src/kimchi/model_/config.py b/src/kimchi/model_/config.py new file mode 100644 index 0000000..933e37f --- /dev/null +++ b/src/kimchi/model_/config.py @@ -0,0 +1,87 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2013 +# +# Authors: +# Aline Manera <alinefm@linux.vnet.ibm.com> +# +# 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 cherrypy + +from kimchi.basemodel import Singleton +from kimchi.distroloader import DistroLoader +from kimchi.exception import NotFoundError +from kimchi.featuretests import FeatureTests +from kimchi.model_.debugreports import DebugReportsModel +from kimchi.screenshot import VMScreenshot +from kimchi.utils import kimchi_log + + +class CapabilitiesModel(object): + __metaclass__ = Singleton + + def __init__(self, **kargs): + self.qemu_stream = False + self.qemu_stream_dns = False + self.libvirt_stream_protocols = [] + + # Subscribe function to set host capabilities to be run when cherrypy + # server is up + # It is needed because some features tests depends on the server + cherrypy.engine.subscribe('start', self._set_capabilities) + + def _set_capabilities(self): + kimchi_log.info("*** Running feature tests ***") + self.qemu_stream = FeatureTests.qemu_supports_iso_stream() + self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns() + self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe() + + self.libvirt_stream_protocols = [] + for p in ['http', 'https', 'ftp', 'ftps', 'tftp']: + if FeatureTests.libvirt_supports_iso_stream(p): + self.libvirt_stream_protocols.append(p) + + kimchi_log.info("*** Feature tests completed ***") + _set_capabilities.priority = 90 + + def lookup(self, *ident): + report_tool = DebugReportsModel.get_system_report_tool() + + return {'libvirt_stream_protocols': self.libvirt_stream_protocols, + 'qemu_stream': self.qemu_stream, + 'screenshot': VMScreenshot.get_stream_test_result(), + 'system_report_tool': bool(report_tool)} + + +class DistrosModel(object): + def __init__(self, **kargs): + distroloader = DistroLoader() + self.distros = distroloader.get() + + def get_list(self): + return self.distros.keys() + + +class DistroModel(object): + def __init__(self, **kargs): + self._distros = DistrosModel() + + def lookup(self, name): + try: + return self._distros.distros[name] + except KeyError: + raise NotFoundError("Distro '%s' not found." % name) -- 1.7.10.4