added net client get ifindex and mac functions
This commit is contained in:
parent
bab5c75cb9
commit
c5ce85b235
2 changed files with 23 additions and 10 deletions
|
@ -678,16 +678,9 @@ class CoreNode(CoreNodeBase):
|
||||||
veth.name = ifname
|
veth.name = ifname
|
||||||
|
|
||||||
if self.up:
|
if self.up:
|
||||||
# TODO: potentially find better way to query interface ID
|
flow_id = self.node_net_client.get_ifindex(veth.name)
|
||||||
# retrieve interface information
|
veth.flow_id = int(flow_id)
|
||||||
output = self.node_net_client.device_show(veth.name)
|
logging.info("interface flow index: %s - %s", veth.name, veth.flow_id)
|
||||||
logging.debug("interface command output: %s", output)
|
|
||||||
output = output.split("\n")
|
|
||||||
veth.flow_id = int(output[0].strip().split(":")[0]) + 1
|
|
||||||
logging.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
|
|
||||||
# TODO: mimic packed hwaddr
|
|
||||||
# veth.hwaddr = MacAddress.from_string(output[1].strip().split()[1])
|
|
||||||
logging.debug("interface mac: %s - %s", veth.name, veth.hwaddr)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# add network interface to the node. If unsuccessful, destroy the
|
# add network interface to the node. If unsuccessful, destroy the
|
||||||
|
|
|
@ -91,6 +91,26 @@ class LinuxNetClient(object):
|
||||||
"""
|
"""
|
||||||
return self.run(f"{IP_BIN} link show {device}")
|
return self.run(f"{IP_BIN} link show {device}")
|
||||||
|
|
||||||
|
def get_mac(self, device):
|
||||||
|
"""
|
||||||
|
Retrieve MAC address for a given device.
|
||||||
|
|
||||||
|
:param str device: device to get mac for
|
||||||
|
:return: MAC address
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return self.run(f"cat /sys/class/net/{device}/address")
|
||||||
|
|
||||||
|
def get_ifindex(self, device):
|
||||||
|
"""
|
||||||
|
Retrieve ifindex for a given device.
|
||||||
|
|
||||||
|
:param str device: device to get ifindex for
|
||||||
|
:return: ifindex
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return self.run(f"cat /sys/class/net/{device}/ifindex")
|
||||||
|
|
||||||
def device_ns(self, device, namespace):
|
def device_ns(self, device, namespace):
|
||||||
"""
|
"""
|
||||||
Set netns for a device.
|
Set netns for a device.
|
||||||
|
|
Loading…
Add table
Reference in a new issue