Beispiel #1
0
 def create_address(self, address):
     """
     Create new address
     :param address: DiscoveredAddress instance
     :return:
     """
     if self.is_ignored_address(address):
         return
     vrf = VRF.get_by_vpn_id(address.vpn_id)
     self.ensure_afi(vrf, address)
     if not self.has_address_permission(vrf, address):
         self.logger.debug(
             "Do not creating vpn_id=%s address=%s: Disabled by policy",
             address.vpn_id, address.address)
         metrics["address_creation_denied"] += 1
         return
     a = Address(vrf=vrf,
                 address=address.address,
                 name=self.get_address_name(address),
                 fqdn=address.fqdn,
                 profile=address.profile,
                 description=address.description,
                 source=address.source,
                 mac=address.mac)
     if address.source in LOCAL_SRC:
         a.managed_object = self.object
         a.subinterface = address.subinterface
     self.logger.info(
         "Creating address %s (%s): name=%s fqdn=%s mac=%s profile=%s source=%s",
         a.address, a.vrf.name, a.name, a.fqdn, a.mac, a.profile.name,
         a.source)
     a.save()
     self.fire_seen(a)
     metrics["address_created"] += 1
Beispiel #2
0
 def create_address(self, zone, vrf, afi, address, fqdn, is_test):
     """
     Create IPAM record
     """
     try:
         a = Address.objects.get(
             vrf=vrf,
             afi=afi,
             address=address
         )
         if self.force:
             if a.fqdn != fqdn:
                 self.info("Updating FQDN %s (%s)" % (a.address, a.fqdn))
                 a.fqdn = fqdn
                 a.save()
         else:
             self.info("Address %s (%s) is already exists in IPAM, ignoring" % (a.address, a.fqdn))
     except Address.DoesNotExist:
         a = Address(
             vrf=vrf,
             afi=afi,
             address=address,
             fqdn=fqdn,
             description="Imported from %s zone" % zone
         )
         self.info("Creating address %s (%s)" % (a.address, a.fqdn))
         if not is_test:
             a.save()
Beispiel #3
0
 def create_address(self,
                    zone,
                    vrf,
                    address,
                    fqdn,
                    address_profile,
                    dry_run=False,
                    force=False):
     """
     Create IPAM record
     """
     afi = "6" if ":" in address else "4"
     a = Address.objects.filter(vrf=vrf, afi=afi, address=address).first()
     if a:
         if force:
             if a.fqdn != fqdn:
                 self.print("Updating FQDN %s (%s)" % (a.address, a.fqdn))
                 a.fqdn = fqdn
                 a.name = fqdn
                 if not dry_run:
                     a.save()
         else:
             self.print(
                 "Address %s (%s) is already exists in IPAM, ignoring" %
                 (a.address, a.fqdn))
     else:
         # Not found
         a = Address(
             vrf=vrf,
             afi=afi,
             address=address,
             profile=address_profile,
             fqdn=fqdn,
             name=fqdn,
             description="Imported from %s zone" % zone,
         )
         self.print("Creating address %s (%s)" % (a.address, a.fqdn))
         if not dry_run:
             a.save()