~cloud-init-dev/cloud-init/trunk

« back to all changes in this revision

Viewing changes to cloudinit/config/cc_grub_dpkg.py

  • Committer: Scott Moser
  • Date: 2016-08-10 15:06:15 UTC
  • Revision ID: smoser@ubuntu.com-20160810150615-ma2fv107w3suy1ma
README: Mention move of revision control to git.

cloud-init development has moved its revision control to git.
It is available at 
  https://code.launchpad.net/cloud-init

Clone with 
  git clone https://git.launchpad.net/cloud-init
or
  git clone git+ssh://git.launchpad.net/cloud-init

For more information see
  https://git.launchpad.net/cloud-init/tree/HACKING.rst

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vi: ts=4 expandtab
2
 
#
3
 
#    Copyright (C) 2009-2010 Canonical Ltd.
4
 
#    Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
5
 
#
6
 
#    Author: Scott Moser <scott.moser@canonical.com>
7
 
#    Author: Juerg Haefliger <juerg.haefliger@hp.com>
8
 
#
9
 
#    This program is free software: you can redistribute it and/or modify
10
 
#    it under the terms of the GNU General Public License version 3, as
11
 
#    published by the Free Software Foundation.
12
 
#
13
 
#    This program is distributed in the hope that it will be useful,
14
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
#    GNU General Public License for more details.
17
 
#
18
 
#    You should have received a copy of the GNU General Public License
19
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 
21
 
import os
22
 
 
23
 
from cloudinit import util
24
 
 
25
 
distros = ['ubuntu', 'debian']
26
 
 
27
 
 
28
 
def handle(name, cfg, _cloud, log, _args):
29
 
 
30
 
    mycfg = cfg.get("grub_dpkg", cfg.get("grub-dpkg", {}))
31
 
    if not mycfg:
32
 
        mycfg = {}
33
 
 
34
 
    enabled = mycfg.get('enabled', True)
35
 
    if util.is_false(enabled):
36
 
        log.debug("%s disabled by config grub_dpkg/enabled=%s", name, enabled)
37
 
        return
38
 
 
39
 
    idevs = util.get_cfg_option_str(mycfg, "grub-pc/install_devices", None)
40
 
    idevs_empty = util.get_cfg_option_str(
41
 
        mycfg, "grub-pc/install_devices_empty", None)
42
 
 
43
 
    if ((os.path.exists("/dev/sda1") and not os.path.exists("/dev/sda")) or
44
 
       (os.path.exists("/dev/xvda1") and not os.path.exists("/dev/xvda"))):
45
 
        if idevs is None:
46
 
            idevs = ""
47
 
        if idevs_empty is None:
48
 
            idevs_empty = "true"
49
 
    else:
50
 
        if idevs_empty is None:
51
 
            idevs_empty = "false"
52
 
        if idevs is None:
53
 
            idevs = "/dev/sda"
54
 
            for dev in ("/dev/sda", "/dev/vda", "/dev/xvda",
55
 
                        "/dev/sda1", "/dev/vda1", "/dev/xvda1"):
56
 
                if os.path.exists(dev):
57
 
                    idevs = dev
58
 
                    break
59
 
 
60
 
    # now idevs and idevs_empty are set to determined values
61
 
    # or, those set by user
62
 
 
63
 
    dconf_sel = (("grub-pc grub-pc/install_devices string %s\n"
64
 
                 "grub-pc grub-pc/install_devices_empty boolean %s\n") %
65
 
                 (idevs, idevs_empty))
66
 
 
67
 
    log.debug("Setting grub debconf-set-selections with '%s','%s'" %
68
 
              (idevs, idevs_empty))
69
 
 
70
 
    try:
71
 
        util.subp(['debconf-set-selections'], dconf_sel)
72
 
    except Exception:
73
 
        util.logexc(log, "Failed to run debconf-set-selections for grub-dpkg")