def new_prefix(self, vrf, afi, prefix, interface=None, description=None): # Enable IPv4 AFI on VRF, if not set if afi == "4" and not vrf.afi_ipv4: self.info("Enabling IPv4 AFI on VRF %s (%s)" % (vrf.name, vrf.rd)) if self.to_save: vrf.afi_ipv4 = True vrf.save() # Enable IPv6 AFI on VRF, if not set if afi == "6" and not vrf.afi_ipv6: self.info("Enabling IPv6 AFI on VRF %s (%s)" % (vrf.name, vrf.rd)) if self.to_save: vrf.afi_ipv6 = True vrf.save() # Save prefix self.info("IPv%s prefix found: %s:%s" % (afi, vrf, prefix)) self.new_prefixes += [{ "vrf": vrf, "prefix": prefix, "object": self.object, "interface": interface, "description": description }] if self.to_save: Prefix(vrf=vrf, afi=afi, prefix=prefix, description=description).save()
def create_prefix(self, prefix): """ Create new prefix :param prefix: DiscoveredPrefix instance :return: """ if self.is_ignored_prefix(prefix): return vrf = VRF.get_by_vpn_id(prefix.vpn_id) self.ensure_afi(vrf, prefix) if not self.has_prefix_permission(vrf, prefix): self.logger.debug( "Do not creating vpn_id=%s asn=%s prefix=%s: Disabled by policy", prefix.vpn_id, prefix.asn.asn if prefix.asn else None, prefix.prefix, ) metrics["prefix_creation_denied"] += 1 return p = Prefix( vrf=vrf, prefix=prefix.prefix, name=self.get_prefix_name(prefix), profile=prefix.profile, asn=prefix.asn, description=prefix.description, source=prefix.source, ) self.logger.info( "Creating prefix %s (%s): name=%s profile=%s source=%s", p.prefix, p.vrf.name, p.name, p.profile.name, p.source, ) p.save() self.fire_seen(p) metrics["prefix_created"] += 1