summaryrefslogtreecommitdiffhomepage
path: root/cli
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-29 17:54:17 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-29 17:54:17 +0900
commitcab5edcacf7cacc9a0d4a0d7aa62ad512092d22f (patch)
tree02d5a99f0143dfb473f04d9982e26d3635b35f23 /cli
parented699a962400b6c8703c2f435bd231eacc290222 (diff)
cli: adjust tab length for show neighbors
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'cli')
-rwxr-xr-xcli/gobgpcli37
1 files changed, 28 insertions, 9 deletions
diff --git a/cli/gobgpcli b/cli/gobgpcli
index 90ed8c3f..b14a1e49 100755
--- a/cli/gobgpcli
+++ b/cli/gobgpcli
@@ -141,8 +141,33 @@ class Show(object):
if self.options.debug:
print neighbors
return 0
- print("{:40s} {:5s} {:13s} {:8s} |#{:8s} {:8s} {:8s}".format("Peer", "AS", "Up/Down", "State", "Advertised", "Received", "Accepted"))
+ sorted_neighbors = []
+ maxaddrlen = 0
+ maxaslen = 0
+ maxtimelen = 0
+ maxtimelen = 0
for n in sorted(neighbors, key=lambda n: n["conf"]["remote_ip"]):
+ sorted_neighbors.append(n)
+ if len(n["conf"]["remote_ip"]) > maxaddrlen:
+ maxaddrlen = len(n["conf"]["remote_ip"])
+ if len(str(n["conf"]["remote_as"])) > maxaslen:
+ maxaslen = len(str(n["conf"]["remote_as"]))
+
+ s = n["info"]["bgp_state"]
+ if n["info"]["uptime"] == 0:
+ t = "never"
+ elif s == "BGP_FSM_ESTABLISHED":
+ t = self.format_timedelta(n["info"]["uptime"])
+ else:
+ t = self.format_timedelta(n["info"]["downtime"])
+ if len(str(t)) > maxtimelen:
+ maxtimelen = len(str(t))
+ n["info"]["time"] = t
+
+ h = "{:%ds} {:%ds} {:%ds} {:8s} |" % (maxaddrlen, maxaslen, maxtimelen)
+ f1 = h + "#{:8s} {:8s} {:8s}"
+ print(f1.format("Peer", "AS", "Up/Down", "State", "Advertised", "Received", "Accepted"))
+ for n in sorted_neighbors:
s = n["info"]["bgp_state"]
if s == "BGP_FSM_IDLE":
state = "Idle"
@@ -157,14 +182,8 @@ class Show(object):
elif s == "BGP_FSM_ESTABLISHED":
state = "Establ"
- if n["info"]["uptime"] == 0:
- t = "never"
- elif s == "BGP_FSM_ESTABLISHED":
- t = self.format_timedelta(n["info"]["uptime"])
- else:
- t = self.format_timedelta(n["info"]["downtime"])
-
- print("{:40s} {:5d} {:13s} {:8s} | {:>8d} {:>8d} {:>8d}".format(n["conf"]["remote_ip"], n["conf"]["remote_as"], t, state, n["info"]["Advertized"], n["info"]["Received"], n["info"]["Accepted"]))
+ f2 = h + " {:>8d} {:>8d} {:>8d}"
+ print f2.format(n["conf"]["remote_ip"], str(n["conf"]["remote_as"]), n["info"]["time"], state, n["info"]["Advertized"], n["info"]["Received"], n["info"]["Accepted"])
return 0
def _format_attrs(self, attrlist):