Return LLDP neighbors details.
489692
def get_lldp_neighbors(self):
        """"""
        lldp = junos_views.junos_lldp_table(self.device)
        try:
            lldp.get()
        except RpcError as rpcerr:
            # this assumes the library runs in an environment
            # able to handle logs
            # otherwise, the user just won't see this happening
            log.error('Unable to retrieve the LLDP neighbors information:')
            log.error(rpcerr.message)
            return {}
        result = lldp.items()

        neighbors = {}
        for neigh in result:
            if neigh[0] not in neighbors.keys():
                neighbors[neigh[0]] = []
            neighbors[neigh[0]].append({x[0]: py23_compat.text_type(x[1]) for x in neigh[1]})

        return neighbors
542391
def parents(self, p_todo, p_only_direct=False):
        
        parents = self._depgraph.incoming_neighbors(
            hash(p_todo), not p_only_direct)
        return [self._tododict[parent] for parent in parents]
365262
def out_filter_get(self, address):
        

        func_name = 'neighbor.out_filter.get'
        param = {
            neighbors.IP_ADDRESS: address,
        }

        return call(func_name, **param)
661792
def get_bgp_neighbors(self):
        """"""
        bgp_neighbor_data = {}
        default_neighbor_details = {
            'local_as': 0,
            'remote_as': 0,
            'remote_id': '',
            'is_up': False,
            'is_enabled': False,
            'description': '',
            'uptime': 0,
            'address_family': {}
        }
        keys = default_neighbor_details.keys()

        uptime_table = junos_views.junos_bgp_uptime_table(self.device)
        bgp_neighbors_table = junos_views.junos_bgp_table(self.device)

        uptime_table_lookup = {}

        def _get_uptime_table(instance):
            if instance not in uptime_table_lookup:
                uptime_table_lookup[instance] = uptime_table.get(instance=instance).items()
            return uptime_table_lookup[instance]

        def _get_bgp_neighbors_core(neighbor_data, instance=None, uptime_table_items=None):
            '''
            Make sure to execute a simple request whenever using
            junos > 13. This is a helper used to avoid code redundancy
            and reuse the function also when iterating through the list
            BGP neighbors under a specific routing instance,
            also when the device is capable to return the routing
            instance name at the BGP neighbor level.
            '''
            for bgp_neighbor in neighbor_data:
                peer_ip = napalm_base.helpers.ip(bgp_neighbor[0].split('+')[0])
                neighbor_details = deepcopy(default_neighbor_details)
                neighbor_details.update(
                    {elem[0]: elem[1] for elem in bgp_neighbor[1] if elem[1] is not None}
                )
                if not instance:
                    # not instance, means newer Junos version,
                    # as we request everything in a single request
                    peer_fwd_rti = neighbor_details.pop('peer_fwd_rti')
                    instance = peer_fwd_rti
                else:
                    # instance is explicitly requests,
                    # thus it's an old Junos, so we retrieve the BGP neighbors
                    # under a certain routing instance
                    peer_fwd_rti = neighbor_details.pop('peer_fwd_rti', '')
                instance_name = 'global' if instance == 'master' else instance
                if instance_name not in bgp_neighbor_data:
                    bgp_neighbor_data[instance_name] = {}
                if 'router_id' not in bgp_neighbor_data[instance_name]:
                    # we only need to set this once
                    bgp_neighbor_data[instance_name]['router_id'] = \
                        py23_compat.text_type(neighbor_details.get('local_id', ''))
                peer = {
                    key: self._parse_value(value)
                    for key, value in neighbor_details.items()
                    if key in keys
                }
                peer['local_as'] = napalm_base.helpers.as_number(peer['local_as'])
                peer['remote_as'] = napalm_base.helpers.as_number(peer['remote_as'])
                peer['address_family'] = self._parse_route_stats(neighbor_details)
                if 'peers' not in bgp_neighbor_data[instance_name]:
                    bgp_neighbor_data[instance_name]['peers'] = {}
                bgp_neighbor_data[instance_name]['peers'][peer_ip] = peer
                if not uptime_table_items:
                    uptime_table_items = _get_uptime_table(instance)
                for neighbor, uptime in uptime_table_items:
                    if neighbor not in bgp_neighbor_data[instance_name]['peers']:
                        bgp_neighbor_data[instance_name]['peers'][neighbor] = {}
                    bgp_neighbor_data[instance_name]['peers'][neighbor]['uptime'] = uptime[0][1]

        # Commenting out the following sections, till Junos
        #   will provide a way to identify the routing instance name
        #   from the details of the BGP neighbor
        #   currently, there are Junos 15 version having a field called `peer_fwd_rti`
        #   but unfortunately, this is not consistent.
        # Junos 17 might have this fixed, but this needs to be revisited later.
        # In the definition below, `old_junos` means a version that does not provide
        #   the forwarding RTI information.
        #
        # old_junos = napalm_base.helpers.convert(
        #     int, self.device.facts.get('version', '0.0').split('.')[0], 0) < 15

        # if old_junos:
        instances = junos_views.junos_route_instance_table(self.device).get()
        for instance, instance_data in instances.items():
            if instance.startswith('__'):
                # junos internal instances
                continue
            bgp_neighbor_data[instance] = {'peers': {}}
            instance_neighbors = bgp_neighbors_table.get(instance=instance).items()
            uptime_table_items = uptime_table.get(instance=instance).items()
            _get_bgp_neighbors_core(instance_neighbors,
                                    instance=instance,
                                    uptime_table_items=uptime_table_items)
        # If the OS provides the `peer_fwd_rti` or any way to identify the
        #   rotuing instance name (see above), the performances of this getter
        #   can be significantly improved, as we won't execute one request
        #   for each an every RT.
        # However, this improvement would only be beneficial for multi-VRF envs.
        #
        # else:
        #     instance_neighbors = bgp_neighbors_table.get().items()
        #     _get_bgp_neighbors_core(instance_neighbors)
        bgp_tmp_dict = {}
        for k, v in bgp_neighbor_data.items():
            if bgp_neighbor_data[k]['peers']:
                bgp_tmp_dict[k] = v
        return bgp_tmp_dict
