4

我正在尝试使用 cloud-init 脚本设置我的 Bluemix VM 的主机名,但它抛出了一个错误:

cloud-init[1143]: Cloud-init v. 0.7.5 running 'init' at Sun, 27 Sep 2015 13:14:39 +0000. Up 66.82 seconds.
cloud-init[1143]: ci-info: +++++++++++++++++++++++Net device info+++++++++++++++++++++++
cloud-init[1143]: ci-info: +--------+------+-----------+-----------+-------------------+
cloud-init[1143]: ci-info: | Device |  Up  |  Address  |    Mask   |     Hw-Address    |
cloud-init[1143]: ci-info: +--------+------+-----------+-----------+-------------------+
cloud-init[1143]: ci-info: |  lo:   | True | 127.0.0.1 | 255.0.0.0 |         .         |
cloud-init[1143]: ci-info: | eth0:  | True |     .     |     .     | fa:16:3e:20:97:7b |
cloud-init[1143]: ci-info: +--------+------+-----------+-----------+-------------------+
cloud-init[1143]: ci-info: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Route info failed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CentOS Linux 7 (Core)
Kernel 3.10.0-123.13.2.el7.x86_64 on an x86_64

localhost login: cloud-init[1143]: 2015-09-27 13:15:07,239 - util.py[WARNING]: Failed to set the hostname to XXXXXXXXX (XXXX)
cloud-init[1143]: 2015-09-27 13:15:07,258 - util.py[WARNING]: Running set_hostname (<module 'cloudinit.config.cc_set_hostname' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.pyc'>) failed
cloud-init[1143]: 2015-09-27 13:15:32,287 - util.py[WARNING]: Failed to write hostname XXXXXXXXX to /var/lib/cloud/data/previous-hostname

登录到服务器,我可以看到它/var/lib/cloud/data/previous-hostname不存在:

[ibmcloud@host-192-168-0-30 ~]$ ls -lh /var/lib/cloud/data/previous-hostname
ls: cannot access /var/lib/cloud/data/previous-hostname: No such file or directory

中的代码/usr/lib/python2.7/site-packages/cloudinit/config/cc_set_hostname.py看起来很简单:

from cloudinit import util


def handle(name, cfg, cloud, log, _args):
    if util.get_cfg_option_bool(cfg, "preserve_hostname", False):
        log.debug(("Configuration option 'preserve_hostname' is set,"
                    " not setting the hostname in module %s"), name)
        return

    (hostname, fqdn) = util.get_hostname_fqdn(cfg, cloud)
    try:
        log.debug("Setting the hostname to %s (%s)", fqdn, hostname)
        cloud.distro.set_hostname(hostname, fqdn)
    except Exception:
        util.logexc(log, "Failed to set the hostname to %s (%s)", fqdn,
                    hostname)
        raise

什么可能导致此错误?是否可以提供我自己的 cc_set_hostname.py 脚本版本,我可以添加额外的调试来转储Exception

4

0 回答 0