Example #1
0
    def update(self, iterable, flags=0):
        """
        Update the contents of this IP set with the union of itself and
        other IP set.

        :param iterable: an iterable containing IP addresses and subnets.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the netaddr.core namespace documentation
            for supported constant values.

        """
        if isinstance(iterable, IPSet):
            self._cidrs = dict.fromkeys((ip for ip in cidr_merge(
                _dict_keys(self._cidrs) + _dict_keys(iterable._cidrs))), True)
            return
        elif isinstance(iterable, (IPNetwork, IPRange)):
            self.add(iterable)
            return

        if not hasattr(iterable, '__iter__'):
            raise TypeError('an iterable was expected!')
        #   An iterable containing IP addresses or subnets.
        mergeable = []
        for addr in iterable:
            if isinstance(addr, _int_type):
                addr = IPAddress(addr, flags=flags)
            mergeable.append(addr)

        for cidr in cidr_merge(_dict_keys(self._cidrs) + mergeable):
            self._cidrs[cidr] = True

        self.compact()
Example #2
0
    def update(self, iterable, flags=0):
        """
        Update the contents of this IP set with the union of itself and
        other IP set.

        :param iterable: an iterable containing IP addresses and subnets.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the netaddr.core namespace documentation
            for supported constant values.

        """
        if isinstance(iterable, IPSet):
            self._cidrs = dict.fromkeys(
                (ip for ip in cidr_merge(_dict_keys(self._cidrs)
                                         + _dict_keys(iterable._cidrs))), True)
            return
        elif isinstance(iterable, (IPNetwork, IPRange)):
            self.add(iterable)
            return

        if not hasattr(iterable, '__iter__'):
            raise TypeError('an iterable was expected!')
        #   An iterable containing IP addresses or subnets.
        mergeable = []
        for addr in iterable:
            if isinstance(addr, _int_type):
                addr = IPAddress(addr, flags=flags)
            mergeable.append(addr)

        for cidr in cidr_merge(_dict_keys(self._cidrs) + mergeable):
            self._cidrs[cidr] = True

        self.compact()
Example #3
0
File: sets.py Project: embr/nonce
    def update(self, iterable, flags=0):
        """
        Update the contents of this IP set with the union of itself and
        other IP set.

        :param iterable: an iterable containing IP addresses and subnets.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the netaddr.core namespace documentation
            for supported constant values.

        """
        if not hasattr(iterable, "__iter__"):
            raise TypeError("an iterable was expected!")

        if hasattr(iterable, "_cidrs"):
            #   Another IP set.
            for ip in cidr_merge(_dict_keys(self._cidrs) + _dict_keys(iterable._cidrs)):
                self._cidrs[ip] = True
        else:
            #   An iterable contain IP addresses or subnets.
            mergeable = []
            for addr in iterable:
                if isinstance(addr, _int_type):
                    addr = IPAddress(addr, flags=flags)
                mergeable.append(addr)

            for cidr in cidr_merge(_dict_keys(self._cidrs) + mergeable):
                self._cidrs[cidr] = True

        self.compact()
 def print_hosts_networks(self):
     for nd in shared.model.hosts:
         for x in shared.model.shared.model.hosts[nd].interfaces:
             print x.primary_ipn.ip
             print "============"
             print x.nets[x.primary_ipn]
             print "--------------"
           # 
             print cidr_merge(x.nets[x.primary_ipn])
Example #5
0
    def __init__(self, iterable=None, flags=0):
        """
        Constructor.

        :param iterable: (optional) an iterable containing IP addresses and
            subnets.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the netaddr.core namespace documentation
            for supported constant values.

        """
        if isinstance(iterable, IPNetwork):
            self._cidrs = {iterable.cidr: True}
        elif isinstance(iterable, IPRange):
            self._cidrs = dict.fromkeys(
                iprange_to_cidrs(iterable[0], iterable[-1]), True)
        elif isinstance(iterable, IPSet):
            self._cidrs = dict.fromkeys(iterable.iter_cidrs(), True)
        else:
            self._cidrs = {}
            if iterable is not None:
                mergeable = []
                for addr in iterable:
                    if isinstance(addr, _int_type):
                        addr = IPAddress(addr, flags=flags)
                    mergeable.append(addr)

                for cidr in cidr_merge(mergeable):
                    self._cidrs[cidr] = True
Example #6
0
    def __init__(self, iterable=None, flags=0):
        """
        Constructor.

        :param iterable: (optional) an iterable containing IP addresses and
            subnets.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the netaddr.core namespace documentation
            for supported constant values.

        """
        if isinstance(iterable, IPNetwork):
            self._cidrs = {iterable.cidr: True}
        elif isinstance(iterable, IPRange):
            self._cidrs = dict.fromkeys(
                iprange_to_cidrs(iterable[0], iterable[-1]), True)
        elif isinstance(iterable, IPSet):
            self._cidrs = dict.fromkeys(iterable.iter_cidrs(), True)
        else:
            self._cidrs = {}
            if iterable is not None:
                mergeable = []
                for addr in iterable:
                    if isinstance(addr, _int_type):
                        addr = IPAddress(addr, flags=flags)
                    mergeable.append(addr)

                for cidr in cidr_merge(mergeable):
                    self._cidrs[cidr] = True
Example #7
0
    def __init__(self, iterable=None):
        """
        Constructor.

        @param iterable: (optional) an iterable containing IP addresses and
            subnets.
        """
        self._cidrs = {}
        if iterable is not None:
            for ip in cidr_merge(iterable):
                self._cidrs[ip] = True
Example #8
0
    def update(self, iterable):
        """
        Update the contents of this IP set with the union of itself and
        other IP set.

        @param iterable: an iterable containing IP addresses and subnets.
        """
        if not hasattr(iterable, '__iter__'):
            raise TypeError('an iterable was expected!')

        if hasattr(iterable, '_cidrs'):
            #   Another IP set.
            for ip in cidr_merge(self._cidrs.keys() + iterable._cidrs.keys()):
                self._cidrs[ip] = True
        else:
            #   An iterable contain IP addresses or subnets.
            for ip in cidr_merge(self._cidrs.keys() + list(iterable)):
                self._cidrs[ip] = True

        self.compact()
Example #9
0
    def __init__(self, iterable=None):
        """
        Constructor.

        @param iterable: (optional) an iterable containing IP addresses and
            subnets.
        """
        self._cidrs = {}
        if iterable is not None:
            for ip in cidr_merge(iterable):
                self._cidrs[ip] = True
Example #10
0
    def update(self, iterable):
        """
        Update the contents of this IP set with the union of itself and
        other IP set.

        @param iterable: an iterable containing IP addresses and subnets.
        """
        if not hasattr(iterable, '__iter__'):
            raise TypeError('an iterable was expected!')

        if hasattr(iterable, '_cidrs'):
            #   Another IP set.
            for ip in cidr_merge(self._cidrs.keys() + iterable._cidrs.keys()):
                self._cidrs[ip] = True
        else:
            #   An iterable contain IP addresses or subnets.
            for ip in cidr_merge(self._cidrs.keys() + list(iterable)):
                self._cidrs[ip] = True

        self.compact()
 def extract_subnet(self, prefix, count=None):
     """Extract 1 or more subnets of size specified by CIDR prefix."""
     for cidr in self.available_subnets():
         subnets = list(cidr.subnet(prefix, count=count))
         if not subnets:
             continue
         self.remove_subnet(cidr)
         self._subnets = self._subnets.union(
             set(cidr_exclude(cidr,
                              cidr_merge(subnets)[0])))
         return subnets
     return []
Example #12
0
 def extract_subnet(self, prefix, count=None):
     """Extract 1 or more subnets of size specified by CIDR prefix."""
     for cidr in self.available_subnets():
         subnets = list(cidr.subnet(prefix, count=count))
         if not subnets:
             continue
         self.remove_subnet(cidr)
         self._subnets = self._subnets.union(
             set(
                 cidr_exclude(cidr, cidr_merge(subnets)[0])
             )
         )
         return subnets
     return []
Example #13
0
   def interface_networks(self):
       print " interface_networks:"
       for nd in shared.model.hosts.values():
           for x in nd.interfaces:
          # for n in model1.shared.model.hosts.itervalues():
        #       if x.primary_ipn.ip in n.ip.cidr:
               print x.primary_ipn.ip
               print "============"
               print nd.nets[x.primary_ipn]
               print "--------------"
             #  for n in x.nets[]
              #     print "hhh"
               #    print n
                #   print "--------------"    
                
                   #x.nets[x.primary_ipn].append(n.ip)
               #
          #  ip_list = [ ip for ip in x.nets.itervalues()]
  # ip = IPNetwork('192.0.2.16/29')
 #  ip_list = [IPAddress('192.0.2.130'), IPAddress('10.0.0.1'), IPNetwork('192.0.2.128/28'), IPNetwork('192.0.3.0/24'), IPNetwork('192.0.2.0/24'), IPNetwork('fe80::/64'), IPAddress('::'), IPNetwork('172.24/12')]
  # ip_list = list(iter_iprange('192.0.2.1', '192.0.2.14'))
               print " merge"
               print cidr_merge(nd.nets[x.primary_ipn])
Example #14
0
    def __init__(self, iterable=None, flags=0):
        """
        Constructor.

        :param iterable: (optional) an iterable containing IP addresses and
            subnets.

        :param flags: decides which rules are applied to the interpretation
            of the addr value. See the netaddr.core namespace documentation
            for supported constant values.

        """
        self._cidrs = {}
        if iterable is not None:
            mergeable = []
            for addr in iterable:
                if isinstance(addr, _int_type):
                    addr = IPAddress(addr, flags=flags)
                mergeable.append(addr)

            for cidr in cidr_merge(mergeable):
                self._cidrs[cidr] = True
Example #15
0
    def __init__(self, iterable=None, flags=0):
        """
        Constructor.

        @param iterable: (optional) an iterable containing IP addresses and
            subnets.

        @param flags: decides which rules are applied to the interpretation
            of the addr value. See the netaddr.core namespace documentation
            for supported constant values.

        """
        self._cidrs = {}
        if iterable is not None:
            mergeable = []
            for addr in iterable:
                if isinstance(addr, _int_type):
                    addr = IPAddress(addr, flags=flags)
                mergeable.append(addr)

            for cidr in cidr_merge(mergeable):
                self._cidrs[cidr] = True
Example #16
0
 def compact(self):
     """
     Compact internal list of `IPNetwork` objects using a CIDR merge.
     """
     cidrs = cidr_merge(self._cidrs)
     self._cidrs = dict.fromkeys(cidrs, True)
Example #17
0
 def compact(self):
     """
     Compact internal list of `IPNetwork` objects using a CIDR merge.
     """
     cidrs = cidr_merge(self._cidrs)
     self._cidrs = dict.fromkeys(cidrs, True)
Example #18
0
 def compact(self):
     """
     Compact internal list of L{IPNetwork} objects using a CIDR merge.
     """
     cidrs = cidr_merge(list(self._cidrs))
     self._cidrs = dict(zip(cidrs, [True] * len(cidrs)))
Example #19
0
 def compact(self):
     """
     Compact internal list of `IPNetwork` objects using a CIDR merge.
     """
     cidrs = cidr_merge(list(self._cidrs))
     self._cidrs = dict(_zip(cidrs, [True] * len(cidrs)))