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 theSession.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-addrAOS_USER
- the login user-name, defaults toDEFAULTS["USER"]
.AOS_PASSWD
- the login user-password, defaults toDEFAULTS["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 inDEFAULTS
, or the values that are taken from the callers shell environment, as defined inENV
. Once a Session instance has been created, the caller can complete the login process by invokinglogin()
.Parameters: - target (str) –
URL to the AOS-Server. The target value must be in the form of <scheme>://<aos-server>[:port]. For example:
- user (str) – User login name
- passwd (str) – User login password
- target (str) –
-
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, theport
is blocked by a firewall, or theserver
value is IP unreachable.LoginNoServerError
– The instance does not haveserver
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.