added net client get ifindex and mac functions

This commit is contained in:
Blake Harnden 2019-10-18 14:22:37 -07:00
parent bab5c75cb9
commit c5ce85b235
2 changed files with 23 additions and 10 deletions

View file

@ -678,16 +678,9 @@ class CoreNode(CoreNodeBase):
veth.name = ifname
if self.up:
# TODO: potentially find better way to query interface ID
# retrieve interface information
output = self.node_net_client.device_show(veth.name)
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)
flow_id = self.node_net_client.get_ifindex(veth.name)
veth.flow_id = int(flow_id)
logging.info("interface flow index: %s - %s", veth.name, veth.flow_id)
try:
# add network interface to the node. If unsuccessful, destroy the

View file

@ -91,6 +91,26 @@ class LinuxNetClient(object):
"""
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):
"""
Set netns for a device.