~ubuntu-branches/ubuntu/saucy/cloud-init/saucy

« back to all changes in this revision

Viewing changes to cloudinit/config/cc_set_hostname.py

  • Committer: Scott Moser
  • Date: 2012-07-06 21:24:18 UTC
  • mfrom: (1.1.26)
  • Revision ID: smoser@ubuntu.com-20120706212418-zwcpwxsdodi0pms3
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vi: ts=4 expandtab
 
2
#
 
3
#    Copyright (C) 2011 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
from cloudinit import util
 
22
 
 
23
 
 
24
def handle(name, cfg, cloud, log, _args):
 
25
    if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
 
26
        log.debug(("Configuration option 'preserve_hostname' is set,"
 
27
                    " not setting the hostname in module %s"), name)
 
28
        return
 
29
 
 
30
    (hostname, _fqdn) = util.get_hostname_fqdn(cfg, cloud)
 
31
    try:
 
32
        log.debug("Setting hostname to %s", hostname)
 
33
        cloud.distro.set_hostname(hostname)
 
34
    except Exception:
 
35
        util.logexc(log, "Failed to set hostname to %s", hostname)