From c12a94d6827bf51cff323a33efb289ff32b5546a Mon Sep 17 00:00:00 2001 From: Karl Newell Date: Fri, 15 Mar 2019 16:12:26 -0700 Subject: [PATCH] Update main.py - more v6 support. Flow Config now retrieves v6 flows. Cannot Add/Mod/Del --- main.py | 88 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/main.py b/main.py index 6b21c2d..96122eb 100644 --- a/main.py +++ b/main.py @@ -297,45 +297,55 @@ def loadFlowRouteConfig(self): # if int(version[0]) <= 14 and int(version[1]) <= 1: if True: - data = dev.rpc.get_config(options={'format': 'xml'}, filter_xml='routing-options/flow') - - for route in data.iter('route'): - my_list = list() - - for item in route: - - if 'name' in item.tag: - my_list.append(item.text) - self.flow_config[item.text] = {} - - elif 'match' in item.tag: - tag = None - - for child in item.iterchildren(): - - if 'destination-port' in child.tag: - tag = 'dstPort' - elif 'source-port' in child.tag: - tag = 'srcPort' - elif 'destination' in child.tag: - tag = 'dstPrefix' - elif 'source' in child.tag: - tag = 'srcPrefix' - elif 'protocol' in child.tag: - tag = 'protocol' - - self.flow_config[my_list[0]][tag] = child.text - - elif 'then' in item.tag: - - _action = dict() - - for child in item.iterchildren(): - - for value in child.iter(): - _action[child.tag] = {'value': value.text} - - self.flow_config[my_list[0]]['action'] = _action + # Retrieving all routing-options so we can get both v4 and v6. Might also work for VRFs + data = dev.rpc.get_config(options={'format': 'xml'}, filter_xml='routing-options') + + # iterate only over children. Appears to enter into multiple levels implicitly + for routes in data.iter('flow'): + for route in routes.iter('route'): + my_list = list() + + for item in route: + + if 'name' in item.tag: + my_list.append(item.text) + self.flow_config[item.text] = {} + + elif 'match' in item.tag: + tag = None + + for child in item.iterchildren(): + + if 'destination-port' in child.tag: + tag = 'dstPort' + elif 'source-port' in child.tag: + tag = 'srcPort' + elif 'destination' in child.tag: + tag = 'dstPrefix' + elif 'source' in child.tag: + tag = 'srcPrefix' + elif 'protocol' in child.tag: + tag = 'protocol' + + # v6 flow routes have a child inside src and dst items + # this grabs the value and puts it in child.txt + if tag in ['srcPrefix', 'dstPrefix']: + for grandchild in child.iterchildren(): + if 'prefix' in grandchild.tag: + child.text = grandchild.text + + self.flow_config[my_list[0]][tag] = child.text + + elif 'then' in item.tag: + + _action = dict() + + for child in item.iterchildren(): + + for value in child.iter(): + _action[child.tag] = {'value': value.text} + + self.flow_config[my_list[0]]['action'] = _action return True, self.flow_config