Make backends into drivers, loadable as entry points
Added base.py, which has classes for backends to derive from. This is the stevedore suggested way of writing drivers. stevedore.readthedocs.org/en/latest/tutorial/creating_plugins.html Added entrypoints to setup.cfg implements blueprint backend-abstraction Change-Id: Ib53bd1ec930f15480e33b9105033e9999f96b842
This commit is contained in:
parent
29cf50152b
commit
3499d899c8
|
@ -0,0 +1,39 @@
|
||||||
|
# Copyright (C) 2013 Yahoo! Inc. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import abc
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
|
class Backend(object):
|
||||||
|
"""Base class for persistence backends."""
|
||||||
|
|
||||||
|
def __init__(self, conf):
|
||||||
|
if not conf:
|
||||||
|
conf = {}
|
||||||
|
if not isinstance(conf, dict):
|
||||||
|
raise TypeError("Configuration dictionary expected not: %s"
|
||||||
|
% type(conf))
|
||||||
|
self._conf = conf
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def open(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def close(self):
|
||||||
|
"""Closes any resources this backend has open."""
|
||||||
|
pass
|
|
@ -11,3 +11,13 @@
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import os
|
||||||
|
|
||||||
|
from entropy.backends import base
|
||||||
|
|
||||||
|
|
||||||
|
class FileBackend(base.Backend):
|
||||||
|
"""A directory based backend."""
|
||||||
|
def __init__(self, conf):
|
||||||
|
super(FileBackend, self).__init(conf)
|
||||||
|
self.path = os.path.abspath(conf['path'])
|
||||||
|
|
|
@ -6,7 +6,7 @@ description-file =
|
||||||
README.md
|
README.md
|
||||||
author = Entropy devs
|
author = Entropy devs
|
||||||
author-email = praneshpg@gmail.com
|
author-email = praneshpg@gmail.com
|
||||||
home-page = http://entropy.readthedocs.org/
|
home-page = https://wiki.openstack.org/wiki/Entropy
|
||||||
classifier =
|
classifier =
|
||||||
Development Status :: 4 - Beta
|
Development Status :: 4 - Beta
|
||||||
Environment :: Console
|
Environment :: Console
|
||||||
|
@ -26,6 +26,10 @@ classifier =
|
||||||
console_scripts =
|
console_scripts =
|
||||||
entropy = entropy.__main__:main
|
entropy = entropy.__main__:main
|
||||||
|
|
||||||
|
entropy.backend =
|
||||||
|
file = entropy.backends.file_backend:FileBackend
|
||||||
|
db = entropy.backends.file_backend:DbBackend
|
||||||
|
|
||||||
[global]
|
[global]
|
||||||
setup-hooks =
|
setup-hooks =
|
||||||
pbr.hooks.setup_hook
|
pbr.hooks.setup_hook
|
||||||
|
|
Loading…
Reference in New Issue