-
-def whitelistfilter():
- """creates a regex (re) object based on the slice definitions
- in /etc/planetlab/whitelist"""
-
- whitelist = []
- whitelist_re = re.compile("([a-zA-Z0-9\*]+)_([a-zA-Z0-9\*]+)")
- linecount = 0
- try:
- f = open('/etc/planetlab/whitelist')
- for line in f.readlines():
- linecount = linecount+1
- line = line.strip()
- # skip comments
- if len(line)>0 and line[0]=='#':
- continue
- m = whitelist_re.search(line)
- if m == None:
- logger.log("skipping line #%d in /etc/planetlab/whitelist" % linecount)
- continue
- else:
- whitelist.append(m.group())
- f.close()
- except IOError,e:
- logger.log("IOError -> %s" % e)
- logger.log("No whitelist file found; setting slice white list to *_*")
- whitelist = ["*_*"]
-
- white_re_list = None
- for w in whitelist:
- w = string.replace(w,'*','([a-zA-Z0-9]+)')
- if white_re_list == None:
- white_re_list = w
- else:
- white_re_list = "(%s)|(%s)" % (white_re_list,w)
-
- if white_re_list == None:
- white_re_list = "([a-zA-Z0-9]+)_([a-zA-Z0-9]+)"
-
- logger.log("whitelist regex = %s" % white_re_list)
- whitelist_re = re.compile(white_re_list)
- return whitelist_re
-