Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netbox 3.0 adjustments #128

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions networking_ccloud/tools/netbox_config_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -486,7 +477,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:
Expand Down Expand Up @@ -571,10 +562,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'
Expand All @@ -586,7 +581,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, [])
Expand Down Expand Up @@ -636,8 +631,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
Expand Down
Loading