Skip to content

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

Merged
merged 1 commit into from May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 31 additions & 11 deletions main.py
Expand Up @@ -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()

Expand All @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions template/set-flow-route.conf
Expand Up @@ -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}};
Expand All @@ -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}};
Expand All @@ -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}};
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions ui/ui.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
Expand Down