#!/usr/bin/env python

import glob
import re
import subprocess
import os
import sys

pathspec = "/etc/xen/auto/*"
regexp = re.compile(r"vif.*?=.*?ip=([0-9\. ]+)'")

files = glob.glob(pathspec)

contents = ( file(t).read(-1) for t in files )

def ips(contents):
	matches = regexp.findall("\n".join(list(contents)))
	for match in matches:
		mips = match.split(" ")
		for ip in mips: yield ip

devnull = file("/dev/null","w")
procs = ( subprocess.Popen(["ping",ip,"-c","1"],stdin=devnull,stdout=devnull,stderr=devnull) for ip in ips(contents) )

returncodes = ( proc.wait() for proc in list(procs) )

sys.exit(sum(returncodes))

