Check another network against the given network.
439792
def check_collision(self, other):
        """"""
        other = Network(other)
        return self.network_long() <= other.network_long() <= self.broadcast_long() or \
            other.network_long() <= self.network_long() <= other.broadcast_long()
933802
def has_edge(self, node1_name, node2_name, account_for_direction=True):
        
        return self.__has_edge(node1_name=node1_name, node2_name=node2_name, account_for_direction=account_for_direction)
119841
def check_network_id(network_id, web3: Web3):
    
    while True:
        current_id = int(web3.version.network)
        if network_id != current_id:
            raise RuntimeError(
                f'Raiden was running on network with id {network_id} and it detected '
                f'that the underlying ethereum client network id changed to {current_id}.'
                f' Changing the underlying blockchain while the Raiden node is running '
                f'is not supported.',
            )
        gevent.sleep(CHECK_NETWORK_ID_INTERVAL)
269397
def _nics_equal(nic1, nic2):
    '''
    
    '''

    def _filter_nic(nic):
        '''
        Filter out elements to ignore when comparing nics
        '''
        return {
            'type': nic.attrib['type'],
            'source': nic.find('source').attrib[nic.attrib['type']] if nic.find('source') is not None else None,
            'mac': nic.find('mac').attrib['address'].lower() if nic.find('mac') is not None else None,
            'model': nic.find('model').attrib['type'] if nic.find('model') is not None else None,
        }
    return _filter_nic(nic1) == _filter_nic(nic2)
1059197
def check_network(session, configure_network, network, subnet,
                  dns_nameservers=None, allocation_pool=None):
    
    nclient = neutron.Client('2', session=session,
                             region_name=os.environ['OS_REGION_NAME'])

    # Check the security groups
    secgroups = nclient.list_security_groups()['security_groups']
    secgroup_name = SECGROUP_NAME
    if secgroup_name not in list(map(itemgetter('name'), secgroups)):
        secgroup = {'name': secgroup_name,
                    'description': 'Enos Security Group'}
        res = nclient.create_security_group({'security_group': secgroup})
        secgroup = res['security_group']
        logger.info("[neutron]: %s security group created" % secgroup_name)
        # create the rules
        tcp = {'protocol': 'tcp',
               'direction': 'ingress',
               'port_range_min': '1',
               'port_range_max': '65535',
               'security_group_id': secgroup['id']}
        icmp = {'protocol': 'icmp',
                'direction': 'ingress',
                'security_group_id': secgroup['id']}
        nclient.create_security_group_rule({'security_group_rule': tcp})
        logger.info("[neutron]: %s rule (all tcp) created" % secgroup_name)
        nclient.create_security_group_rule({'security_group_rule': icmp})
        logger.info("[neutron]: %s rule (all icmp) created" % secgroup_name)
    else:
        logger.info("[neutron]: Reusing security-groups %s " % secgroup_name)

    networks = nclient.list_networks()['networks']
    network_name = network['name']
    if network_name not in list(map(itemgetter('name'), networks)):
        network = {'name': network_name}
        res = nclient.create_network({'network': network})
        network = res['network']
        logger.info("[neutron]: %s network created" % network_name)
    else:
        network = [n for n in networks if n['name'] == network_name][0]
        logger.info("[neutron]: Reusing existing %s network", network)

    # find ext_net
    ext_net = [n for n in networks if n['router:external']]
    if len(ext_net) < 1:
        raise Exception("No external network found")
    ext_net = ext_net[0]

    subnets = nclient.list_subnets()['subnets']
    subnet_name = subnet['name']
    if (subnet_name not in list(map(itemgetter('name'), subnets))
            and configure_network):
        subnet = {'name': subnet['name'],
                  'network_id': network['id'],
                  # NOTE(msimonin): using the dns of chameleon
                  # for a generic openstack provider we should think to
                  # parameteried this or use public available dns
                  'cidr': subnet['cidr'],
                  'ip_version': 4}
        if dns_nameservers is not None:
            subnet.update({'dns_nameservers': dns_nameservers})
        if allocation_pool is not None:
            subnet.update({'allocation_pools': [allocation_pool]})

        s = nclient.create_subnet({'subnet': subnet})
        logger.debug(s)
        subnet = s['subnet']
        logger.info("[neutron]: %s subnet created" % subnet_name)
    else:
        subnet = [s for s in subnets if s['name'] == subnet_name][0]
        logger.info("[neutron]: Reusing %s subnet", subnet)

    # create a router
    routers = nclient.list_routers()
    router_name = ROUTER_NAME
    logger.debug(routers)
    router_present = router_name not in [r['name'] for r in routers['routers']]
    if (router_present and configure_network):
        router = {
            'name': router_name,
            'external_gateway_info': {
                'network_id': ext_net['id']
            }
        }
        r = nclient.create_router({'router': router})
        logger.info("[neutron]  %s router created" % router_name)
        # NOTE(msimonin): We should check the interface outside this block
        # in case the router is created but the interface is not added
        interface = {
            'subnet_id': subnet['id'].encode('UTF-8')
        }
        nclient.add_interface_router(str(r['router']['id']), interface)

    return (ext_net, network, subnet)