1065726
def get_lldp_neighbors_detail(self, interface=""):
        """"""
        lldp_neighbors = defaultdict(list)
        lldp_table = junos_views.junos_lldp_neighbors_detail_table(self.device)
        if not interface:
            try:
                lldp_table.get()
            except RpcError as rpcerr:
                # this assumes the library runs in an environment
                # able to handle logs
                # otherwise, the user just won't see this happening
                log.error("Unable to retrieve the LLDP neighbors information:")
                log.error(py23_compat.text_type(rpcerr))
                return {}
            interfaces = lldp_table.get().keys()
        else:
            interfaces = [interface]

        if self.device.facts.get("switch_style") == "VLAN":
            lldp_table.GET_RPC = "get-lldp-interface-neighbors-information"
            interface_variable = "interface_name"
            alt_rpc = "get-lldp-interface-neighbors"
            alt_interface_variable = "interface_device"
        else:
            lldp_table.GET_RPC = "get-lldp-interface-neighbors"
            interface_variable = "interface_device"
            alt_rpc = "get-lldp-interface-neighbors-information"
            alt_interface_variable = "interface_name"

        for interface in interfaces:
            try:
                interface_args = {interface_variable: interface}
                lldp_table.get(**interface_args)
            except RpcError as e:
                if "syntax error" in e.message:
                    # Looks like we need to call a different RPC on this device
                    # Switch to the alternate style
                    lldp_table.GET_RPC = alt_rpc
                    interface_variable = alt_interface_variable
                    # Retry
                    interface_args = {interface_variable: interface}
                    lldp_table.get(**interface_args)

            for item in lldp_table:
                lldp_neighbors[interface].append(
                    {
                        "parent_interface": item.parent_interface,
                        "remote_port": item.remote_port or "",
                        "remote_chassis_id": napalm.base.helpers.convert(
                            napalm.base.helpers.mac,
                            item.remote_chassis_id,
                            item.remote_chassis_id,
                        ),
                        "remote_port_description": napalm.base.helpers.convert(
                            py23_compat.text_type, item.remote_port_description
                        ),
                        "remote_system_name": item.remote_system_name,
                        "remote_system_description": item.remote_system_description,
                        "remote_system_capab": self._transform_lldp_capab(
                            item.remote_system_capab
                        ),
                        "remote_system_enable_capab": self._transform_lldp_capab(
                            item.remote_system_enable_capab
                        ),
                    }
                )

        return lldp_neighbors
