def _getRules(device): """ 32764: from all to 10.35.0.0/23 iif ovirtmgmt lookup 170066094 32765: from 10.35.0.0/23 lookup 170066094 The first rule we'll find directly via the interface name We'll then use that rule's destination network, and use it to find the second rule via its source network """ allRules = [] for entry in ruleList(): try: rule = Rule.fromText(entry) except ValueError: logging.debug("Could not parse rule %s" % entry) else: allRules.append(rule) # Find the rule we put in place with 'device' as its 'srcDevice' rules = [rule for rule in allRules if rule.srcDevice == device] if not rules: logging.error("Routing rules not found for device %s" % device) return # Extract its destination network network = rules[0].destination # Find the other rule we put in place - It'll have 'network' as # its source rules += [rule for rule in allRules if rule.source == network] return rules
def wrapper(*args, **kwargs): try: base = ipwrapper.ruleList() func(*args, **kwargs) except Exception: restoreRules(base) raise
def _getRules(device): """ 32764: from all to 10.35.0.0/23 iif ovirtmgmt lookup 170066094 32765: from 10.35.0.0/23 lookup 170066094 The first rule we'll find directly via the interface name We'll then use that rule's destination network, and use it to find the second rule via its source network """ allRules = [] for entry in ruleList(): try: rule = Rule.fromText(entry) except ValueError: logging.debug("Could not parse rule %s", entry) else: allRules.append(rule) # Find the rule we put in place with 'device' as its 'srcDevice' rules = [r for r in allRules if r.srcDevice == device] if not rules: logging.error("Routing rules not found for device %s", device) return # Extract its destination network network = rules[0].destination # Find the other rule we put in place - It'll have 'network' as # its source rules += [r for r in allRules if r.source == network] return rules
def restoreRules(base): current = ipwrapper.ruleList() added = set(current) - set(base) for rule in added: ipwrapper.ruleDel(ipwrapper.Rule.fromText(rule))