示例#1
0
def handle(_name, cfg, cloud, log, _args):
    if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
        log.debug("Option 'preserve_hostname' is set. Not setting hostname.")
        return True

    (hostname, _fqdn) = util.get_hostname_fqdn(cfg, cloud)
    try:
        old_name = set_hostname(hostname, log)
        if old_name:
            prev_fn = "%s/%s" % (cloud.get_cpath('data'), "previous-hostname")
            util.write_file(prev_fn, "%s\n" % (old_name), 0644)
    except Exception:
        util.logexc(log)
        log.warn("Failed to set hostname to %s", hostname)

    return True
def handle(_name, cfg, _cloud, _log, _args):
    if util.get_cfg_option_bool(cfg, "disable_ec2_metadata", False):
        util.subp(["route", "add", "-host", "169.254.169.254", "reject"])