diff --git a/answerfile.py b/answerfile.py index d0eca714..b79b440b 100644 --- a/answerfile.py +++ b/answerfile.py @@ -428,16 +428,21 @@ def parseInterface(self): if_hwaddr = None if_name = getStrAttribute(node, ['name']) - if if_name and if_name in nethw: + if_hwaddr = getStrAttribute(node, ['hwaddr']) + if not (bool(if_name) ^ bool(if_hwaddr)): + raise AnswerfileException(" tag must have exactly one of 'name' or 'hwaddr'") + + if if_name: + if if_name not in nethw: + raise AnswerfileException(': unknown interface, have %s' % ( + if_name, ", ".join(nethw.keys()))) if_hwaddr = nethw[if_name].hwaddr - else: - if_hwaddr = getStrAttribute(node, ['hwaddr']) - if if_hwaddr: - matching_list = filter(lambda x: x.hwaddr == if_hwaddr.lower(), nethw.values()) - if len(matching_list) == 1: - if_name = matching_list[0].name - if not if_name and not if_hwaddr: - raise AnswerfileException(" tag must have one of 'name' or 'hwaddr'") + elif if_hwaddr: + matching_list = [x for x in nethw.values() if x.hwaddr == if_hwaddr.lower()] + if len(matching_list) != 1: + raise AnswerfileException(': cannot identify interface, have %s' % ( + if_hwaddr, ", ".join(nethw.values()))) + if_name = matching_list[0].name results['net-admin-interface'] = if_name