diff --git a/example.py b/example.py index a5326b84..a40f4f89 100644 --- a/example.py +++ b/example.py @@ -168,9 +168,6 @@ def deploy(): signals.connect(keystone_config1, glance_api_endpoint, {'admin_token': 'admin_token'}) signals.connect(keystone_service1, glance_api_endpoint, {'ip': 'keystone_host', 'admin_port': 'keystone_port'}) - if hasattr(db, 'flush'): - db.flush() - signals.Connections.flush() diff --git a/solar/solar/core/signals.py b/solar/solar/core/signals.py index ddc08fb2..a51486e6 100644 --- a/solar/solar/core/signals.py +++ b/solar/solar/core/signals.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import atexit from collections import defaultdict import itertools import networkx as nx @@ -67,9 +68,13 @@ class Connections(object): @staticmethod def flush(): + print 'FLUSHING Connections' utils.save_to_config_file(CLIENTS_CONFIG_KEY, CLIENTS) +atexit.register(Connections.flush) + + def guess_mapping(emitter, receiver): """Guess connection mapping between emitter and receiver. diff --git a/solar/solar/interfaces/db/cached_file_system_db.py b/solar/solar/interfaces/db/cached_file_system_db.py index 14a77bec..d5b8b06c 100644 --- a/solar/solar/interfaces/db/cached_file_system_db.py +++ b/solar/solar/interfaces/db/cached_file_system_db.py @@ -1,5 +1,6 @@ from solar.third_party.dir_dbm import DirDBM +import atexit import os import types import yaml @@ -19,6 +20,8 @@ class CachedFileSystemDB(DirDBM): super(CachedFileSystemDB, self).__init__(self.STORAGE_PATH) self.entities = {} + atexit.register(self.flush) + def __setitem__(self, k, v): """ C{dirdbm[k] = v} @@ -102,5 +105,6 @@ class CachedFileSystemDB(DirDBM): return key def flush(self): + print 'FLUSHING DB' for path, data in self._CACHE.items(): super(CachedFileSystemDB, self)._writeFile(path, yaml.dump(data))