162832
def neighbors2(self, distance, chain_residue, atom = None, resid_list = None):

        #atom = " CA "
        ''''''

        if atom == None:     # consider all atoms
            lines = [line for line in self.atomlines(resid_list) if line[17:20] in allowed_PDB_residues_types]
        else:                # consider only given atoms
            lines = [line for line in self.atomlines(resid_list) if line[17:20] in allowed_PDB_residues_types and line[12:16] == atom]

        shash = spatialhash.SpatialHash(distance)

        for line in lines:
            pos = (float(line[30:38]), float(line[38:46]), float(line[46:54]))
            shash.insert(pos, line[21:26])

        neighbor_list = []
        for line in lines:
            resid = line[21:26]
            if resid == chain_residue:
                pos = (float(line[30:38]), float(line[38:46]), float(line[46:54]))

                for data in shash.nearby(pos, distance):
                    if data[1] not in neighbor_list:
                        neighbor_list.append(data[1])
                neighbor_list.sort()
        return neighbor_list
42877
def get_lldp_neighbors(self):
        """"""
        lldp = {}
        neighbors_detail = self.get_lldp_neighbors_detail()
        for intf_name, entries in neighbors_detail.items():
            lldp[intf_name] = []
            for lldp_entry in entries:
                hostname = lldp_entry["remote_system_name"]
                # Match IOS behaviour of taking remote chassis ID
                # When lacking a system name (in show lldp neighbors)
                if hostname == "N/A":
                    hostname = lldp_entry["remote_chassis_id"]
                lldp_dict = {"port": lldp_entry["remote_port"], "hostname": hostname}
                lldp[intf_name].append(lldp_dict)

        return lldp
1068030
def relations_for_id(relid=None):
    """"""
    relation_data = []
    relid = relid or relation_ids()
    for unit in related_units(relid):
        unit_data = relation_for_unit(unit, relid)
        unit_data['__relid__'] = relid
        relation_data.append(unit_data)
    return relation_data
1088739
def load_neighbour_info(self, cache_dir, mask=None, **kwargs):
        """"""
        mask_name = getattr(mask, 'name', None)
        filename = self._create_cache_filename(cache_dir,
                                               mask=mask_name, **kwargs)
        if kwargs.get('mask') in self._index_caches:
            self._apply_cached_indexes(self._index_caches[kwargs.get('mask')])
        elif cache_dir:
            cache = np.load(filename, mmap_mode='r')
            # copy the dict so we can modify it's keys
            new_cache = dict(cache.items())
            cache.close()
            self._apply_cached_indexes(new_cache)  # modifies cache dict in-place
            self._index_caches[mask_name] = new_cache
        else:
            raise IOError
765230
def getedges(fname, iddfile):
    """"""
    data, commdct, _idd_index = readidf.readdatacommdct(fname, iddfile=iddfile)
    edges = makeairplantloop(data, commdct)
    return edges
592499
def neighbor_difference(self):
        """"""
        differences = np.zeros(self.num_neurons)
        num_neighbors = np.zeros(self.num_neurons)

        distance, _ = self.distance_function(self.weights, self.weights)
        for x, y in self.neighbors():
            differences[x] += distance[x, y]
            num_neighbors[x] += 1

        return differences / num_neighbors
198013
def get_ntp_peers(self):
        """"""
        ntp_table = junos_views.junos_ntp_peers_config_table(self.device)
        ntp_table.get()

        ntp_peers = ntp_table.items()

        if not ntp_peers:
            return {}

        return {napalm_base.helpers.ip(peer[0]): {} for peer in ntp_peers}
368039
def update(self, neighbors):
        

        data = {'neighbors': neighbors}
        neighbors_ids = [str(env.get('id')) for env in neighbors]

        return super(ApiV4Neighbor, self).put('api/v4/neighbor/%s/' %
                                               ';'.join(neighbors_ids), data)
925351
def get_ntp_peers(self):
        """"""
        ntp_stats = self.get_ntp_stats()

        return {
            ntp_peer.get("remote"): {}
            for ntp_peer in ntp_stats
            if ntp_peer.get("remote")
        }
880444
def address_info(self):
        """"""
        return {
            "node_ip_address": self._node_ip_address,
            "redis_address": self._redis_address,
            "object_store_address": self._plasma_store_socket_name,
            "raylet_socket_name": self._raylet_socket_name,
            "webui_url": self._webui_url,
        }
1058250
def get_neighbor_out_filter(neigh_ip_address):
    """"""
    core = CORE_MANAGER.get_core_service()
    ret = core.peer_manager.get_by_addr(neigh_ip_address).out_filters
    return ret
684930
def neighbors(self, key):
        """"""
        return {n: attr["bond"] for n, attr in self.graph[key].items()}