xenserver 命令行得到vm的ip

All IP addresses for the host?

export hostuuid=`xe host-list name-label=[YOURHOSTNAME] --minimal` && xe pif-list host-uuid=$hostuuid params=device,IP,netmask,gateway,DNS | grep -v "^$"

will output all the IP addresses for the host itself. If you want all the IP addresses for all the VMs on a host - as has been mentioned

xe vm-list params=name-label,networks | grep -v "^$"

If you’re getting “not in database” the VMs might not have a network card, or haven’t been turned on yet, or have and are missing xentools.

#

XenServer doesn’t have the functionality to assign IPs to guests. If you are using a configuration management tool, you could have your VM check in with it and configure itself on first boot. You could also script something in your template. For example, one thing I’ve seen done is to add custom kernel parameters after creating the VM (e.g. with xe vm-param-set uuid={VM UUID} PV-args={something}+ ), and have a script in the VM parse +/proc/cmdline and set the network configuration on first boot.

So for example, after importing the CentOS template you could do something like:

> xe vm-param-set uuid={VM UUID} PV-args="graphical utf8 -- _ipaddr=10.0.0.50 _netmask=255.255.255.0 _gateway=10.0.0.1"

Then in the VM run something like this on first boot:
{code}

#!/bin/bash
OPTIONS=$(cat /proc/cmdline|sed 's/.*--//g')
CONFIG=/etc/sysconfig/network-scripts/ifcfg-eth0
echo "DEVICE=eth0">$CONFIG
echo "ONBOOT=yes">>$CONFIG
echo "BOOTPROTO=none">>$CONFIG
for i in $OPTIONS
do
OPT=$(echo $i|cut -f 1 -d "=")
VAL=$(echo $i|cut -f 2 -d "=")
if [ "${OPT:0:1}" = "_" ]
then
case $OPT in
_ipaddr)
echo "IPADDR=$VAL">>$CONFIG;;
_netmask)
echo "NETMASK=$VAL">>$CONFIG;;
_gateway)
echo "GATEWAY=$VAL">>$CONFIG;;
esac
fi
done
service network restart
exit

{code}

And the resulting ifcfg-eth0 would be:
{code}

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.0.0.50
NETMASK=255.255.255.0
GATEWAY=10.0.0.1

{code}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值