Move simpledb to db/anydbm just so we are using the new API.
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
parent
93726e0567
commit
ba17e5286b
|
@ -40,7 +40,7 @@ from heat.common import wsgi
|
|||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
conf = config.HeatConfigOpts()
|
||||
conf = config.HeatEngineConfigOpts()
|
||||
conf()
|
||||
|
||||
app = config.load_paste_app(conf)
|
||||
|
|
|
@ -47,13 +47,17 @@ class HeatConfigOpts(cfg.CommonConfigOpts):
|
|||
**kwargs)
|
||||
|
||||
|
||||
class HeatCacheConfigOpts(HeatConfigOpts):
|
||||
class HeatEngineConfigOpts(HeatConfigOpts):
|
||||
|
||||
db_opts = [
|
||||
cfg.StrOpt('db_backend', default='heat.db.anydbm.api', help='The backend to use for db'),
|
||||
]
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
config_files = cfg.find_config_files(project='heat',
|
||||
prog='heat-cache')
|
||||
super(HeatCacheConfigOpts, self).__init__(config_files, **kwargs)
|
||||
|
||||
prog='heat-engine')
|
||||
super(HeatEngineConfigOpts, self).__init__(config_files, **kwargs)
|
||||
self.register_cli_opts(self.db_opts)
|
||||
|
||||
def setup_logging(conf):
|
||||
"""
|
||||
|
|
|
@ -25,6 +25,55 @@ import uuid
|
|||
|
||||
from heat.common import exception
|
||||
|
||||
def import_class(import_str):
|
||||
"""Returns a class from a string including module and class."""
|
||||
mod_str, _sep, class_str = import_str.rpartition('.')
|
||||
try:
|
||||
__import__(mod_str)
|
||||
return getattr(sys.modules[mod_str], class_str)
|
||||
except (ImportError, ValueError, AttributeError), exc:
|
||||
#LOG.debug(_('Inner Exception: %s'), exc)
|
||||
raise exception.ClassNotFound(class_name=class_str, exception=exc)
|
||||
|
||||
|
||||
def import_object(import_str):
|
||||
"""Returns an object including a module or module and class."""
|
||||
try:
|
||||
__import__(import_str)
|
||||
return sys.modules[import_str]
|
||||
except ImportError:
|
||||
cls = import_class(import_str)
|
||||
return cls()
|
||||
|
||||
class LazyPluggable(object):
|
||||
"""A pluggable backend loaded lazily based on some value."""
|
||||
|
||||
def __init__(self, pivot, **backends):
|
||||
self.__backends = backends
|
||||
self.__pivot = pivot
|
||||
self.__backend = None
|
||||
|
||||
def __get_backend(self):
|
||||
if not self.__backend:
|
||||
backend_name = FLAGS[self.__pivot]
|
||||
if backend_name not in self.__backends:
|
||||
raise exception.Error(_('Invalid backend: %s') % backend_name)
|
||||
|
||||
backend = self.__backends[backend_name]
|
||||
if isinstance(backend, tuple):
|
||||
name = backend[0]
|
||||
fromlist = backend[1]
|
||||
else:
|
||||
name = backend
|
||||
fromlist = backend
|
||||
|
||||
self.__backend = __import__(name, None, None, fromlist)
|
||||
#LOG.debug(_('backend %s'), self.__backend)
|
||||
return self.__backend
|
||||
|
||||
def __getattr__(self, key):
|
||||
backend = self.__get_backend()
|
||||
return getattr(backend, key)
|
||||
|
||||
def chunkreadable(iter, chunk_size=65536):
|
||||
"""
|
||||
|
|
|
@ -16,7 +16,57 @@
|
|||
import anydbm
|
||||
import json
|
||||
|
||||
def event_append(event):
|
||||
def raw_template_get(context, template_id):
|
||||
return 'test return value'
|
||||
|
||||
def raw_template_get_all(context):
|
||||
pass
|
||||
|
||||
def raw_template_create(context, values):
|
||||
pass
|
||||
|
||||
|
||||
def parsed_template_get(context, template_id):
|
||||
pass
|
||||
|
||||
def parsed_template_get_all(context):
|
||||
pass
|
||||
|
||||
def parsed_template_create(context, values):
|
||||
pass
|
||||
|
||||
|
||||
def state_get(context, state_id):
|
||||
pass
|
||||
|
||||
def state_get_all(context):
|
||||
pass
|
||||
|
||||
def state_create(context, values):
|
||||
pass
|
||||
|
||||
|
||||
def event_get(context, event_id):
|
||||
pass
|
||||
|
||||
def event_get_all(context):
|
||||
pass
|
||||
|
||||
def event_get_all_by_stack(context, stack_id):
|
||||
events = {'events': []}
|
||||
try:
|
||||
d = anydbm.open('/var/lib/heat/%s.events.db' % stack_id, 'r')
|
||||
except:
|
||||
return events
|
||||
|
||||
for k, v in d.iteritems():
|
||||
if k != 'lastid':
|
||||
events['events'].append(json.loads(v))
|
||||
|
||||
d.close()
|
||||
return events
|
||||
|
||||
def event_create(context, event):
|
||||
'''
|
||||
EventId The unique ID of this event.
|
||||
Timestamp Time the status was updated.
|
||||
|
@ -33,18 +83,3 @@ def event_append(event):
|
|||
|
||||
d.close()
|
||||
|
||||
|
||||
def events_get(stack_id):
|
||||
events = {'events': []}
|
||||
try:
|
||||
d = anydbm.open('/var/lib/heat/%s.events.db' % stack_id, 'r')
|
||||
except:
|
||||
return events
|
||||
|
||||
for k, v in d.iteritems():
|
||||
if k != 'lastid':
|
||||
events['events'].append(json.loads(v))
|
||||
|
||||
d.close()
|
||||
return events
|
||||
|
|
@ -26,20 +26,12 @@ The underlying driver is loaded as a :class:`LazyPluggable`. SQLAlchemy is
|
|||
currently the only supported backend.
|
||||
'''
|
||||
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
db_opts = [
|
||||
cfg.StrOpt('db_backend', default='db', help='The backend to use for db'),
|
||||
]
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
FLAGS.register_opts(db_opts)
|
||||
|
||||
IMPL = utils.LazyPluggable('db_backend', db='heat.db.sqlalchemy.api')
|
||||
from heat.openstack.common import cfg
|
||||
from heat.common import utils
|
||||
|
||||
def configure(conf):
|
||||
global IMPL
|
||||
IMPL = utils.import_object(conf.db_backend)
|
||||
|
||||
def raw_template_get(context, template_id):
|
||||
return IMPL.raw_template_get(context, template_id)
|
||||
|
|
|
@ -28,7 +28,7 @@ from heat.common import exception
|
|||
from heat.common import wsgi
|
||||
|
||||
from heat.engine import parser
|
||||
from heat.engine import simpledb
|
||||
from heat.db import api as db_api
|
||||
|
||||
logger = logging.getLogger('heat.engine.api.v1.events')
|
||||
|
||||
|
@ -43,7 +43,7 @@ class EventsController(object):
|
|||
self.conf = conf
|
||||
|
||||
def index(self, req, stack_id):
|
||||
return simpledb.events_get(stack_id)
|
||||
return db_api.event_get_all_by_stack(None, stack_id)
|
||||
|
||||
def create_resource(conf):
|
||||
"""Events resource factory method."""
|
||||
|
|
|
@ -28,6 +28,7 @@ from heat.common import exception
|
|||
from heat.common import wsgi
|
||||
|
||||
from heat.engine import parser
|
||||
from heat.db import api as db_api
|
||||
|
||||
|
||||
logger = logging.getLogger('heat.engine.api.v1.stacks')
|
||||
|
@ -41,6 +42,7 @@ class StacksController(object):
|
|||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
db_api.configure(conf)
|
||||
|
||||
def index(self, req, format='json'):
|
||||
logger.info('format is %s' % format)
|
||||
|
|
|
@ -18,7 +18,7 @@ import os
|
|||
import time
|
||||
from novaclient.v1_1 import client
|
||||
|
||||
from heat.engine import simpledb
|
||||
from heat.db import api as db_api
|
||||
|
||||
logger = logging.getLogger('heat.engine.resources')
|
||||
|
||||
|
@ -72,7 +72,7 @@ class Resource(object):
|
|||
ev['ResourceType'] = self.t['Type']
|
||||
ev['ResourceProperties'] = self.t['Properties']
|
||||
|
||||
simpledb.event_append(ev)
|
||||
db_api.event_create(None, ev)
|
||||
self.state = new_state
|
||||
|
||||
def stop(self):
|
||||
|
|
Loading…
Reference in New Issue