Return Fibre Channel port WWNs from a Linux host.
761016
def _linux_wwns():
    '''
    
    '''
    ret = []
    for fc_file in glob.glob('/sys/class/fc_host/*/port_name'):
        with salt.utils.files.fopen(fc_file, 'r') as _wwn:
            content = _wwn.read()
            for line in content.splitlines():
                ret.append(line.rstrip()[2:])
    return ret
836316
def _mksocket(host, port, q, done, stop):
    """"""
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(2)
    attempt = 0
    while not stop.is_set():
        try:
            s.connect((host, port))
            return s
        except Exception as ex:
            # Simple exponential backoff: sleep for 1,2,4,8,16,30,30...
            time.sleep(min(30, 2 ** attempt))
            attempt += 1
729733
def inet_ntop(af, addr):
    """"""
    # Use inet_ntop if available
    addr = bytes_encode(addr)
    try:
        return socket.inet_ntop(af, addr)
    except AttributeError:
        try:
            return _INET_NTOP[af](addr)
        except KeyError:
            raise ValueError("unknown address family %d" % af)
1144024
def hostaddr(dest='8.8.8.8'):
    '''
    
    '''
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    # doesn't actually send any packets!
    sock.connect((dest, 80))
    addr, port = sock.getsockname()

    sock.close()

    return addr
743643
def _get_machines_cache_from_dns(self, host, port):
        """"""
        if self.protocol == 'http':
            ret = []
            for af, _, _, _, sa in self._dns_resolver.resolve(host, port):
                host, port = sa[:2]
                if af == socket.AF_INET6:
                    host = '[{0}]'.format(host)
                ret.append(uri(self.protocol, host, port))
            if ret:
                return list(set(ret))
        return [uri(self.protocol, host, port)]
517670
def get_open_port(host="localhost"):
    
    temp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    temp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    temp_sock.bind((host, 0))
    port = temp_sock.getsockname()[1]
    temp_sock.close()
    del temp_sock
    return port
657272
def _get_binary_from_ipv6(self, ip_addr):
        """"""

        hi, lo = struct.unpack("!QQ", socket.inet_pton(socket.AF_INET6,
                                                       ip_addr))
        return (hi << 64) | lo
1106810
def wploader(self):
        ''''''
        if self.target_system not in self.wploader_by_sysid:
            self.wploader_by_sysid[self.target_system] = mavwp.MAVWPLoader()
        return self.wploader_by_sysid[self.target_system]
1078250
def in6_getifaddr():
    
    ret = []
    try:
        fdesc = open("/proc/net/if_inet6", "rb")
    except IOError:
        return ret
    for line in fdesc:
        # addr, index, plen, scope, flags, ifname
        tmp = plain_str(line).split()
        addr = scapy.utils6.in6_ptop(
            b':'.join(
                struct.unpack('4s4s4s4s4s4s4s4s', tmp[0].encode())
            ).decode()
        )
        # (addr, scope, iface)
        ret.append((addr, int(tmp[3], 16), tmp[5]))
    fdesc.close()
    return ret
43751
def requestSocket(self, host, port):
        '''
        
        '''
        socket = self._context.socket(zmq.REQ)
        socket.connect(self.tcpAddress(host, port))
        return socket
638018
def unpack_ip_addr(addr):
    """"""
    if isinstance(addr, bytearray):
        addr = bytes(addr)
    return (socket.inet_ntoa(addr[0:4]), struct.unpack('!H', addr[4:6])[0])
1162266
def get_free_udp_port():
    '''
    
    '''
    import socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(('localhost', 0))
    addr = sock.getsockname()
    sock.close()
    return addr[1]
1255181
def bind_domain_socket(address):
    """"""
    path, _ = address
    try:
        os.unlink(path)
    except OSError:
        pass

    sock = socket.socket(socket.AF_UNIX)
    sock.bind(path)
    sock.listen(128)
    return sock, (path, 0)
1324664
def client_port(self):
        """"""
        address = self._client.getpeername()
        if isinstance(address, tuple):
            return address[1]

        # Maybe a Unix domain socket connection.
        return 0
259409
def _get_channel(host, timeout):
    
    connection = create_blocking_connection(host)

    # register timeout
    if timeout >= 0:
        connection.add_timeout(
            timeout,
            lambda: sys.stderr.write("Timeouted!\n") or sys.exit(1)
        )

    return connection.channel()
480453
def hwif(self, as_private=False):
        """"""
        return self._network.bip32_as_string(self.serialize(as_private=as_private), as_private=as_private)
155679
def get_port_switch_bindings(port_id, switch_ip):
    """"""
    LOG.debug("get_port_switch_bindings() called, "
              "port:'%(port_id)s', switch:'%(switch_ip)s'",
              {'port_id': port_id, 'switch_ip': switch_ip})
    try:
        return _lookup_all_nexus_bindings(port_id=port_id,
                                          switch_ip=switch_ip)
    except c_exc.NexusPortBindingNotFound:
        pass