def get_ibstatus(self): """ Get ibstatus :return: """ path_netdev = ''.join(['/sys', self.device.get_property("DEVPATH")]) path_pci = path_netdev.split('net')[0] path_ibdev = 'infiniband_verbs/uverb*/ibdev' path_ibdev = ''.join([path_pci, path_ibdev]) cmd = "cat %s" % path_ibdev com = Command(cmd) try: self.ib_device = com.read() except Exception as concrete_error: print(concrete_error) return False path_ibport = '/sys/class/net/%s/dev_id' % self.interface cmd = "cat %s" % path_ibport com = Command(cmd) try: self.ib_port = int(com.read(), 16) + 1 except Exception as concrete_error: print(concrete_error) return False ib_str = "Infiniband device '%s' port %d" % (self.ib_device, self.ib_port) print("Interface %s ===> %s" % (self.interface, ib_str)) cmd = "ibstatus" print(cmd) com = Command(cmd) try: output = com.read() for info in output.split('\n\n'): if ib_str not in info: continue print(info) self.gid = re.search(r"default gid:\s+(.*)", info).group(1) self.base_lid = re.search(r"base lid:\s+(.*)", info).group(1) self.sm_lid = re.search(r"sm lid:\s+(.*)", info).group(1) self.state = re.search(r"state:\s+(.*)", info).group(1) self.phys_state = re.search(r"phys state:\s+(.*)", info).group(1) self.link_layer = re.search(r"link_layer:\s+(.*)", info).group(1) self.speed = int(re.search(r"rate:\s+(\d*)", info).group(1)) * 1024 except Exception as concrete_error: print(concrete_error) return False return True
def get_other_interfaces(self): """ Get other interfaces :return: """ ignore_interfaces = ['^lo', '^v', 'docker', 'br', 'bond'] cmd = "ip route show default | awk '/default/ {print $5}'" com = Command(cmd) management_interface = com.read() if management_interface: ignore_interfaces.append(management_interface) # print(cmd) # print("Management interface: %s" % management_interface) ignore_pattern = '|'.join(ignore_interfaces) # print(ignore_pattern) cmd = "ls /sys/class/net/ | grep -vE '%s'" % ignore_pattern # print(cmd) com = Command(cmd) try: com.run() return com.output except Exception as concrete_error: print(concrete_error) return []