Remove cloud config from here and move to cloud.py
This commit is contained in:
@@ -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
|
||||
import yaml
|
||||
|
||||
from cloudinit.settings import (PER_INSTANCE, PER_ALWAYS, PER_ONCE)
|
||||
|
||||
class CloudConfig():
|
||||
cfgfile = None
|
||||
cfg = None
|
||||
from cloudinit import log as logging
|
||||
from cloudinit import util
|
||||
|
||||
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)
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
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 = {}
|
||||
|
||||
cfg = util.mergedict(cfg, ds_cfg)
|
||||
return(util.mergedict(cfg, self.cloud.cfg))
|
||||
|
||||
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")
|
||||
|
||||
if not freq:
|
||||
freq = def_freq
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user