1155896
def hasPublicNet(self, system_name):
        

        nets_id = [net.id for net in self.networks if net.isPublic()]
        system = self.get_system_by_name(system_name)
        if system:
            i = 0
            while True:
                f = system.getFeature("net_interface.%d.connection" % i)
                if not f:
                    break
                if f.value in nets_id:
                    return True
                i += 1

        return False
1158821
def hasIP(self, ip):
        """"""

        for f in self.features:
            if (f.prop.startswith("net_interface.") and
                    f.prop.endswith(".ip") and f.value == ip):
                return True
        return False
1134635
def get_networks_by_name(self, name: str) -> List[Network]:
        """"""
        return self.session.query(Network).filter(Network.name.like(name)).all()
1281305
def _check(peers):

    ''''''

    if not isinstance(peers, list):
        return False

    for peer in peers:
        if not isinstance(peer, six.string_types):
            return False

    if not HAS_NETADDR:  # if does not have this lib installed, will simply try to load what user specified
        # if the addresses are not correctly specified, will trow error when loading the actual config
        return True

    ip_only_peers = []
    for peer in peers:
        try:
            ip_only_peers.append(six.text_type(IPAddress(peer)))  # append the str value
        except AddrFormatError:
            # if not a valid IP Address
            # will try to see if it is a nameserver and resolve it
            if not HAS_DNSRESOLVER:
                continue  # without the dns resolver cannot populate the list of NTP entities based on their nameserver
                # so we'll move on
            dns_reply = []
            try:
                # try to see if it is a valid NS
                dns_reply = dns.resolver.query(peer)
            except dns.resolver.NoAnswer:
                # no a valid DNS entry either
                return False
            for dns_ip in dns_reply:
                ip_only_peers.append(six.text_type(dns_ip))

    peers = ip_only_peers

    return True
286838
public final void connectIfNotFound(N n1, E edge, N n2) {
    if (!isConnected(n1, edge, n2)) {
      connect(n1, edge, n2);
    }
  }
54808
public static boolean isInRangeV6(byte[] network,byte[] subnet,byte[] ipAddress)
    {
    	if(network.length!=16 || subnet.length!=16 || ipAddress.length!=16)
    		return false;
    	
    	return compareByteValues(network,subnet,ipAddress);
    }
282488
def matches_pattern(self, other):
        """"""
        matches = False
        if hasattr(other, 'addr'):
            if self.addr is None or other.addr is None:
                matches = True
            else:
                matches = self.addr == other.addr
        return matches
877573
def matches_ip(self, ip):
        """"""

        # Check the cache if caching is enabled
        if self.cache is not None:
            matches_ip = self.cache.get(ip)
            if matches_ip is not None:
                return matches_ip

        # Query MongoDB to see if the IP is blacklisted
        matches_ip = IPNetwork.matches_ip(
            ip, read_preference=self.read_preference)

        # Cache the result if caching is enabled
        if self.cache is not None:
            self.cache[ip] = matches_ip

        return matches_ip
1249612
def _check_socket(self, timeout=None):
        """"""
        sock = self.sock
        available_socks = select.select([sock], [sock], [sock], timeout)
        if available_socks[2]:
            raise OSError
        return available_socks
545664
public static boolean isInRangeV4(byte[] network,byte[] subnet,byte[] ipAddress)
    {
    	if(network.length!=4 || subnet.length!=4 || ipAddress.length!=4)
    		return false;    	
    	
    	return compareByteValues(network,subnet,ipAddress);
    }
128097
def contains(self, other):
        """"""
        return self._start <= other.start and self._end >= other.end
1185399
def is_address_in_network(ip, net):
    """"""
    # http://stackoverflow.com/questions/819355/how-can-i-check-if-an-ip-is-in-a-network-in-python
    import socket
    import struct
    ipaddr = struct.unpack('=L', socket.inet_aton(ip))[0]
    netaddr, bits = net.split('/')
    if int(bits) == 0:
        return True
    net = struct.unpack('=L', socket.inet_aton(netaddr))[0]

    mask = ((2L << int(bits) - 1) - 1)

    return (ipaddr & mask) == (net & mask)