Session

class apstra.aosom.session.Session(target=None, **kwargs)

The Session class is used to create a client connection with the AOS-server. The general process to create a connection is as follows:

from apstra.aosom.session import Session

aos = Session('aos-session')                  # hostname or ip-addr of AOS-server
aos.login()                                   # username/password uses defaults

This module will use your environment variables to provide the default login values, if they are set. Refer to ENV for specific values.

This module will use value defaults as defined in DEFAULTS.

Once you have an active session with the AOS-server you use the modules defined in the ModuleCatalog.

The following are the available public attributes of a Session instance:
  • api - an instance of the Session.Api that provides HTTP access capabilities.
  • server - the provided AOS-server hostname/ip-addr value.
  • user - the provided AOS login user-name
The following are the available user-shell environment variables that are used by the Session instance:
  • AOS_SERVER - the AOS-server hostname/ip-addr
  • AOS_USER - the login user-name, defaults to DEFAULTS["USER"].
  • AOS_PASSWD - the login user-password, defaults to DEFAULTS["PASSWD"].
  • AOS_SESSION_TOKEN - a pre-existing API session-token to avoid user login/authentication.
ENV = {'USER': 'AOS_USER', 'PASSWD': 'AOS_PASSWD', 'TOKEN': 'AOS_SESSION_TOKEN', 'PORT': 'AOS_SERVER_PORT', 'SERVER': 'AOS_SERVER'}
DEFAULTS = {'PASSWD': 'admin', 'USER': 'admin', 'PORT': 443}
__init__(target=None, **kwargs)

Create a Session instance that will connect to an AOS-server, server. Additional keyword arguments can be provided that override the default values, as defined in DEFAULTS, or the values that are taken from the callers shell environment, as defined in ENV. Once a Session instance has been created, the caller can complete the login process by invoking login().

Parameters:
login()

Login to the AOS-server, obtaining a session token for use with later calls to the API.

Raises:
  • LoginAuthError – The provided user credentials are not valid. Check the user/password or session token values provided.
  • LoginServerUnreachableError – The API is not able to connect to the AOS-server via the API. This could be due to any number of networking related issues. For example, the port is blocked by a firewall, or the server value is IP unreachable.
  • LoginNoServerError – The instance does not have server configured.
session

When used as a setter attempts to resume an existing session with the AOS-server using the provided session data. If there is an error, an exception is raised.

Returns:The session data that can be used for a future resume.
Return type:dict
Raises:See the login() for details.
token
Returns:Authentication token from existing session.
Return type:str
Raises:NoLoginError – When no token is present.
url
Returns:
  • Return the current AOS-server API URL. If this value is
  • not set, then an exception is raised. The raise here is important
  • because other code depends on this behavior.
Raises:NoLoginError: URL does not exist
valid

Returns bool if this session is valid; i.e. we have a valid login/token.

Returns:
  • True if valid
  • False if not valid.