pyaoscx.session module

class pyaoscx.session.Session(ip_address, api, proxy=None)

Bases: object

Represents a connection to an AOS-CX device. It keeps all information
needed to login/logout to it, including parameters like proxy, IP address (both IPv4 and IPv6 are supported), and API version. The IP address should be similar to: ‘1.1.1.1’ or ‘2001:db8::11/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff’
close()
Perform a POST call to logout and end the session. Given all the
required information to perform the operation is already stored within the session, no parameters are required.
cookies()

Return the cookie stored in the requests’ session.

classmethod from_session(req_session, base_url, credentials=None)
Create a session from an existing request Session. It allows to create
an internal session from an already-authenticated and serialized session.
Parameters:
  • req_session – Existing Request Session object.
  • base_url – Url needed to create Session Object.
  • credentials – Dictionary with user and password credentials. Example: { username: <username>, password: <password> }
Return session:

Request Session Object.

classmethod login(base_url, username=None, password=None, use_proxy=True, handle_zeroized_device=False)
Perform a POST call to login and gain access to other API calls. If
either username or password is not specified, user will be prompted to enter the missing credential(s).
Parameters:
  • base_url – URL in main() function
  • username – username
  • password – password
  • use_proxy – Whether the system proxy should be used, defaults to True.
  • handle_zeroized_device – Whether a zeroized device should be initialized, if so sets the admin password to the provided one, defaults to False.
Returns:

requests.session object with loaded cookie jar

classmethod logout(**kwargs)

Perform a POST call to logout and end session.

Parameters:kwargs – keyword “s” requests.session object with loaded cookie jar keyword “url” URL in main() function
Returns:True if successful.
open(username=None, password=None, use_proxy=True)
Perform a POST call to login and gain access to other API calls. If
either username or password is not specified, user will be prompted to enter the missing credential(s).
Parameters:
  • username – username
  • password – password
password()

Get password.

:return password.

request(operation, path, params=None, data=None, verify=False)

Perform a Request to the switch.

Parameters:
  • operation – type of operation: PUT, GET, POST, DELETE.
  • path – Path to the resource.
  • params – Extra request parameters.
  • data – Data to send in the resquest.
  • verify – If session should verify.
Returns:

response object from the request.

username()

Get username.

:return username.