diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-01-17 14:41:29 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-01-17 14:41:29 -0500 |
commit | 15e3241ba725a21604e0f3570e755a91b5edba00 (patch) | |
tree | d84be61c3a56ddc03eb927d5de5433afacadf64b /cloudinit/CloudConfig/cc_update_hostname.py | |
parent | 2f7227c7092ad873757167f62c2a82fb4ee69472 (diff) | |
download | vyos-cloud-init-15e3241ba725a21604e0f3570e755a91b5edba00.tar.gz vyos-cloud-init-15e3241ba725a21604e0f3570e755a91b5edba00.zip |
[PATCH] PEP8 coding style fixes.
From: Juerg Haefliger <juerg.haefliger@hp.com>
This pulls in the named patch for LP: #914739 with a few other changes.
Diffstat (limited to 'cloudinit/CloudConfig/cc_update_hostname.py')
-rw-r--r-- | cloudinit/CloudConfig/cc_update_hostname.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/cloudinit/CloudConfig/cc_update_hostname.py b/cloudinit/CloudConfig/cc_update_hostname.py index 893c99e0..2387a8dc 100644 --- a/cloudinit/CloudConfig/cc_update_hostname.py +++ b/cloudinit/CloudConfig/cc_update_hostname.py @@ -22,19 +22,21 @@ from cloudinit.CloudConfig import per_always frequency = per_always + def handle(_name, cfg, cloud, log, _args): if util.get_cfg_option_bool(cfg, "preserve_hostname", False): log.debug("preserve_hostname is set. not updating hostname") return - ( hostname, _fqdn ) = util.get_hostname_fqdn(cfg, cloud) + (hostname, _fqdn) = util.get_hostname_fqdn(cfg, cloud) try: - prev ="%s/%s" % (cloud.get_cpath('data'), "previous-hostname") + prev = "%s/%s" % (cloud.get_cpath('data'), "previous-hostname") update_hostname(hostname, prev, log) except Exception: log.warn("failed to set hostname\n") raise + # read hostname from a 'hostname' file # allow for comments and stripping line endings. # if file doesn't exist, or no contents, return default @@ -54,7 +56,8 @@ def read_hostname(filename, default=None): if e.errno != errno.ENOENT: raise return default - + + def update_hostname(hostname, prev_file, log): etc_file = "/etc/hostname" @@ -75,7 +78,7 @@ def update_hostname(hostname, prev_file, log): if not hostname_prev or hostname_prev != hostname: update_files.append(prev_file) - if (not hostname_in_etc or + if (not hostname_in_etc or (hostname_in_etc == hostname_prev and hostname_in_etc != hostname)): update_files.append(etc_file) @@ -93,4 +96,3 @@ def update_hostname(hostname, prev_file, log): if etc_file in update_files: log.debug("setting hostname to %s" % hostname) subprocess.Popen(['hostname', hostname]).communicate() - |