Skip to content

Instantly share code, notes, and snippets.

@russellb
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russellb/cebb06ec3a099b46b678 to your computer and use it in GitHub Desktop.
Save russellb/cebb06ec3a099b46b678 to your computer and use it in GitHub Desktop.
A script to print out the OVN Pipeline in a sorted table
#!/usr/bin/python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import prettytable
import subprocess
import sys
def main(argv=None):
if argv is None:
argv = sys.argv
proc = subprocess.Popen(['ovsdb-client','dump', 'OVN_Southbound'],
stdout=subprocess.PIPE)
rows = []
headings = []
lengths = []
in_pipeline = False
while True:
line = proc.stdout.readline().strip()
if in_pipeline:
if not line:
break
row = []
cur = 0
for l in lengths:
row.append(line[cur:cur + len(l)])
cur = cur + len(l) + 1
rows.append(row)
elif line == 'Pipeline table':
in_pipeline = True
headings = proc.stdout.readline().split()
lengths = proc.stdout.readline().split()
rows.sort(key=lambda row: (row[2], row[5], 0 - int(row[4])))
table = prettytable.PrettyTable(headings)
for r in rows:
table.add_row(r)
print table
if __name__ == '__main__':
sys.exit(main())
$ ovn-pipeline.py
+--------------------------------------+-----------------------------------------------------------------+--------------------------------------+--------------------------------------------------------------+----------+----------+
| _uuid | actions | logical_datapath | match | priority | table_id |
+--------------------------------------+-----------------------------------------------------------------+--------------------------------------+--------------------------------------------------------------+----------+----------+
| 4b016001-ae0d-4501-b8f7-845de5c8926f | "drop;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "eth.src[40]" | 100 | 0 |
| fb902ce2-986f-4f3b-b748-092b22965e24 | "drop;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | vlan.present | 100 | 0 |
| 7e9f2159-e6b2-4cfc-98fa-98b6eb4b9bf9 | "next;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "inport == \"sw1-port1\" && eth.src == {00:00:00:00:00:03}" | 50 | 0 |
| 1c8c5944-28ef-4dcd-ab96-c22cb05daa19 | "next;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "inport == \"sw1-port2\" && eth.src == {00:00:00:00:00:04}" | 50 | 0 |
| f70902eb-1a7e-4df4-a1aa-9a566eb9ba5b | "drop;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "1" | 0 | 0 |
| f89fa154-f9cd-4328-b061-9fb5473cfe90 | "outport = \"sw1-port2\"; next; outport = \"sw1-port1\"; next;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "eth.dst[40]" | 100 | 1 |
| 3be52018-c527-4239-9cb6-9f0d7cadbd93 | "outport = \"sw1-port1\"; next;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "eth.dst == 00:00:00:00:00:03" | 50 | 1 |
| 671def3f-bb28-4039-9d63-415302547c68 | "outport = \"sw1-port2\"; next;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "eth.dst == 00:00:00:00:00:04" | 50 | 1 |
| c7ddce2b-74cb-4f5b-bea5-ce09fdb75fa5 | "" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "1" | 0 | 1 |
| 4aa7bf90-c9c8-4e31-85a8-88e0b9d537e0 | "next;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "1" | 0 | 2 |
| 24c75671-a6f1-4a17-9035-5d1383023607 | "output;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "eth.dst[40]" | 100 | 3 |
| 0ee6d3ba-2107-4902-94f5-2299ab4117d4 | "output;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "outport == \"sw1-port1\" && eth.dst == {00:00:00:00:00:03}" | 50 | 3 |
| 32e14422-6fd7-4eba-9c72-98010d527e8f | "output;" | 2f7d1616-fc16-40f3-ae46-baea98bb33d4 | "outport == \"sw1-port2\" && eth.dst == {00:00:00:00:00:04}" | 50 | 3 |
| bef8f79c-a473-47f2-b533-675aa1f3d1d0 | "drop;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "eth.src[40]" | 100 | 0 |
| cba1f1bc-a69e-410f-9501-cf83a8c9c873 | "drop;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | vlan.present | 100 | 0 |
| dd39220d-fb26-42ee-8412-e329014b9406 | "next;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "inport == \"sw0-port1\" && eth.src == {00:00:00:00:00:01}" | 50 | 0 |
| cfc25190-78cf-4487-a37a-f712469981ab | "next;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "inport == \"sw0-port2\" && eth.src == {00:00:00:00:00:02}" | 50 | 0 |
| d3071e43-ddc8-4796-8d7b-567884c90ed1 | "drop;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "1" | 0 | 0 |
| 6f5ab097-70b8-481b-adfd-7eda058fc869 | "outport = \"sw0-port2\"; next; outport = \"sw0-port1\"; next;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "eth.dst[40]" | 100 | 1 |
| a068c36d-5de2-4059-a976-6c04bd6608d4 | "outport = \"sw0-port1\"; next;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "eth.dst == 00:00:00:00:00:01" | 50 | 1 |
| 3dac1b4c-a44e-422e-b7e7-eff1543762f4 | "outport = \"sw0-port2\"; next;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "eth.dst == 00:00:00:00:00:02" | 50 | 1 |
| 450025bf-3c1e-45cd-b0f8-c77b0115c30e | "" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "1" | 0 | 1 |
| 92bf3543-1381-418e-b3a3-1d11cab47b72 | "next;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "1" | 0 | 2 |
| b94938ff-594f-4575-ad21-4ae487436106 | "output;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "eth.dst[40]" | 100 | 3 |
| d0fdbf30-4d6d-4e8f-9814-bc5b9799a585 | "output;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "outport == \"sw0-port1\" && eth.dst == {00:00:00:00:00:01}" | 50 | 3 |
| e419494d-ed8b-4a80-b1f6-5b87a7427027 | "output;" | d52118a1-c5f5-454f-8c9d-1deae1a79053 | "outport == \"sw0-port2\" && eth.dst == {00:00:00:00:00:02}" | 50 | 3 |
+--------------------------------------+-----------------------------------------------------------------+--------------------------------------+--------------------------------------------------------------+----------+----------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment