Skip to content

Commit

Permalink
"Changes for 0.3.0"
Browse files Browse the repository at this point in the history
  • Loading branch information
derekwangHPEAruba committed Oct 8, 2020
1 parent 7bc31ed commit 29d3fb9
Show file tree
Hide file tree
Showing 8 changed files with 669 additions and 2 deletions.
7 changes: 7 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# 0.3.0

## Notable Changes
* Added nae.py, a new module to provide functionality for interacting with NAE scripts and agents.
* Added a function 'create_first_password' to setup.py to support logging into a factory default switch and handling the mandatory password creation.

# 0.2.2

## Notable Changes
* Minor bug fix in system.py module

Expand Down
7 changes: 7 additions & 0 deletions docs/source/pyaoscx.nae.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pyaoscx.nae module
==================

.. automodule:: pyaoscx.nae
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/pyaoscx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Submodules
pyaoscx.lldp
pyaoscx.loop_protect
pyaoscx.mac
pyaoscx.nae
pyaoscx.ospf
pyaoscx.port
pyaoscx.qos
Expand Down
2 changes: 1 addition & 1 deletion pyaoscx/common_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _response_ok(response, call_type):
ok_codes = {
"GET": [200],
"PUT": [200, 204],
"POST": [201],
"POST": [201, 268],
"DELETE": [204]
}

Expand Down
616 changes: 616 additions & 0 deletions pyaoscx/nae.py

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions pyaoscx/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@ def login(base_url, username=None, password=None):
return s


def create_first_password(base_url, password=None):
"""
Perform POST and PUT calls to open a restricted session with user admin and create the first password needed to gain access to other API calls.
:param base_url: URL in main() function
:param password: password
:return: requests.session object with loaded cookie jar
"""
if password is None:
password = getpass.getpass(prompt='Please provide a password: ')
s = requests.Session()
try:
# POST Request opens a limited session for user "admin" - Response code is 268
response = s.post(base_url + "login", params={"username": "admin"}, verify=False, timeout=5)
if not common_ops._response_ok(response, "POST"):
logging.warning("FAIL: Login failed with status code %d: %s" % (response.status_code, response.text))
exit(-1)
else:
# PUT Request updates the password for user "admin" - Response code is 200 - Session is kept open
payload = {
"password": str(password)
}
response = s.put(base_url + "system/users/admin", data=json.dumps(payload), verify=False, timeout=5)
if not common_ops._response_ok(response, "PUT"):
logging.warning("FAIL: Password update failed with status code %d: %s" % (response.status_code, response.text))
exit(-1)
else:
logging.info("SUCCESS: Password has been set for user admin")
return s
except requests.exceptions.ConnectTimeout:
logging.warning('ERROR: Error connecting to host: connection attempt timed out.')
exit(-1)


def logout(**kwargs):
"""
Perform a POST call to logout and end session.
Expand Down
2 changes: 2 additions & 0 deletions pyaoscx/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_system_info(params={}, **kwargs):

return system_info_dict


def get_chassis_info(params={}, **kwargs):
"""
Perform a GET call to get the chassis information, such as product info, reboot statistics, selftest info, and more.
Expand Down Expand Up @@ -59,6 +60,7 @@ def get_chassis_info(params={}, **kwargs):

return chassis_info_dict


def get_product_info(params={}, **kwargs):
"""
Perform a GET call to get the product information, such as MAC, Part Number, Model, and Serial
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = f.read()

setup(name='pyaoscx',
version='0.2.2',
version='0.3.0',
description='AOS-CX Python Modules',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 29d3fb9

Please sign in to comment.