diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-06-17 22:22:39 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-06-17 22:22:39 -0400 |
commit | 22184b7ca3f78808d8025bab5981ed92f8ad99f5 (patch) | |
tree | 89c9f4b1991d5f453b7fec5d9239c09adeb7f0f3 /cloudinit/CloudConfig/cc_runcmd.py | |
parent | 257da18b16434360e656fe1ef94e4cf8ba3a5210 (diff) | |
download | vyos-cloud-init-22184b7ca3f78808d8025bab5981ed92f8ad99f5.tar.gz vyos-cloud-init-22184b7ca3f78808d8025bab5981ed92f8ad99f5.zip |
make cloud-config modules configurable by cloud-config
The list of cloud-config modules is now kept in cloud config itself.
There is a builtin list in cloudinit, which is overrideable by
/etc/cloud/cloud.cfg or user data cloud-config.
This should make the modules more easily added or removed (as no code
needs to be edited now)
Basic summary of changes:
- move CloudConfig.py -> cloudinit/CloudConfig/__init__.py
- split cloud-config modules into their own files named
cloudinit/CloudConfig/cc_<name>.py
- remove all the upstart/cloud-config-* scripts, replacing them with
upstart/cloud-config.conf
Diffstat (limited to 'cloudinit/CloudConfig/cc_runcmd.py')
-rw-r--r-- | cloudinit/CloudConfig/cc_runcmd.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cloudinit/CloudConfig/cc_runcmd.py b/cloudinit/CloudConfig/cc_runcmd.py new file mode 100644 index 00000000..fb5739da --- /dev/null +++ b/cloudinit/CloudConfig/cc_runcmd.py @@ -0,0 +1,25 @@ +import cloudinit +import cloudinit.util as util + +def handle(name,cfg,cloud,log,args): + 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'" % str(f).replace("'",escaped)) + content="%s%s\n" % ( content, ' '.join(fixed) ) + else: + content="%s%s\n" % ( content, str(args) ) + + util.write_file(outfile,content,0700) + except: + log.warn("failed to open %s for runcmd" % outfile) |