Skip to content

Nautobot Plugin Nornir Credentials

nautobot_plugin_nornir.plugins.credentials

Init file for credentials.

env_vars

Credentials class for environment variables passwords.

CredentialsEnvVars

Bases: MixinNautobotORMCredentials

Credentials Class designed to work with Nautobot ORM.

This class is the default class that will return the same login and password for all devices based on the values of the environment variables

Source code in nautobot_plugin_nornir/plugins/credentials/env_vars.py
class CredentialsEnvVars(MixinNautobotORMCredentials):
    """Credentials Class designed to work with Nautobot ORM.

    This class is the default class that will return the same login and password
    for all devices based on the values of the environment variables
    """

    def __init__(self, params=None):
        """Initialize Credentials Class designed to work with Nautobot ORM.

        Args:
            params ([dict], optional): Credentials Parameters
        """
        if not params:
            params = {}

        if not isinstance(params, dict):
            raise TypeError("params must be a dictionary")

        self.username = os.getenv(params.get("username", USERNAME_ENV_VAR_NAME))
        self.password = os.getenv(params.get("password", PASSWORD_ENV_VAR_NAME))
        self.secret = os.getenv(params.get("secret", SECRET_ENV_VAR_NAME))

        if not self.secret:
            self.secret = self.password
__init__(params=None)

Initialize Credentials Class designed to work with Nautobot ORM.

Parameters:

Name Type Description Default
params [dict]

Credentials Parameters

None
Source code in nautobot_plugin_nornir/plugins/credentials/env_vars.py
def __init__(self, params=None):
    """Initialize Credentials Class designed to work with Nautobot ORM.

    Args:
        params ([dict], optional): Credentials Parameters
    """
    if not params:
        params = {}

    if not isinstance(params, dict):
        raise TypeError("params must be a dictionary")

    self.username = os.getenv(params.get("username", USERNAME_ENV_VAR_NAME))
    self.password = os.getenv(params.get("password", PASSWORD_ENV_VAR_NAME))
    self.secret = os.getenv(params.get("secret", SECRET_ENV_VAR_NAME))

    if not self.secret:
        self.secret = self.password

nautobot_orm

Credentials class designed to work with Nautobot ORM.

MixinNautobotORMCredentials

Bases: NautobotORMCredentials

Abstract Credentials Class mixin, to provide base get_device_creds functionality.

Source code in nautobot_plugin_nornir/plugins/credentials/nautobot_orm.py
class MixinNautobotORMCredentials(NautobotORMCredentials):
    """Abstract Credentials Class mixin, to provide base get_device_creds functionality."""

    def get_device_creds(self, device):
        """Return the credentials for a given device.

        Args:
            device (dcim.models.Device): Nautobot device object

        Return:
            username (string):
            password (string):
            secret (string):
        """
        return (self.username, self.password, self.secret)  # pylint: disable=no-member
get_device_creds(device)

Return the credentials for a given device.

Parameters:

Name Type Description Default
device Device

Nautobot device object

required
Return

username (string): password (string): secret (string):

Source code in nautobot_plugin_nornir/plugins/credentials/nautobot_orm.py
def get_device_creds(self, device):
    """Return the credentials for a given device.

    Args:
        device (dcim.models.Device): Nautobot device object

    Return:
        username (string):
        password (string):
        secret (string):
    """
    return (self.username, self.password, self.secret)  # pylint: disable=no-member

NautobotORMCredentials

Abstract Credentials Class designed to work with Nautobot ORM.

Source code in nautobot_plugin_nornir/plugins/credentials/nautobot_orm.py
class NautobotORMCredentials:
    """Abstract Credentials Class designed to work with Nautobot ORM."""

    def get_device_creds(self, device):  # pylint: disable=unused-argument
        """Return the credentials for a given device.

        Args:
            device (dcim.models.Device): Nautobot device object

        Return:
            username (string):
            password (string):
            secret (string):
        """
        return (None, None, None)

    def get_group_creds(self, group_name):  # pylint: disable=unused-argument
        """Return the credentials for a given group.

        Args:
            group_name (string): Name of the group

        Return:
            string: username
            string: password
            string: secret
        """
        return (None, None, None)
get_device_creds(device)

Return the credentials for a given device.

Parameters:

Name Type Description Default
device Device

Nautobot device object

required
Return

username (string): password (string): secret (string):

Source code in nautobot_plugin_nornir/plugins/credentials/nautobot_orm.py
def get_device_creds(self, device):  # pylint: disable=unused-argument
    """Return the credentials for a given device.

    Args:
        device (dcim.models.Device): Nautobot device object

    Return:
        username (string):
        password (string):
        secret (string):
    """
    return (None, None, None)
