summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/cloud.py37
1 files changed, 31 insertions, 6 deletions
diff --git a/cloudinit/cloud.py b/cloudinit/cloud.py
index 765e7d3a..b2dfc749 100644
--- a/cloudinit/cloud.py
+++ b/cloudinit/cloud.py
@@ -20,6 +20,9 @@
# 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 copy
+import os
+
from cloudinit import distros
from cloudinit import helpers
from cloudinit import log as logging
@@ -28,18 +31,40 @@ LOG = logging.getLogger(__name__)
class Cloud(object):
- def __init__(self, datasource, paths, cfg):
+ def __init__(self, datasource, paths, cfg, distro, runners):
self.datasource = datasource
self.paths = paths
- self.cfg = cfg
- self.distro = distros.fetch(cfg, self)
- self.runners = helpers.Runners(paths)
+ self.distro = distro
+ self._cfg = cfg
+ self._runners = runners
+
+ # If a transform manipulates logging or logging services
+ # it is typically useful to cause the logging to be
+ # setup again.
+ def cycle_logging(self):
+ logging.setupLogging(self.cfg)
+
+ @property
+ def cfg(self):
+ # Ensure that not indirectly modified
+ return copy.deepcopy(self._cfg)
def run(self, name, functor, args, freq=None, clear_on_fail=False):
- return self.runners.run(name, functor, args, freq, clear_on_fail)
+ return self._runners.run(name, functor, args, freq, clear_on_fail)
+
+ def get_template_filename(self, name):
+ fn = self.paths.template_tpl % (name)
+ if not os.path.isfile(fn):
+ LOG.warn("No template found at %s for template named %s", fn, name)
+ return None
+ return fn
+ # The rest of thes are just useful proxies
def get_userdata(self):
return self.datasource.get_userdata()
+
+ def get_instance_id(self):
+ return self.datasource.get_instance_id()
def get_public_ssh_keys(self):
return self.datasource.get_public_ssh_keys()
@@ -47,7 +72,7 @@ class Cloud(object):
def get_locale(self):
return self.datasource.get_locale()
- def get_mirror(self):
+ def get_local_mirror(self):
return self.datasource.get_local_mirror()
def get_hostname(self, fqdn=False):