From e285b1614b00c5689ac71ec9afcfa83d996b22c0 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 7 Feb 2011 17:03:34 -0500 Subject: add 'bootcmd' like 'runcmd' to cloud-config syntax for running things early --- cloudinit/util.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'cloudinit/util.py') diff --git a/cloudinit/util.py b/cloudinit/util.py index 40925b94..72db58f9 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -338,3 +338,22 @@ def readurl(url, data=None): response = urllib2.urlopen(req) return(response.read()) + +# shellify, takes a list of commands +# for each entry in the list +# if it is an array, shell protect it (with single ticks) +# if it is a string, do nothing +def shellify(cmdlist): + content="#!/bin/sh\n" + escaped="%s%s%s%s" % ( "'", '\\', "'", "'" ) + for args in cmdlist: + # 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'" % str(f).replace("'",escaped)) + content="%s%s\n" % ( content, ' '.join(fixed) ) + else: + content="%s%s\n" % ( content, str(args) ) + return content -- cgit v1.2.3