Skip to content
Permalink
Browse files

Update main.py, ui/ui.js, template/set-flow-route.conf

Fixes #4
  • Loading branch information...
knewell committed Apr 11, 2019
1 parent 3d15275 commit 25ca268f783d1e06530b08ace18c6e79c526754e
Showing with 47 additions and 25 deletions.
  1. +31 −11 main.py
  2. +6 −4 template/set-flow-route.conf
  3. +10 −10 ui/ui.js
42 main.py
@@ -70,7 +70,7 @@ def addNewFlowRoute(self, flowRouteData=None):
cu = Config(dev)
cu.lock()

cu.load(template_path='template/set-flow-route.conf', template_vars=flowRouteData, merge=True)
cu.load(template_path='template/set-flow-route.conf', template_vars=flowRouteData)
cu.commit()
cu.unlock()

@@ -93,7 +93,7 @@ def modFlowRoute(self, flowRouteData=None):

env = Environment(autoescape=False,
loader=FileSystemLoader('./template'), trim_blocks=False, lstrip_blocks=False)
template = env.get_template('mod-flow-route.conf')
template = env.get_template('set-flow-route.conf')
#print(template.render(flowRouteData))

my_router = None
@@ -108,7 +108,7 @@ def modFlowRoute(self, flowRouteData=None):
try:
cu = Config(dev)
cu.lock()
cu.load(template_path='template/mod-flow-route.conf', template_vars=flowRouteData)
cu.load(template_path='template/set-flow-route.conf', template_vars=flowRouteData)
cu.commit()
cu.unlock()

@@ -198,11 +198,11 @@ def getActiveFlowRoutes(self):

for flow in frt:

destination = flow.destination.split(',')
destination = self.parseFlow(flow.destination)

for index, item in enumerate(destination):
_item = item.split('=')
destination[index] = _item[1] if len(_item) > 1 else _item[0]
# for index, item in enumerate(destination):
# _item = item.split('=')
# destination[index] = _item[1] if len(_item) > 1 else _item[0]

hash_object = hashlib.sha512(b'{0}{1}'.format(str(destination), str(value['ip'])))
hex_dig = hash_object.hexdigest()
@@ -322,11 +322,11 @@ def getActiveFlowRouteFilter(self):

for filter in frft:

data = filter.name.split(',')
data = self.parseFlow(filter.name)

for didx, item in enumerate(data):
_item = item.split('=')
data[didx] = _item[1] if len(_item) > 1 else _item[0]
# for didx, item in enumerate(data):
# _item = item.split('=')
# data[didx] = _item[1] if len(_item) > 1 else _item[0]

_vrf = table.split('_')
family = ''
@@ -476,6 +476,26 @@ def loadFlowRouteConfig(self):

return True, self.flow_config

def parseFlow(self, flow=None):
_flow = flow.split(',')
data = dict()

data['dst'] = _flow[0]
data['src'] = _flow[1]
key = ''

for counter,item in enumerate(_flow):
if counter == 0 or counter == 1:
continue
_item = re.split('=|:', item)
if _item[0] is not '':
key = _item[0]
data[key] = [_item[1]]
else:
data[key].append(_item[1])

return data

def save_settings(self, dev_user=None, dev_pw=None, routers=None, age_out_interval=None):

self.dev_user = dev_user
@@ -12,12 +12,13 @@ routing-instances {
{% endif %}
flow {
route {{ flowRouteName }} {
replace:
match {
{%- if dstPrefix is defined and dstPrefix !=None %}
destination {{dstPrefix}};
{%- endif %}
{%- if dstPort is defined and dstPort !=None %}
destination-port {{ dstPort }};
destination-port [{{ dstPort }}];
{%- endif %}
{%- if dscp is defined and dscp !=None %}
dscp {{dscp}};
@@ -35,7 +36,7 @@ routing-instances {
packet-length {{packet_length}};
{%- endif %}
{%- if port is defined and port !=None %}
port {{port}};
port [{{port}}];
{%- endif %}
{%- if protocol is defined and protocol !=None %}
protocol {{protocol}};
@@ -44,14 +45,15 @@ routing-instances {
source {{srcPrefix}};
{%- endif %}
{%- if srcPort is defined and srcPortt !=None %}
source-port {{srcPort}};
source-port [{{srcPort}}];
{%- endif %}
{%- if tcp_flags is defined and tcp_flags !=None %}
tcp-flags {{tcp_flags}};
{%- endif %}
}
replace:
then {
{{action}};
{{action}};
}
}
}
@@ -132,11 +132,11 @@ $(document).ready(function () {
'vrf': flow.vrf,
'family': flow.family,
'term': flow.term,
'dstPrefix': flow.destination[0],
'dstPort': flow.destination[3],
'srcPrefix': flow.destination[1],
'srcPort': flow.destination[4],
'protocol': flow.destination[2],
'dstPrefix': flow.destination.dst,
'dstPort': flow.destination.dstport,
'srcPrefix': flow.destination.src,
'srcPort': flow.destination.srcport,
'protocol': flow.destination.proto,
'krtAction': flow.krtAction,
'commAction': flow.commAction,
'age': flow.age
@@ -224,11 +224,11 @@ $(document).ready(function () {
'name': rname,
'vrf': filter.vrf,
'family': filter.family,
'dstPrefix': filter.data[0],
'dstPort': filter.data[3],
'srcPrefix': filter.data[1],
'srcPort': filter.data[4],
'protocol': filter.data[2],
'dstPrefix': filter.data.dst,
'dstPort': filter.data.dstport,
'srcPrefix': filter.data.src,
'srcPort': filter.data.srcport,
'protocol': filter.data.proto,
'packetCount': filter.packet_count,
'byteCount': filter.byte_count
})

0 comments on commit 25ca268

Please sign in to comment.
You can’t perform that action at this time.