diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-06-17 22:22:39 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-06-17 22:22:39 -0400 |
commit | 22184b7ca3f78808d8025bab5981ed92f8ad99f5 (patch) | |
tree | 89c9f4b1991d5f453b7fec5d9239c09adeb7f0f3 /cloudinit/CloudConfig/__init__.py | |
parent | 257da18b16434360e656fe1ef94e4cf8ba3a5210 (diff) | |
download | vyos-cloud-init-22184b7ca3f78808d8025bab5981ed92f8ad99f5.tar.gz vyos-cloud-init-22184b7ca3f78808d8025bab5981ed92f8ad99f5.zip |
make cloud-config modules configurable by cloud-config
The list of cloud-config modules is now kept in cloud config itself.
There is a builtin list in cloudinit, which is overrideable by
/etc/cloud/cloud.cfg or user data cloud-config.
This should make the modules more easily added or removed (as no code
needs to be edited now)
Basic summary of changes:
- move CloudConfig.py -> cloudinit/CloudConfig/__init__.py
- split cloud-config modules into their own files named
cloudinit/CloudConfig/cc_<name>.py
- remove all the upstart/cloud-config-* scripts, replacing them with
upstart/cloud-config.conf
Diffstat (limited to 'cloudinit/CloudConfig/__init__.py')
-rw-r--r-- | cloudinit/CloudConfig/__init__.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/cloudinit/CloudConfig/__init__.py b/cloudinit/CloudConfig/__init__.py new file mode 100644 index 00000000..600b21ab --- /dev/null +++ b/cloudinit/CloudConfig/__init__.py @@ -0,0 +1,57 @@ +# vi: ts=4 expandtab +# +# Copyright (C) 2008-2010 Canonical Ltd. +# +# Author: Chuck Short <chuck.short@canonical.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +import yaml +import cloudinit +import cloudinit.util as util +import sys + +per_instance="once-per-instance" +per_always="always" + +class CloudConfig(): + cfgfile = None + cfg = None + + def __init__(self,cfgfile): + self.cloud = cloudinit.CloudInit() + self.cfg = self.get_config_obj(cfgfile) + self.cloud.get_data_source() + + def get_config_obj(self,cfgfile): + f=file(cfgfile) + cfg=yaml.load(f.read()) + f.close() + if cfg is None: 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(name, freq, handler, + [ name, self.cfg, self.cloud, cloudinit.log, args ]) + except: + cloudinit.log.error(traceback.format_exc()) + raise + |