Commit 446297a7 authored by Mohamad Rahhal's avatar Mohamad Rahhal
Browse files

SpineLeaf:

  -Loader Update
parent 06ada740
Loading
Loading
Loading
Loading
+2 −17
Original line number Diff line number Diff line
@@ -520,10 +520,6 @@ class DescriptorLoader:
                )
                if not is_loopback:
                    target_device = str(interface_data.get('link_to_device', ''))

                    # Resolve remote_as and remote_address from link_to_device lookup.
                    # This is done per-interface so a single device can contribute
                    # multiple distinct BGP sessions.
                    remote_as = str(interface_data.get('remote_as', ''))
                    remote_address = str(interface_data.get('remote_address', ''))
                    session_name = str(interface_data.get('bgp_session_name', ''))
@@ -533,22 +529,15 @@ class DescriptorLoader:
                            session_name = comment_slug[3:]

                    if target_device:
                        # Resolve remote AS: explicit in interface entry takes precedence,
                        # otherwise look up the ASN allocated to the target device.
                        if not remote_as:
                            remote_as = asn_by_device.get(target_device, '')

                        # Resolve remote address:
                        # 1) use explicit remote_address in interface data if present
                        # 2) else, use the target device's allocated ip (strip CIDR to host)
                        # 3) else, derive peer from local ip_value
                        if not remote_address:
                            remote_ip_cidr = ip_by_device.get(target_device, '')
                            if remote_ip_cidr:
                                try:
                                    remote_address = str(ipaddress.ip_interface(remote_ip_cidr).ip)
                                except Exception:
                                    # fallback: strip mask if simple CIDR string
                                    remote_address = remote_ip_cidr.split('/')[0] if '/' in remote_ip_cidr else remote_ip_cidr
                        if not remote_address:
                            remote_address = self._derive_peer_ip(ip_value)
@@ -560,7 +549,6 @@ class DescriptorLoader:
                                if target_slug:
                                    session_name = target_slug
                    else:
                        # No link_to_device specified; use explicit interface data or derive
                        if not remote_address:
                            remote_address = self._derive_peer_ip(ip_value)

@@ -600,9 +588,6 @@ class DescriptorLoader:
        if inferred_sessions:
            hints['bgp_sessions'] = inferred_sessions

        # Also collect any explicit /network_instances/bgp_session entries from
        # the device descriptor so spine can declare peers even when the
        # session list is only present in the original descriptor payload.
        bgp_sessions: List[Dict[str, Any]] = list(inferred_sessions)
        seen_sessions = {json.dumps(session, sort_keys=True) for session in bgp_sessions}
        try:
@@ -688,7 +673,7 @@ class DescriptorLoader:
                        request_kwargs['role'] = json.dumps(hints)
                    method(SetDeviceRoleRequest(**request_kwargs))
                    num_ok += 1
                except Exception as e:  # pylint: disable=broad-except
                except Exception as e:  
                    error_list.append(f'{fabric_id}/{device_identifier}: {str(e)}')

        self.__results.append(('spine_leaf', 'config', num_ok, error_list))
@@ -711,7 +696,7 @@ class DescriptorLoader:
                try:
                    _ = future.result()
                    num_ok += 1
                except Exception as e:  # pylint: disable=broad-except
                except Exception as e:  
                    error_list.append((i, f'{str(entity)}: {str(e)}'))

        error_list = [str_error for _,str_error in sorted(error_list, key=operator.itemgetter(0))]