get_group_creds(group_name)

Return the credentials for a given group.

Parameters:

Name Type Description Default
group_name string

Name of the group

required
Return

string: username string: password string: secret

Source code in nautobot_plugin_nornir/plugins/credentials/nautobot_orm.py
def get_group_creds(self, group_name):  # pylint: disable=unused-argument
    """Return the credentials for a given group.

    Args:
        group_name (string): Name of the group

    Return:
        string: username
        string: password
        string: secret
    """
    return (None, None, None)

nautobot_secrets

Credentials class designed to work with Nautobot Secrets Functionality.

CredentialsNautobotSecrets

Bases: MixinNautobotORMCredentials

Credentials Class designed to work with Nautobot Secrets Functionality.

Source code in nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py
class CredentialsNautobotSecrets(MixinNautobotORMCredentials):
    """Credentials Class designed to work with Nautobot Secrets Functionality."""

    def get_device_creds(self, device):
        """Return the credentials for a given device.

        Args:
            device (dcim.models.Device): Nautobot device object

        Return:
            username (string):
            password (string):
            secret (string):
        """
        if device.secrets_group:
            self.username = _get_secret_value(
                secret_type=SecretsGroupSecretTypeChoices.TYPE_USERNAME, device_obj=device
            )
            self.password = _get_secret_value(
                secret_type=SecretsGroupSecretTypeChoices.TYPE_PASSWORD, device_obj=device
            )
            self.secret = _get_secret_value(secret_type=SecretsGroupSecretTypeChoices.TYPE_SECRET, device_obj=device)
            if not self.secret:
                self.secret = self.password
            return (self.username, self.password, self.secret)
        return (None, None, None)
get_device_creds(device)

Return the credentials for a given device.

Parameters:

Name Type Description Default
device Device

Nautobot device object

required
Return

username (string): password (string): secret (string):

Source code in nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py
def get_device_creds(self, device):
    """Return the credentials for a given device.

    Args:
        device (dcim.models.Device): Nautobot device object

    Return:
        username (string):
        password (string):
        secret (string):
    """
    if device.secrets_group:
        self.username = _get_secret_value(
            secret_type=SecretsGroupSecretTypeChoices.TYPE_USERNAME, device_obj=device
        )
        self.password = _get_secret_value(
            secret_type=SecretsGroupSecretTypeChoices.TYPE_PASSWORD, device_obj=device
        )
        self.secret = _get_secret_value(secret_type=SecretsGroupSecretTypeChoices.TYPE_SECRET, device_obj=device)
        if not self.secret:
            self.secret = self.password
        return (self.username, self.password, self.secret)
    return (None, None, None)

settings_vars

Credentials class for setting credentials.

CredentialsSettingsVars

Bases: MixinNautobotORMCredentials

Credentials Class designed to work with Nautobot ORM that comes from settings.

This class will return the same login and password for all devices based on the values within your settings.

Source code in nautobot_plugin_nornir/plugins/credentials/settings_vars.py
class CredentialsSettingsVars(MixinNautobotORMCredentials):
    """Credentials Class designed to work with Nautobot ORM that comes from settings.

    This class will return the same login and password for all devices based on the values
    within your settings.
    """

    def __init__(self, params=None):
        """Initialize Credentials Class designed to work with Nautobot ORM.

        Args:
            params ([dict], optional): Credentials Parameters
        """
        if not params:
            params = {}

        if not isinstance(params, dict):
            raise TypeError("params must be a dictionary")

        self.username = PLUGIN_CFG.get("username")
        self.password = PLUGIN_CFG.get("password")
        self.secret = PLUGIN_CFG.get("secret")

        if not self.secret:
            self.secret = self.password
__init__(params=None)

Initialize Credentials Class designed to work with Nautobot ORM.

Parameters:

Name Type Description Default
params [dict]

Credentials Parameters

None
Source code in nautobot_plugin_nornir/plugins/credentials/settings_vars.py
def __init__(self, params=None):
    """Initialize Credentials Class designed to work with Nautobot ORM.

    Args:
        params ([dict], optional): Credentials Parameters
    """
    if not params:
        params = {}

    if not isinstance(params, dict):
        raise TypeError("params must be a dictionary")

    self.username = PLUGIN_CFG.get("username")
    self.password = PLUGIN_CFG.get("password")
    self.secret = PLUGIN_CFG.get("secret")

    if not self.secret:
        self.secret = self.password