summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-02-19 01:54:49 -0500
committerScott Moser <smoser@ubuntu.com>2010-02-19 01:54:49 -0500
commitd24e24686e0aa40adbd2f31f29a61f02db838b00 (patch)
treebdb1d06025390d855fc5f3954edb09b73b205814 /cloudinit
parent433db020a1d7a3165053a0a13b0dda22086ac71b (diff)
downloadvyos-cloud-init-d24e24686e0aa40adbd2f31f29a61f02db838b00.tar.gz
vyos-cloud-init-d24e24686e0aa40adbd2f31f29a61f02db838b00.zip
add "runcmd" support in CloudConfig
runcmd allows simple running of commands at rc.local like time frame see doc/examples/cloud-config.txt for more info.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/CloudConfig.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/cloudinit/CloudConfig.py b/cloudinit/CloudConfig.py
index 674e868e..e15dbb2c 100644
--- a/cloudinit/CloudConfig.py
+++ b/cloudinit/CloudConfig.py
@@ -189,6 +189,7 @@ class CloudConfig():
def h_config_misc(self,name,args):
handle_updates_check(self.cfg)
+ handle_runcmd(self.cfg)
def h_config_puppet(self,name,args):
# If there isn't a puppet key in the configuration don't do anything
@@ -494,3 +495,25 @@ def handle_updates_check(cfg):
except:
warn("failed to enable cron update system check")
+def handle_runcmd(cfg):
+ if not cfg.has_key("runcmd"):
+ return
+ outfile="%s/runcmd" % cloudinit.user_scripts_dir
+
+ content="#!/bin/sh\n"
+ escaped="%s%s%s%s" % ( "'", '\\', "'", "'" )
+ try:
+ for args in cfg["runcmd"]:
+ # if the item is a list, wrap all items in single tick
+ # if its not, then just write it directly
+ if isinstance(args,list):
+ fixed = [ ]
+ for f in args:
+ fixed.append("'%s'" % f.replace("'",escaped))
+ content="%s%s\n" % ( content, ' '.join(fixed) )
+ else:
+ content="%s%s\n" % ( content, args )
+
+ util.write_file(outfile,content,0700)
+ except:
+ warn("failed to open %s for runcmd", outfile)