summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-02-07 17:03:34 -0500
committerScott Moser <smoser@ubuntu.com>2011-02-07 17:03:34 -0500
commite285b1614b00c5689ac71ec9afcfa83d996b22c0 (patch)
tree54f9df3a9620def7a87106b8d618c00c35a2007e /cloudinit/util.py
parent00ac0cfe971b1891b722455615df2230b0382567 (diff)
downloadvyos-cloud-init-e285b1614b00c5689ac71ec9afcfa83d996b22c0.tar.gz
vyos-cloud-init-e285b1614b00c5689ac71ec9afcfa83d996b22c0.zip
add 'bootcmd' like 'runcmd' to cloud-config syntax for running things early
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py19
1 files changed, 19 insertions, 0 deletions
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