From d24e24686e0aa40adbd2f31f29a61f02db838b00 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 19 Feb 2010 01:54:49 -0500 Subject: 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. --- cloudinit/CloudConfig.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'cloudinit') 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) -- cgit v1.2.3