def linux_interfaces(): ''' Obtain interface information for *NIX/BSD variants ''' ifaces = dict() ip_path = salt.utils.which('ip') ifconfig_path = None if ip_path else salt.utils.which('ifconfig') if ip_path: cmd1 = subprocess.Popen( '{0} link show'.format(ip_path), shell=True, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0] cmd2 = subprocess.Popen( '{0} addr show'.format(ip_path), shell=True, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0] ifaces = _interfaces_ip("{0}\n{1}".format( salt.utils.to_str(cmd1), salt.utils.to_str(cmd2))) elif ifconfig_path: cmd = subprocess.Popen( '{0} -a'.format(ifconfig_path), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0] ifaces = _interfaces_ifconfig(salt.utils.to_str(cmd)) return ifaces
def _osarch(): ''' Get the os architecture using rpm --eval ''' ret = subprocess.Popen('rpm --eval "%{_host_cpu}"', shell=True, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] return ret or 'unknown'
def _hw_addr_aix(iface): ''' Return the hardware address (a.k.a. MAC address) for a given interface on AIX MAC address not available in through interfaces ''' cmd = subprocess.Popen( 'entstat -d {0} | grep \'Hardware Address\''.format(iface), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0] if cmd: comps = cmd.split(' ') if len(comps) == 3: mac_addr = comps[2].strip('\'').strip() return mac_addr error_msg = ('Interface "{0}" either not available or does not contain a hardware address'.format(iface)) log.error(error_msg) return error_msg