Skip to content

Instantly share code, notes, and snippets.

@krono
Created October 19, 2018 12:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krono/0616e314785ea410a7419aa409a36fc6 to your computer and use it in GitHub Desktop.
Save krono/0616e314785ea410a7419aa409a36fc6 to your computer and use it in GitHub Desktop.
Update Xen info from an OpenBSD guest
#!/bin/sh
#
# add to /etc/rc.local
# [ -x /usr/local/bin/xe-update-stats ] && /usr/local/bin/xe-update-stats init
# add to `crontab -e`
# 1-59 * * * * /bin/sh /usr/local/bin/xe-update-stats
if [ "$1" = "init" ]; then
ostype=$(sysctl -n kern.ostype)
osrelease=$(sysctl -n kern.osrelease)
# XenServer Tools version
hostctl attr/PVAddons/MajorVersion 6
hostctl attr/PVAddons/MinorVersion 2
hostctl attr/PVAddons/MicroVersion 0
hostctl attr/PVAddons/BuildVersion 76888
hostctl attr/PVAddons/Installed 1
for ifline in $(dmesg | grep address | sed -E -e 's/^(xnf.+)\ at.*address\ ([a-fA-F0-9:]+)/\1=\2/' | sort); do
mac=$(echo $ifline | cut -d= -f2)
if=$(echo $ifline | cut -d= -f1)
for vif in $(hostctl device/vif); do
if [ "$mac" = "$(hostctl device/vif/$vif/mac)" ]; then
ip4=$(ifconfig $if | grep 'inet[^6]' | cut -d ' ' -f2)
ip6=$(ifconfig $if | grep 'inet6' | cut -d ' ' -f2 | cut -d% -f1)
if [ -n "$ip4" ]; then
hostctl attr/eth$vif/ip "$ip4"
fi
if [ -n "$ip6" ]; then
hostctl attr/eth$vif/ipv6/0/addr "$ip6"
fi
fi
done
done
# OS version
hostctl data/os_name "$ostype $osrelease"
hostctl data/os_uname $osrelease
hostctl data/os_distro $ostype
hostctl data/os_majorver $(echo $osrelease | sed -e 's/\..*$//')
hostctl data/os_minorver $(echo $osrelease | sed -e 's/^.*\.//')
# Update XenStore
hostctl data/updated 1
fi
hostctl data/meminfo_total $(vmstat -s | awk -v pagesize=`/sbin/sysctl -n hw.pagesize` '/pages managed$/ { print $1 * pagesize / 1024 }')
hostctl data/meminfo_free $(vmstat -s | awk -v pagesize=`/sbin/sysctl -n hw.pagesize` '/pages free$/ { print $1 * pagesize / 1024 }')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment