From 5e83d1c9dc32cacf8fe40630c64621f3223a93ff Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 6 Oct 2023 11:11:15 +0200 Subject: [PATCH 1/2] Netbox 3.0 adjustments With netbox 3.0, there were 2 API changes that affect us: 1. Interfaces can now carry multiple connections, I believe is that is to support broken out interfaces. We do not plan to have break outs in the future, however we have them now. Yet we model them in the form that we create a new interface (which could carry individual VLANs and so on) and then model the connection. Hence, there is no need for us to support multiple connected endpoints under an interface. If we encounter it, we fail. 2. Sites can have multiple ASNs now, ASNs are objects, not plain ints anymore. This is not an issue so far as a site currently only carries one ASN, which we simply unpack. Yet, I can imagine that we use multiple ASN in a site in the future in which case we would currently throw an exceptions. That's fine for now. If the time comes, we probably need to tag the ASN we want to use for the fabric. --- networking_ccloud/tools/netbox_config_gen.py | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/networking_ccloud/tools/netbox_config_gen.py b/networking_ccloud/tools/netbox_config_gen.py index 3c8168f6..848bf947 100644 --- a/networking_ccloud/tools/netbox_config_gen.py +++ b/networking_ccloud/tools/netbox_config_gen.py @@ -486,7 +486,7 @@ def get_l3_data(self, asn_region: int, pod: int, switchgroup_no: int, leaf_no: i def get_asn_region(self, region): sites = self.netbox.dcim.sites.filter(region=region) - site_asns = {site.asn for site in sites if site.asn} + site_asns = {asn for site in sites if site.asns for asn in site.asns} if not site_asns: raise ConfigException(f"Region {region} has no ASN") if len(site_asns) > 1: @@ -571,10 +571,14 @@ def get_connected_devices(self, switches: List[NbRecord]) -> Tuple[Set[NbRecord] continue # FIXME: ignore management, peerlink (maybe), unconnected ports - if iface.connected_endpoint is None: + if iface.connected_endpoints is None: continue - far_device = iface.connected_endpoint.device + if len(iface.connected_endpoints) > 1: + raise ConfigException(f'Interface {iface.name} on {switch.name} has more than one ' + 'connected endpoint') + + far_device = iface.connected_endpoints[0].device if far_device.device_role.slug not in self.connection_roles: continue if (far_device.device_role.slug == 'filer' @@ -586,7 +590,7 @@ def get_connected_devices(self, switches: List[NbRecord]) -> Tuple[Set[NbRecord] if self.verbose: print(f"Device {switch.name} port {iface.name} is connected to " - f"device {far_device.name} port {iface.connected_endpoint.name} " + f"device {far_device.name} port {iface.connected_endpoints[0].name} " f"role {far_device.device_role.name}") ports_to_device = device_ports_map.get(far_device, []) @@ -636,8 +640,13 @@ def get_interconnect_hostgroups(self, nb_switches: List[NbRecord]) -> List[conf. ifaces = self._ignore_filter(self.netbox.dcim.interfaces.filter(device_id=nb_switch.id)) aci_facing_ifaces = list() for iface in ifaces: - connected_device_role = iface - for attr in ('connected_endpoint', 'device', 'device_role', 'slug'): + if not iface.connected_endpoints: + continue + if len(iface.connected_endpoints) > 1: + raise ConfigException(f'Interface {iface.name} on {nb_switch.name} has more than ' + 'one connected endpoint') + connected_device_role = iface.connected_endpoints[0] + for attr in ('device', 'device_role', 'slug'): connected_device_role = getattr(connected_device_role, attr, None) if not connected_device_role: continue From 86c707d29b282d8cf5688953e11633ff5b553425 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 6 Oct 2023 12:16:42 +0200 Subject: [PATCH 2/2] VLAN groups now support tags, remove convention extra-vlan adding Since netbox now supports tagging of VLAN groups, we can tag these groups and thus not have to rely on some lose convention if and when a VLAN group should considered to be always an extra vlan. --- networking_ccloud/tools/netbox_config_gen.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/networking_ccloud/tools/netbox_config_gen.py b/networking_ccloud/tools/netbox_config_gen.py index 848bf947..3f2b4ecb 100644 --- a/networking_ccloud/tools/netbox_config_gen.py +++ b/networking_ccloud/tools/netbox_config_gen.py @@ -382,15 +382,6 @@ def make_infra_networks_and_extra_vlans(self, iface: NbRecord, svis: Dict[NbReco extra_vlans.add(vlan.vid) continue - # by convention we ignore certain VLAN groups member VLANs, once we upgrade to netbox 3.x we shall remove - # this as VLAN groups will then support tags - if vlan.group and ( - (vlan.group.slug.startswith(self.region) and vlan.group.slug.endswith('cp')) - or vlan.group.slug == f'{self.region}-regional' - or vlan.group.slug == 'global-cc-core-transit'): - extra_vlans.add(vlan.vid) - continue - mandatory_attrs = ('vid', 'tenant') for attr in mandatory_attrs: if not getattr(vlan, attr, None):