Skip to content
Snippets Groups Projects
Select Git revision
  • f4d737c8728a6f3af8527b9247a09f5efdfa49eb
  • develop default protected
  • master protected
  • feature/NAT-1797-netbox-migration
  • authorship-fix-from-develop
  • 1048-service-config-backfilling
  • feature/nat-1211-edgeport-lacp-xmit
  • fix/nat-1120-sdp-validation
  • NAT-1154-import-edge-port-update
  • fix/l3-imports
  • feature/10GGBS-NAT-980
  • fix/NAT-1009/fix-redeploy-base-config-if-there-is-a-vprn
  • 4.27
  • 4.26
  • 4.25
  • 4.24
  • 4.23
  • 4.22
  • 4.21
  • 4.20
  • 4.19
  • 4.18
  • 4.17
  • 4.16
  • 4.15
  • 4.14
  • 4.13
  • 4.12
  • 4.11
  • 4.10
  • 4.8
  • 4.5
32 results

netbox_router.py

Blame
  • netbox_router.py 1.12 KiB
    """A router that must be present in Netbox."""
    
    from typing import Annotated, TypeVar
    
    from pydantic import AfterValidator
    from pydantic_forms.types import UUIDstr
    
    from gso.products.product_types.router import Router
    from gso.services.netbox_client import NetboxClient
    from gso.utils.shared_enums import Vendor
    
    
    def validate_router_in_netbox(subscription_id: UUIDstr) -> UUIDstr:
        """Verify if a device exists in Netbox.
    
        Raises a :class:`ValueError` if the device is not found.
    
        :param subscription_id: The :term:`UUID` of the router subscription.
        :type subscription_id: :class:`UUIDstr`
    
        :return: The :term:`UUID` of the router subscription.
        :rtype: :class:`UUIDstr`
        """
        router_type = Router.from_subscription(subscription_id)
        if router_type.router.vendor == Vendor.NOKIA:
            device = NetboxClient().get_device_by_name(router_type.router.router_fqdn)
            if not device:
                msg = "The selected router does not exist in Netbox."
                raise ValueError(msg)
        return subscription_id
    
    
    T = TypeVar("T")
    NetboxEnabledRouter = Annotated[T, UUIDstr, AfterValidator(validate_router_in_netbox)]