We just started supporting Solaris 10 in our VMware cluster so I had to update my zone type script to detect if the OS is running there. I’m not sure how I feel about depending on the output of ptrdiag since the interface is labeled “unstable”, but it works for now, and I really don’t see Sun changing the first line of output where the system configuration is listed. Anyhow, when issued with the -v or –vmware flag, the script returns 0 if it’s running on the cluster and 1 if it is not.
Usage:
# zonetype.sh -g or –global
Return 0: The machine is a global zone with 1 or more local zones
Return 1: The machine is not a global zone
# zonetype.sh -l or –local
Return 0: The machine is a local zone
Return 1: The machine is not a not a local zone
# zonetype.sh -v or –vmware
Return 0: The machine is running on a VMware hypervisor
Return 1: The machine is not running in VMware
#! /bin/bash
#
# When issued with the -g or --global flag, this script will return:
# 0 if the machine is a global zone and has one or more local zones.
# Otherwise, it will return 1
#
# When issued with the -l or --local flag, this script will return:
# 0 if if is a local zone and 1 if it is not
#
# When issued with the -v or --vmware flag, this script will return:
# 0 if it is a vmware host and 1 if not.
#
list=( `/usr/sbin/zoneadm list -civ | awk '{ print $1 }'`)
case "$1" in
-g|--global)
# If the third element in our array is null, set it to 0
if [ "${list[2]}" == "" ]; then
list[2]=0
fi
# This is a global zone only if it has one or more local zones.
if [ ${list[1]} -eq 0 ] && [ ${list[2]} -ge 1 ]; then
# 1 is returned if we have a global and local zone,
# otherwise, we return 0
exit 0
else
exit 1
fi
;;
-l|--local)
# If the second element in our array is = or > 1, it is a local zone.
if [ ${list[1]} -ge 1 ]; then
# Return 1 if this is a local zone, otherwise return 0.
exit 0
else
exit 1
fi
;;
-v|--vmware)
# Don't run our check on local zones... Prtdiag can't run there
if [ ${list[1]} != 0 ]; then
exit 1
else
vmhost=( `/usr/sbin/prtdiag | grep System | awk '{ print $5 }'`)
if [ $vmhost == VMware ]; then
#If the host is running on the vmware cluster return 0,
# otherwise, return 1
exit 0
else
exit 1
fi
fi
;;
*)
echo "Usage: /local/adm/zonetype.sh {-l | --local | -g | --global | -v | --vmware}"
exit 1
esac