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

Accept serial number as optional arg for connecting via panorama #122

Open
amylieb opened this issue Jan 10, 2025 · 1 comment
Open

Accept serial number as optional arg for connecting via panorama #122

amylieb opened this issue Jan 10, 2025 · 1 comment

Comments

@amylieb
Copy link

amylieb commented Jan 10, 2025

Environment

  • napalm-panos version: 0.6.2

Proposed Functionality

Allow for 'serial' value in optional_args in the initializer for this class that can be then referenced in the open method so that an xapi connection can be made to a device via panorama.

Use Case

Connecting to devices through panorama instead of directly - our firewall team gave me an API key that works against panorama, they don't want to manage credentials on firewalls individually. The code changes are pretty simple since pan.xapi will take "serial" in as an argument and then add &target=<serial> to its URL queries.

@amylieb
Copy link
Author

amylieb commented Jan 10, 2025

I've actually implemented this in my own environment so that I can leverage this library without maintaining a fork- here's the relevant code:

class PANOS(PANOSDriver):
    """
    PANOS Parser
    """

    def __init__(self, hostname, username, password, timeout=60, optional_args=None):

        super().__init__(hostname, username, password, timeout, optional_args)

        self.serial = None
        if optional_args:
            self.serial = optional_args.get("serial")
            

    def open(self):
        """PANOS version of `open` method, see NAPALM for documentation."""
        try:
            if self.api_key:
                self.device = pan.xapi.PanXapi(hostname=self.hostname, api_key=self.api_key, serial=self.serial)
            else:
                self.device = pan.xapi.PanXapi(
                    hostname=self.hostname,
                    api_username=self.username,
                    api_password=self.password,
                    serial=self.serial
                )
        except ConnectionException as exc:
            raise ConnectionException(str(exc))
        if not self.locked and self.session_config_lock:
            self._lock()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant