
From: Aline Manera <alinefm@br.ibm.com> To avoid duplicating code in model and mockmodel, the common code related to task resource was added to model_/tasks.py and the specific code for each backend (libvirt or mock) was added to model_/libvirtbackend.py and model_/mockbackend.py The model_ module is a temporary one, as there already is a module named model in source code. When start using the new code, model_ will be renamed to model and the former model.py deleted. Signed-off-by: Aline Manera <alinefm@br.ibm.com> --- src/kimchi/model_/__init__.py | 21 ++++++++++++++++ src/kimchi/model_/libvirtbackend.py | 28 ++++++++++++++++++++++ src/kimchi/model_/mockbackend.py | 28 ++++++++++++++++++++++ src/kimchi/model_/tasks.py | 45 +++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 src/kimchi/model_/__init__.py create mode 100644 src/kimchi/model_/libvirtbackend.py create mode 100644 src/kimchi/model_/mockbackend.py create mode 100644 src/kimchi/model_/tasks.py diff --git a/src/kimchi/model_/__init__.py b/src/kimchi/model_/__init__.py new file mode 100644 index 0000000..8a37cc4 --- /dev/null +++ b/src/kimchi/model_/__init__.py @@ -0,0 +1,21 @@ +# +# 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 diff --git a/src/kimchi/model_/libvirtbackend.py b/src/kimchi/model_/libvirtbackend.py new file mode 100644 index 0000000..0c70116 --- /dev/null +++ b/src/kimchi/model_/libvirtbackend.py @@ -0,0 +1,28 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2013 +# +# Authors: +# Adam Litke <agl@linux.vnet.ibm.com> +# 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 + +from kimchi.objectstore import ObjectStore + +class LibvirtBackend(object): + def __init__(self, objstore_loc=None): + self.objstore = ObjectStore(objstore_loc) diff --git a/src/kimchi/model_/mockbackend.py b/src/kimchi/model_/mockbackend.py new file mode 100644 index 0000000..e3c6ab9 --- /dev/null +++ b/src/kimchi/model_/mockbackend.py @@ -0,0 +1,28 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2013 +# +# Authors: +# Adam Litke <agl@linux.vnet.ibm.com> +# 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 + +from kimchi.objectstore import ObjectStore + +class MockBackend(object): + def __init__(self, objstore_loc=None): + self.objstore = ObjectStore(objstore_loc) diff --git a/src/kimchi/model_/tasks.py b/src/kimchi/model_/tasks.py new file mode 100644 index 0000000..29eaddf --- /dev/null +++ b/src/kimchi/model_/tasks.py @@ -0,0 +1,45 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2013 +# +# Authors: +# Adam Litke <agl@linux.vnet.ibm.com> +# 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 + +from kimchi.exception import NotFoundError + +ERROR_TASK_NOT_FOUND = "Task id '%s' not found." + +class Tasks(object): + def __init__(self, backend): + self.objstore = backend.objstore + + def get_list(self): + with self.objstore as session: + return session.get_list('task') + +class Task(object): + def __init__(self, backend): + self.objstore = backend.objstore + + def lookup(self, ident): + if ident not in self.get_list(): + raise NotFoundError(ERROR_TASK_NOT_FOUND % ident) + + with self.objstore as session: + return session.get('task', str(ident)) -- 1.7.10.4