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}

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