How to use the capirca.lib.nacaddr.SortAddrList function in capirca

To help you get started, we’ve selected a few capirca examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / capirca / capirca / lib / policy.py View on Github external
def cleanup(addresses, complement_addresses):
      if not optimize:
        return nacaddr.SortAddrList(addresses)
      if addressbook:
        return nacaddr.CollapseAddrListPreserveTokens(addresses)
      else:
        return nacaddr.CollapseAddrList(addresses, complement_addresses)
github google / capirca / capirca / lib / junipersrx.py View on Github external
target = IndentList(self.INDENT)

    # create address books if address-book-type set to global
    if self._GLOBAL_ADDR_BOOK in self.addr_book_type:
      global_address_book = collections.defaultdict(list)

      target.IndentAppend(1, 'replace: address-book {')
      target.IndentAppend(2, 'global {')
      for zone in self.addressbook:
        for group in self.addressbook[zone]:
          for address in self.addressbook[zone][group]:
            global_address_book[group].append(address)
      names = sorted(global_address_book.keys())
      for name in names:
        counter = 0
        ips = nacaddr.SortAddrList(global_address_book[name])
        ips = nacaddr.CollapseAddrList(ips)
        global_address_book[name] = ips
        for ip in ips:
          target.IndentAppend(4, 'address ' + name + '_' + str(counter) + ' ' +
                              str(ip) + ';')
          counter += 1

      for group in sorted(global_address_book.keys()):
        target.IndentAppend(4, 'address-set ' + group + ' {')
        counter = 0
        for unused_addr in global_address_book[group]:
          target.IndentAppend(5, 'address ' + group + '_' + str(counter) + ';')
          counter += 1
        target.IndentAppend(4, '}')

      target.IndentAppend(2, '}')
github google / capirca / capirca / lib / policy.py View on Github external
def cleanup(addresses, complement_addresses):
      if not optimize:
        return nacaddr.SortAddrList(addresses)
      if addressbook:
        return nacaddr.CollapseAddrListPreserveTokens(addresses)
      else:
        return nacaddr.CollapseAddrList(addresses, complement_addresses)