我正在寻找一种将 ip 地址传递给 cloud-init 元数据的方法。因此,当我的 qcow 启动时,它不必等待 120 - 180 秒即可启动。
目前,我通过将 IP 地址信息添加到 cloud-init 的 userdata 部分来创建解决方法。缺点是,它确实需要一些时间,因为 cloud-init 用户数据仅在启动 VM 后执行。
echo -e "
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
\taddress $address
\tnetmask $netmask
\tgateway $gateway
\tdns-nameservers $dnsnameservers
" > /etc/network/interfaces
ifdown eth0; ifup eth0
目前要在 cloud-init 元数据中设置主机名,我已经获得了这部分:
cat > $config_dir/meta-data <<-EOF
instance-id: $uuid
hostname: $hostname
local-hostname: $hostname
EOF
但我需要更坚实、更具体的东西,因为 cloud-init 文档非常模糊
编辑:我已经看到这是可能的,因为 Openstack 可以做到。