diff options
Diffstat (limited to 'cloudinit/handlers/__init__.py')
-rw-r--r-- | cloudinit/handlers/__init__.py | 60 |
1 files changed, 9 insertions, 51 deletions
diff --git a/cloudinit/handlers/__init__.py b/cloudinit/handlers/__init__.py index a16bdde6..3b0cdd4e 100644 --- a/cloudinit/handlers/__init__.py +++ b/cloudinit/handlers/__init__.py @@ -19,65 +19,23 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import yaml -import cloudinit -import cloudinit.util as util -import sys -import traceback import os import subprocess +import sys import time +import traceback -per_instance = cloudinit.per_instance -per_always = cloudinit.per_always -per_once = cloudinit.per_once - - -class CloudConfig(): - cfgfile = None - cfg = None - - def __init__(self, cfgfile, cloud=None, ds_deps=None): - if cloud == None: - self.cloud = cloudinit.CloudInit(ds_deps) - self.cloud.get_data_source() - else: - self.cloud = cloud - self.cfg = self.get_config_obj(cfgfile) - - def get_config_obj(self, cfgfile): - try: - cfg = util.read_conf(cfgfile) - except: - # TODO: this 'log' could/should be passed in - cloudinit.log.critical("Failed loading of cloud config '%s'. " - "Continuing with empty config\n" % cfgfile) - cloudinit.log.debug(traceback.format_exc() + "\n") - cfg = None - if cfg is None: - cfg = {} - - try: - ds_cfg = self.cloud.datasource.get_config_obj() - except: - ds_cfg = {} +import yaml - cfg = util.mergedict(cfg, ds_cfg) - return(util.mergedict(cfg, self.cloud.cfg)) +from cloudinit.settings import (PER_INSTANCE, PER_ALWAYS, PER_ONCE) - def handle(self, name, args, freq=None): - try: - mod = __import__("cc_" + name.replace("-", "_"), globals()) - def_freq = getattr(mod, "frequency", per_instance) - handler = getattr(mod, "handle") +from cloudinit import log as logging +from cloudinit import util - if not freq: - freq = def_freq +LOG = logging.getLogger(__name__) - self.cloud.sem_and_run("config-" + name, freq, handler, - [name, self.cfg, self.cloud, cloudinit.log, args]) - except: - raise +DEF_HANDLER_VERSION = 1 +DEF_FREQ = PER_INSTANCE # reads a cloudconfig module list, returns |