Skip to content

Commit 04d827c

Browse files
Merge pull request #3 from SPOpenSource/release/0.15.0-a1
Release/0.15.0 a1
2 parents 158aad2 + 5ed24e0 commit 04d827c

63 files changed

Lines changed: 7345 additions & 426 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ wheels/
2929
tests/
3030
docs/build/
3131
docs/source/_build
32+
examples/generate_preconfig/preconfig_outputs
3233

3334
# dotenv
3435
*.env

.readthedocs.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the version of Python and other tools
9+
build:
10+
tools:
11+
python: "3.9"
12+
13+
# Build documentation in the docs/ directory with Sphinx
14+
sphinx:
15+
configuration: docs/conf.py
16+
17+
# If using Sphinx, optionally build your docs in additional formats such as PDF
18+
formats:
19+
- pdf
20+
21+
# Optionally declare the Python requirements required to build your docs
22+
python:
23+
install:
24+
- requirements: docs/requirements.txt

README.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Aruba Edge Connect Python SDK
22

3+
[![Downloads](https://static.pepy.tech/personalized-badge/pyedgeconnect?period=total&units=none&left_color=grey&right_color=orange&left_text=PyPI%20Downloads)](https://pepy.tech/project/pyedgeconnect)
34

45
This package is a python wrapper for leveraging the API for Aruba
56
Orchestrator and Edge Connect SDWAN systems.
@@ -10,12 +11,8 @@ Edge Connect web interfaces under "Support > Rest API"
1011
Many, but not all API functions have been implemented yet. Development
1112
is underway to continue to add further functions.
1213

13-
As of 0.14.0+ 64% of non-deprecated Swagger functions are covered.
14-
15-
1614
## Install
1715

18-
1916
### Python Version
2017

2118
> **Note:** Requires Python 3.9.0+ (due to PEP585 type-hinting e.g. ``def my_func(var1 = list[str]``)
@@ -59,7 +56,7 @@ Now you can install the package and run your python code
5956
### Install from PyPI
6057

6158
```bash
62-
$ pip install pyedgeconnect
59+
pip install pyedgeconnect
6360
```
6461

6562
### Install from GitHub
@@ -70,13 +67,13 @@ interactive shell and run:
7067
> **Note:** These commands assume you're within a Python 3.9 venv, or Python 3.9 is the exclusive Python version installed in regard to referencing the use of ``pip``. If that is not the case, you can specifically append ``python3.9 -m`` ahead of the ``pip install ...``
7168
7269
```bash
73-
$ pip install git+https://github.com/SPOpenSource/edgeconnect-python
70+
pip install git+https://github.com/SPOpenSource/edgeconnect-python
7471
```
7572

7673
To install a specific branch use the @branch syntax
7774

7875
```bash
79-
$ pip install git+https://github.com/SPOpenSource/edgeconnect-python@<branch_name>
76+
pip install git+https://github.com/SPOpenSource/edgeconnect-python@<branch_name>
8077
```
8178

8279
### Install dev options
@@ -91,7 +88,7 @@ following syntax:
9188
```bash
9289
$ pip install pyedgeconnect[dev]
9390
or
94-
$ pip install -e git+https://github.com/SPOpenSource/edgeconnect-python#egg=pyedgeconnect[dev]
91+
$ pip install -e git+https://github.com/SPOpenSource/edgeconnect-python#egg=pyedgeconnect[dev]
9592
```
9693

9794
## Docs
@@ -104,11 +101,11 @@ To build the documentation locally, clone the repository, install with ``[dev]``
104101
to include sphinx and related packages, then in the docs directory run ``make html``
105102

106103
```bash
107-
$ git clone https://github.com/SPOpenSource/edgeconnect-python.git
108-
$ cd pyedgeconnect
109-
$ pip install .[dev]
110-
$ cd docs
111-
$ make html
104+
git clone https://github.com/SPOpenSource/edgeconnect-python.git
105+
cd edgeconnect-python
106+
pip install .[dev]
107+
cd docs
108+
make html
112109
```
113110

114111
## Usage
@@ -213,15 +210,17 @@ In the [Examples](/examples) directory you can find scripts leveraging
213210
the Orchestrator class demonstrating some uses
214211

215212
* [create_user.py](/examples/create_user.py)
216-
* creates a new read-only user on Orchestrator and returns the
213+
* creates a new read-only user on Orchestrator and returns the
217214
configured details
218215
* [print_appliance_info.py](/examples/print_appliance_info.py)
219-
* retrieves all appliances, retrieves detailed attributes of the
216+
* retrieves all appliances, retrieves detailed attributes of the
220217
appliances, and prints details in a table format
221218
* [run_packet_capture.py](/examples/run_packet_capture.py)
222-
* runs a tcpdump packet capture on a specified appliance, once
219+
* runs a tcpdump packet capture on a specified appliance, once
223220
completed, uploads to Orchestrator for user retrieval
224-
221+
* [preconfig.py](/examples/generate_preconfig/preconfig.py)
222+
* uses a CSV file as source data to generate Edge Connect YAML
223+
preconfig from a Jinja template
225224

226225
## This is an alpha product
227226

@@ -255,7 +254,6 @@ See contribution details at [Contributing](CONTRIBUTING.md)
255254

256255
Release notes are located in ``docs/source/release-notes`` directory [here](docs/source/release-notes)
257256

258-
259257
## Authors
260258

261259
Authored by Zach Camara, email at <zachary.camara@hpe.com>

_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "0.14.0a2.dev1"
1+
version = "0.15.0a2.dev0"

docs/source/code_formatting.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
=========================
2+
Code Formatting
3+
=========================
4+
5+
6+
Flake8 is run on the codebase according to parameters in the .flake8
7+
file following PEP8 conventions where possible.
8+
9+
Naming Conventions
10+
^^^^^^^^^^^^^^^^^^
11+
12+
* Classes are named in CamelCase, e.g. HttpCommon, Orchestrator,
13+
EdgeConnect
14+
* Functions are variables are named in snake_case, e.g. get_appliances()
15+
* Private functions begin with ``_`` e.g. ``_get()`` or ``_req_post()``
16+
17+
Docstrings and comments
18+
^^^^^^^^^^^^^^^^^^^^^^^
19+
* Docstrings follow Sphinx/reStructured Text Formatting
20+
* Short initial description
21+
* Reference to where to find this function in Swagger UI
22+
* Longer description, notes, examples if applicable
23+
* parameter and return descriptions and types
24+
* All functions have docstrings outlining parameters and returns
25+
* Code in a function begins the line immediately following the docstring
26+
27+
**Example:**
28+
29+
.. code::
30+
31+
"""<Short description here>
32+
33+
.. list-table::
34+
:header-rows: 1
35+
36+
* - Swagger Section
37+
- Method
38+
- Endpoint
39+
* - <swagger section> -> e.g. login
40+
- <method> -> e.g. GET
41+
- <endpoint> -> e.g. /logout
42+
43+
<longer description>
44+
45+
.. note::
46+
47+
an optional note
48+
49+
.. warning::
50+
51+
an optional warning
52+
53+
:param <param name>: <param description>
54+
:type <param name>: <param type>
55+
:return: <return description>
56+
:rtype: <return type>
57+
"""
58+
<code begins here>
59+
60+
Maximum Line Length
61+
^^^^^^^^^^^^^^^^^^^
62+
* All comments and docstrings have a maximum line length of 72
63+
characters
64+
* All functional code has a maximum line length of 79 characters
65+
* In the rare case when a string or docstring can't be wrapped over
66+
multiple lines (e.g. specifying a long API endpoint in docstring)
67+
use ``# noqa:`` at the end of the docstring with ``E501``
68+
for extending past 79 and ``W505`` for extending past 72, or just
69+
``W505`` if past 72 but within 79.
70+
71+
**Example:**
72+
73+
.. code::
74+
75+
"""docstring
76+
77+
.. list-table::
78+
:header-rows: 1
79+
80+
* - Swagger Section
81+
- Method
82+
- Endpoint
83+
* - login
84+
- GET
85+
- /long_endpoint/path/{that_cannot}/be/wrapped/over_multiple_lines
86+
...
87+
""" # noqa: W505
88+
89+
90+
Type Hinting (PEP585)
91+
^^^^^^^^^^^^^^^^^^^^^
92+
* All parameters for functions have type hinting following PEP585
93+
(Python 3.9+) formatting with generic types.
94+
95+
.. code::
96+
97+
def my_func(my_var: str) -> dict:
98+
...
99+
# or
100+
def my_func(my_var: list[int]) -> list:
101+
...
102+

docs/source/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
# -- Project information -----------------------------------------------------
1111

1212
project = "pyedgeconnect"
13-
copyright = "2021 Hewlett Packard Enterprise Development LP"
13+
copyright = "2022 Hewlett Packard Enterprise Development LP"
1414
author = "Zach Camara"
1515

1616
# Main version number
17-
version = "0.14"
17+
version = "0.15"
1818
# The full version, including alpha/beta/rc tags
19-
release = "0.14.0-a2"
19+
release = "0.15.0-a1"
2020

2121

2222
# -- General configuration ---------------------------------------------------
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
.. auth_example:
2+
3+
============================
4+
Authentication
5+
============================
6+
7+
The following code snippet is an example of handling multiple authentication
8+
methods when connecting to an Aruba Orchestrator instance with pyedgeconnect.
9+
10+
The example scripts provided in the repository use this process in
11+
addition to any other required logic for a particular use-case.
12+
13+
14+
15+
Environment variables
16+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
The example script will also look for the following environment variables
19+
related to authenticating to Orchestrator
20+
21+
``ORCH_URL``
22+
``ORCH_API_KEY``
23+
``ORCH_USER``
24+
``ORCH_PASSWORD``
25+
26+
If ORCH_URL is specified, it will take precedence, otherwise user will
27+
be prompted for input to enter the Orchestrator IP or FQDN
28+
29+
If ORCH_API_KEY is specified it will take precedence for an authentication
30+
method over user/password authentication. If not found, the user will be
31+
prompted for entering an API key.
32+
33+
.. code-block:: python
34+
35+
import argparse
36+
import getpass
37+
import os
38+
39+
from pyedgeconnect import Orchestrator
40+
41+
# Parse runtime arguments to specify an Orchestrator IP or FQDN
42+
parser = argparse.ArgumentParser()
43+
parser.add_argument(
44+
"-o",
45+
"--orch",
46+
help="specify Orchestrator URL",
47+
type=str,
48+
)
49+
args = parser.parse_args()
50+
51+
# Set Orchestrator FQDN/IP via arguments, environment variable,
52+
# or user input if neither in argument or environment variable
53+
if vars(args)["orch"] is not None:
54+
orch_url = vars(args)["orch"]
55+
elif os.getenv("ORCH_URL") is not None:
56+
orch_url = os.getenv("ORCH_URL")
57+
else:
58+
orch_url = input("Orchstrator IP or FQDN: ")
59+
60+
# Set Orchestrator API Key via environment variable or user input
61+
# Skipping will fallback to user/password authentication
62+
if os.getenv("ORCH_API_KEY") is not None:
63+
orch_api_key = os.getenv("ORCH_API_KEY")
64+
else:
65+
orch_api_key_input = input("Orchstrator API Key (enter to skip): ")
66+
if len(orch_api_key_input) == 0:
67+
orch_api_key = None
68+
# Set user and password if present in environment variable
69+
orch_user = os.getenv("ORCH_USER")
70+
orch_pw = os.getenv("ORCH_PASSWORD")
71+
else:
72+
orch_api_key = orch_api_key_input
73+
74+
# Instantiate Orchestrator with ``log_console`` enabled for
75+
# printing log messages to terminal, and ``verify_ssl`` to False
76+
# which will not verify the web https certificate on Orchestrator
77+
orch = Orchestrator(
78+
orch_url,
79+
api_key=orch_api_key,
80+
log_console=True,
81+
verify_ssl=False,
82+
)
83+
84+
# If not using API key, login to Orchestrator with username/password
85+
if orch_api_key is None:
86+
# If username/password not in environment variables, prompt user
87+
if orch_user is None:
88+
orch_user = input("Enter Orchestrator username: ")
89+
orch_pw = getpass.getpass("Enter Orchestrator password: ")
90+
# Check if multi-factor authentication required
91+
mfa_prompt = input("Are you using MFA for this user (y/n)?: ")
92+
if mfa_prompt == "y":
93+
orch.send_mfa(orch_user, orch_pw, temp_code=False)
94+
token = input("Enter MFA token: ")
95+
else:
96+
token = ""
97+
# Login to Orchestrator with user/password to check auth before
98+
# proceeding
99+
confirm_auth = orch.login(orch_user, orch_pw, mfacode=token)
100+
if confirm_auth:
101+
pass
102+
else:
103+
print("Authentication to Orchestrator Failed")
104+
exit()
105+
# If API key specified, check that key is valid before proceeding
106+
else:
107+
confirm_auth = orch.get_orchestrator_hello()
108+
if confirm_auth != "There was an internal server error.":
109+
pass
110+
else:
111+
print("Authentication to Orchestrator Failed")
112+
exit()

0 commit comments

Comments
 (0)