~ubuntu-branches/ubuntu/quantal/cloud-init/quantal

« back to all changes in this revision

Viewing changes to cloudinit/CloudConfig/cc_bootcmd.py

  • Committer: Scott Moser
  • Date: 2011-02-19 05:49:39 UTC
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: smoser@ubuntu.com-20110219054939-0vwbq9fh2h7qy3xk
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vi: ts=4 expandtab
 
2
#
 
3
#    Copyright (C) 2009-2011 Canonical Ltd.
 
4
#
 
5
#    Author: Scott Moser <scott.moser@canonical.com>
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU General Public License version 3, as
 
9
#    published by the Free Software Foundation.
 
10
#
 
11
#    This program is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU General Public License
 
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
import cloudinit.util as util
 
19
import subprocess
 
20
import tempfile
 
21
 
 
22
def handle(name,cfg,cloud,log,args):
 
23
    if not cfg.has_key("bootcmd"):
 
24
        return
 
25
 
 
26
    try:
 
27
        content = util.shellify(cfg["bootcmd"])
 
28
        tmpf = tempfile.TemporaryFile()
 
29
        tmpf.write(content)
 
30
        tmpf.seek(0)
 
31
    except:
 
32
        log.warn("failed to shellify bootcmd")
 
33
        raise
 
34
    
 
35
    try:
 
36
        subprocess.check_call(['/bin/sh'], stdin=tmpf)
 
37
        tmpf.close()
 
38
    except:
 
39
        log.warn("failed to run commands from bootcmd")
 
40
        raise