Skip to content
Snippets Groups Projects
Select Git revision
  • 1ffb347b7ae01e6b500fa9577b6b70a6be39501e
  • develop default protected
  • master protected
  • feature/POL1-813-error-report-sensu-check
  • 0.22
  • 0.21
  • 0.20
  • 0.19
  • 0.18
  • 0.17
  • 0.16
  • 0.15
  • 0.14
  • 0.13
  • 0.12
  • 0.11
  • 0.10
  • 0.9
  • 0.8
  • 0.7
  • 0.6
  • 0.5
  • 0.4
  • 0.3
24 results

configuration.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)]