Scott Moser fa55bf8ddb This fixes LP: #819507, to make consume_userdata run 'always'
consume_userdata should really run always, rather than once per instance.

The documentation says that boothooks were on their own for per-instance
but since this routine was only being called once, they would only get
called once.

This  modifies the behavior to be:
   user_script: per_always
   cloud_config : per_always
   upstart_job : per_instance
   cloud_boothook: per_always

In order to not break part handlers that are existing, and expect to only be
called once per instance, this adds a 'handler_version' item in a handler
that can indicate the version (currently 1 or 2).  If it is 2, then the
hander will be passed the frequency (per-instance or per-always) that this
is being run.  That way the handler can differenciate between them.

This also makes 'bootcmd' run every boot.  That should be changable in
cloud-config though, so users who dont like the behavior can modify it.
2011-08-02 17:09:43 -04:00

43 lines
1.3 KiB
Python

# vi: ts=4 expandtab
#
# Copyright (C) 2009-2011 Canonical Ltd.
#
# Author: Scott Moser <scott.moser@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import cloudinit.util as util
import subprocess
import tempfile
from cloudinit.CloudConfig import per_always
frequency = per_always
def handle(name,cfg,cloud,log,args):
if not cfg.has_key("bootcmd"):
return
try:
content = util.shellify(cfg["bootcmd"])
tmpf = tempfile.TemporaryFile()
tmpf.write(content)
tmpf.seek(0)
except:
log.warn("failed to shellify bootcmd")
raise
try:
subprocess.check_call(['/bin/sh'], stdin=tmpf)
tmpf.close()
except:
log.warn("failed to run commands from bootcmd")
raise