cli: add support for printing veth pair

They have link set in there json data from ip link show.

Signed-off-by: Richard Alpe <richard@bit42.se>
This commit is contained in:
Richard Alpe
2023-11-06 20:10:43 +01:00
committed by Joachim Wiberg
parent c0a1c7f259
commit 429e1463af
2 changed files with 162 additions and 0 deletions
+24
View File
@@ -86,6 +86,9 @@ class Iface:
def is_bridge(self):
return self.data['type'] == "infix-if-type:bridge"
def is_veth(self):
return self.data['type'] == "infix-if-type:veth"
def pr_name(self, pipe=""):
print(f"{pipe}{self.name:<{Pad.iface - len(pipe)}}", end="")
@@ -137,6 +140,20 @@ class Iface:
lower.pr_name(pipe)
lower.pr_proto_eth()
def pr_veth(self, _ifaces):
self.pr_name(pipe="")
self.pr_proto_eth()
if self.lower_if:
row = f"{'':<{Pad.iface}}"
row += f"{'veth':<{Pad.proto}}"
row += f"{'':<{Pad.state}}"
row += f"peer:{self.lower_if}"
print(row)
self.pr_proto_ipv4()
self.pr_proto_ipv6()
def pr_vlan(self, _ifaces):
self.pr_name(pipe="")
self.pr_proto_eth()
@@ -164,6 +181,9 @@ class Iface:
if self.oper_status:
print(f"{'operational status':<{20}}: {self.oper_status}")
if self.lower_if:
print(f"{'lower-layer-if':<{20}}: {self.lower_if}")
if self.autoneg != 'unknown':
val = "on" if self.autoneg else "off"
print(f"{'auto-negotiation':<{20}}: {val}")
@@ -232,6 +252,10 @@ def pr_interface_list(json):
iface.pr_bridge(ifaces)
continue
if iface.is_veth():
iface.pr_veth(ifaces)
continue
if iface.is_vlan():
iface.pr_vlan(ifaces)
continue
+138
View File
@@ -383,6 +383,144 @@
"vlan-id": 10
}
}
},
{
"TEST-DESCR": "veth pair with minimal data",
"name": "veth0c",
"type": "infix-if-type:veth",
"oper-status": "up",
"if-index": 13,
"phys-address": "8a:f9:5e:d3:0c:80",
"statistics": {
"in-octets": "488",
"out-octets": "488"
},
"ieee802-ethernet-interface:ethernet": {
"auto-negotiation": {
"enable": false
}
},
"ietf-ip:ipv4": {
"mtu": 1500
},
"ietf-ip:ipv6": {
"mtu": 1500
},
"infix-interfaces:vlan": {
"lower-layer-if": "veth0b"
}
},
{
"TEST-DESCR": "veth pair with minimal data",
"name": "veth0d",
"type": "infix-if-type:veth",
"oper-status": "up",
"if-index": 13,
"phys-address": "8a:f9:5e:d3:0c:81",
"statistics": {
"in-octets": "488",
"out-octets": "488"
},
"ieee802-ethernet-interface:ethernet": {
"auto-negotiation": {
"enable": false
}
},
"ietf-ip:ipv4": {
"mtu": 1500
},
"ietf-ip:ipv6": {
"mtu": 1500
},
"infix-interfaces:vlan": {
"lower-layer-if": "veth0b"
}
},
{
"name": "veth0a",
"type": "infix-if-type:veth",
"oper-status": "up",
"if-index": 13,
"phys-address": "8a:f9:5e:d3:0c:32",
"statistics": {
"in-octets": "488",
"out-octets": "488"
},
"ieee802-ethernet-interface:ethernet": {
"auto-negotiation": {
"enable": false
}
},
"ietf-ip:ipv4": {
"mtu": 1500,
"address": [
{
"ip": "192.168.1.1",
"prefix-length": 24,
"origin" : "static"
},
{
"ip": "192.168.2.1",
"prefix-length": 24,
"origin" : "static"
}
]
},
"ietf-ip:ipv6": {
"mtu": 1500,
"address": [
{
"ip": "fe80::beff:407a:d738:aaaa",
"prefix-length": 64,
"origin": "link-layer"
},
{
"ip": "fe80::beff:aaaa:d738:aaab",
"prefix-length": 64,
"origin": "random"
}
]
},
"infix-interfaces:vlan": {
"lower-layer-if": "veth0b"
}
},
{
"name": "veth0b",
"type": "infix-if-type:veth",
"oper-status": "up",
"if-index": 13,
"phys-address": "8a:f9:5e:d3:0c:32",
"statistics": {
"in-octets": "488",
"out-octets": "488"
},
"ieee802-ethernet-interface:ethernet": {
"auto-negotiation": {
"enable": false
}
},
"ietf-ip:ipv4": {
"mtu": 1500
},
"ietf-ip:ipv6": {
"mtu": 1500,
"address": [
{
"ip": "fe80::beff:407a:d738:aaac",
"prefix-length": 64,
"origin": "link-layer"
},
{
"ip": "fe80::beff:aaaa:d738:aaad",
"prefix-length": 64,
"origin": "random"
}
]
},
"infix-interfaces:vlan": {
"lower-layer-if": "veth0a"
}
}
]
}