def getNICNum(ipAddress): """ function: get nic num input : NA output : NA """ if g_Platform.isPlatFormEulerOSOrRHEL7X(): cmd = "/sbin/ifconfig -a | grep -B1 \"inet %s \" | " \ "grep -v \"inet %s \" | awk '{print $1}'" % ( ipAddress, ipAddress) else: cmd = "/sbin/ifconfig -a | grep -B1 \"addr:%s \" | " \ "grep -v \"addr:%s \" | awk '{print $1}'" % ( ipAddress, ipAddress) output = runShellCmd(cmd) if g_Platform.isPlatFormEulerOSOrRHEL7X(): return output.strip()[:-1] else: return output.strip()
def getMaskByIP(IPAddr): """ function: get netMask by ip addr """ if g_Platform.isPlatFormEulerOSOrRHEL7X(): cmd = "/sbin/ifconfig -a |grep -E '\<%s\>'| awk '{print $4}'" % IPAddr else: cmd = \ "/sbin/ifconfig -a |grep -E '\<%s\>'| awk -F ':' '{print $NF}'" \ % IPAddr netMask = runShellCmd(cmd) return netMask
def isBond(netWorkNum): """ function: check whether is or not bond input : NA output : NA """ bondingConfFile = "/proc/net/bonding/%s" % netWorkNum if g_Platform.isPlatFormEulerOSOrRHEL7X(): cmd = "/sbin/ifconfig %s " \ "| grep -E '\<ether\>' | awk -F ' ' '{print $2}'" % netWorkNum else: cmd = "/sbin/ifconfig %s " \ "| grep -E '\<HWaddr\>' | awk -F ' ' '{print $NF}'" % netWorkNum MacAddr = runShellCmd(cmd) cmd = "/sbin/ifconfig -a | grep '\<%s\>' | wc -l" % MacAddr output = runShellCmd(cmd) MacAddrNum = int(output) if (MacAddrNum > 2 and os.path.exists(bondingConfFile)): return True else: return False