mv-pycentral 1.4.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,154 @@
1
+ Metadata-Version: 2.4
2
+ Name: mv-pycentral
3
+ Version: 1.4.3
4
+ Summary: Aruba Central Python Package
5
+ Home-page: https://github.com/Moviri/mv-pycentral
6
+ Author: aruba-automation
7
+ Author-email: dynatrace_extensions@moviri.com
8
+ Classifier: Programming Language :: Python :: 3 :: Only
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Intended Audience :: System Administrators
12
+ Classifier: Topic :: System :: Networking
13
+ Classifier: Development Status :: 4 - Beta
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: requests==2.32.5
18
+ Requires-Dist: PyYAML==6.0.3
19
+ Requires-Dist: urllib3==2.6.3
20
+ Requires-Dist: certifi==2026.1.4
21
+ Provides-Extra: colorlog
22
+ Requires-Dist: colorlog; extra == "colorlog"
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: license-file
30
+ Dynamic: provides-extra
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ # pycentral
36
+ #### Aruba Central Python Package Index SDK
37
+
38
+ Aruba Central is an unified cloud-based network management and configuration platform for campus, branch, remote and data center networks. There are various needs for automation and programmability like automating repetitive tasks, configuring multiple devices, monitoring and more. This python package is to programmatically interact with Aruba Central via REST APIs.
39
+
40
+ ### How To Install
41
+ In order to run the workflow scripts, please complete the steps below:
42
+ 1. install virtual env (refer https://docs.python.org/3/library/venv.html). Make sure python version 3 is installed in system.
43
+ ```
44
+ $ python3 -m venv centralenv
45
+ ```
46
+
47
+ 2. Activate the virtual env
48
+ ```
49
+ $ source centralenv/bin/activate
50
+ in Windows:
51
+ $ centralenv/Scripts/activate.bat
52
+ ```
53
+
54
+ 3. Install the **pycentral** package
55
+ ```
56
+ (centralenv)$ pip3 install pycentral
57
+ ```
58
+
59
+ To install package with *extras* `colorLog` which will display log in color
60
+ ```
61
+ (centralenv)$ pip3 install pycentral[colorLog]
62
+ ```
63
+
64
+ Now you can start making your script based on modules in pycentral or use different workflows from the subpackage `workflows`.
65
+
66
+ ## Executing Scripts
67
+
68
+ 1. Gathering variables required for the package base class `ArubaCentralBase`.
69
+
70
+ * **base_url** OR **cluster_name**: You can find the base URL or cluster name of the Central account's API Gateway from the table <a href="https://www.arubanetworks.com/techdocs/central/latest/content/nms/api/domain_url.htm" target="_blank">here</a>. The base URL or cluster name is based on the geographical Central cluster in which the account is registered.
71
+
72
+ * **access_token**: You can create an API access token for Aruba Central from -
73
+ * <a href="https://developer.arubanetworks.com/aruba-central/docs/api-gateway-obtaining-access-tokens#obtain-access-token-via-web-ui" target="_blank">Aruba Central UI</a>
74
+ * <a href="https://developer.arubanetworks.com/aruba-central/docs/api-oauth-access-token" target="_blank">OAuth APIs</a>
75
+
76
+ * Optional variables - You need to provide the below variables if you want to use PyCentral's ability to generate access tokens from Aruba Central with the help of OAuth APIs.
77
+ * **username** and **password**: Aruba Central user's *username* and *password*. The access token generated by the OAUTH APIs will have the same role/privileges as the provided Aruba Central user.
78
+
79
+ * **client_id** and **client_secret**: Obtain client_id and client_secret variables by creating an API Gateway client in Aruba Central. Refer the following <a href="https://developer.arubanetworks.com/aruba-central/docs/api-gateway-creating-application-token" target="_blank">documentation</a> for more details.
80
+
81
+ * **customer_id**: Obtain the **customer_id** by clicking on the figure icon on top right corner of Aruba Central WebUI.
82
+
83
+ ![Customer ID](https://github.com/aruba/pycentral/raw/master/pictures/customer-id.png)
84
+
85
+
86
+ 2. Providing input variables to the Python scripts. One of the following options can be used.
87
+ * Provide variables directly to Aruba Central Base class in dictionary format.
88
+
89
+ Access token approach:
90
+ ```python
91
+ central_info = {
92
+ "base_url": "<api-gateway-domain-url>",
93
+ "token": {
94
+ "access_token": "<api-gateway-access-token>"
95
+ }
96
+ }
97
+ ```
98
+
99
+ OAUTH APIs approach with capability to generate new access token:
100
+ ```python
101
+ central_info = {
102
+ "username": "<aruba-central-account-username>",
103
+ "password": "<aruba-central-account-password>",
104
+ "client_id": "<api-gateway-client-id>",
105
+ "client_secret": "<api-gateway-client-secret>",
106
+ "customer_id": "<aruba-central-customer-id>",
107
+ "base_url": "<api-gateway-domain-url>"
108
+ }
109
+ ```
110
+ Alternatively, you can use **cluster_name** instead of **base_url** in the above mentioned dictionaries. You can find the list of clusters that are supported in the <a href="https://github.com/aruba/pycentral/blob/master/pycentral/constants.py" target="_blank">constants.py file</a>. If you would like to add support for other Central clusters, you can do so by adding it in the constants.py.
111
+ Refer the sample scripts in *step3* and *step4* for examples.
112
+
113
+ * **OR** Provide the required variables using JSON/YAML file. Refer to the sample input files to understand how the files have to be structured -
114
+ * <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/input_token_only.yaml" target="_blank">sample_scripts/input_token_only.yaml</a>
115
+ * <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/input_credentials.yaml" target="_blank">sample_scripts/input_credentials.yaml</a>
116
+ * <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/sample_scripts/input_token_only_cluster.yaml" target="_blank">sample_scripts/input_token_only_cluster_name.yaml</a>
117
+ * <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/sample_scripts/input_credentials_cluster_name.yaml" target="_blank">sample_scripts/input_credentials_cluster_name.yaml</a>
118
+
119
+ More sample input files can be found in the <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/sample_scripts/" target="_blank">sample_scripts folder</a>. Use `pycentral.workflows_utils.get_conn_from_file()` function which accepts name of the file and returns
120
+ the `ArubaCentralBase` instance object.
121
+
122
+ 3. **Making API call using pycentral base**: Using the base class `ArubaCentralBase`, any Aruba Central supported REST API calls can be made. Refer the following sample script <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/pycentral_base_sample.py" target="_blank">sample_scripts/pycentral_base_sample.py</a>
123
+
124
+ Obtain the HTTP Request related information from Aruba Central Swagger documentation or <a href="https://developer.arubanetworks.com/aruba-central/reference" target="_blank">API references</a> page in Aruba Developer Hub.
125
+
126
+ 4. **Making API call using pycentral modules**: Some API endpoints supported by Aruba Central are implemented as modules in the Python package. Refer the following sample script using modules <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/pycentral_module_sample.py" target="_blank">sample_scripts/pycentral_module_sample.py</a>
127
+
128
+ To obtain a list of implemented modules and its documentation refer the <a href="https://pycentral.readthedocs.io/en/latest/" target="_blank">pycentral module documentation</a>
129
+
130
+ 5. **Workflows**: Workflows are used to achieve an automation use-case which generally involves multiple API calls or dealing with scale and repetitive tasks with ease. Check out the <a href="https://github.com/aruba/central-python-workflows" target="_blank"> central-python-workflows </a> repository to check out workflows that utilize the Pycentral library.
131
+
132
+ ## Documentation:
133
+ * **Python package documentation:**
134
+ * <a href="https://pycentral.readthedocs.io/en/latest/" target="_blank">pycentral module documentation</a>
135
+ * **Use-Cases and Workflows:**
136
+ - <a href="https://developer.arubanetworks.com/aruba-central/docs/python-getting-started" target="_blank">Aruba Developer Hub</a>
137
+ - <a href="https://github.com/aruba/central-python-workflows" target="_blank">central-python-workflows</a>
138
+
139
+ ## Note:
140
+ The package takes one of the two approaches to gain access to Aruba Central APIs.
141
+
142
+ * **OAUTH APIs:** By taking OAUTH approach to generate new access_token, the python package will cache the tokens locally for re-use. Caching tokens locally, helps preventing creation of new access_token every time the script is run. In addition, when the access_token is expired the script will attempt to use the supplied credentials and attempt to refresh the expired token.
143
+
144
+ Override the `ArubaCentralBase.storeToken()` and `ArubaCentralBase.loadToken()` function definitions to change this behavior of caching in local file(JSON) and manage tokens more securely.
145
+
146
+ * **Access Token**: This process is more secure. By providing only the *access_token* instead of credentials, the package will not cache the tokens. But loses the ability to handle expired token and to generate new access tokens.
147
+
148
+ ## How to contribute
149
+ Please see the accompanying <a href="https://github.com/aruba/pycentral/blob/master/CONTRIBUTIONS.md" target="_blank">CONTRIBUTIONS.md</a> file for guidelines on how to contribute to this repository.
150
+
151
+ ## Troubleshooting Issues
152
+ If you encounter module import errors, make sure that the package has been installed correctly.
153
+
154
+ Additionally, please read the <a href="https://github.com/aruba/pycentral/blob/master/RELEASE-NOTES.md" target="_blank">RELEASE-NOTES.md</a> file for the current release information and known issues.
@@ -0,0 +1,24 @@
1
+ mv_pycentral-1.4.3.dist-info/licenses/LICENSE,sha256=Vc02m3OWcayZ8L-vkBhCWxFQVXpC-pvghgXdo1Sld2Q,1100
2
+ pycentral/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ pycentral/audit_logs.py,sha256=Y8jifJBuqo6xM6kajMWjH5gIJdOFyb9MT4SFnMPXTDg,8170
4
+ pycentral/base.py,sha256=4jxXITEqLeExwiovpswSbaRgXBBORo-gxVHryNcz8FA,27768
5
+ pycentral/base_utils.py,sha256=cBKjSp9xc4_bIrAYSUpcjlCxvJbbuiuhdEKZ0RaYnjU,9372
6
+ pycentral/configuration.py,sha256=O1ChMXHrfirGBnMA0tcwvk8Ehoz8oYkThJdaI26_KzU,54622
7
+ pycentral/constants.py,sha256=dirF47_FN6IZJtRkiLq4z8HBn0dWn3SSOylRvB_VUGE,2165
8
+ pycentral/device_inventory.py,sha256=ZZqM0l3X_Cws9GMGVjQEvfT8S086JOBzLKgYq086Nf8,11268
9
+ pycentral/firmware_management.py,sha256=6s0JzYz_k-GxazRVydf_UKrjMtbGq1kPIiLXwiytFYM,12354
10
+ pycentral/licensing.py,sha256=muWRQ4FKOGOBwAuyp0hBBIkm4BfwrL7CyJv43p6RSBk,21314
11
+ pycentral/monitoring.py,sha256=XySHMOvgvXT_-fH6sS7s3JZqTc2CIRpBmUZVwlygdP8,12946
12
+ pycentral/msp.py,sha256=JSn5B5PSisjLe-aRDnG-EVU0sVHpm-JCQdtwX2P1_VA,38361
13
+ pycentral/rapids.py,sha256=rUCZMfXaAgLYfxI-je8_RQ-IWVGvsKzq2AUGGRM2HIw,23062
14
+ pycentral/refresh_api_token.py,sha256=7Djr2WKyaz2BhZXi885PnAf8x-91FZYRCZSqXMsKr3Q,2815
15
+ pycentral/topology.py,sha256=gb7uy_qaUyEzvL1sfDlPpE-tGb5hHH3tdwDKCqiYfSY,5986
16
+ pycentral/url_utils.py,sha256=DhESmMxmb_1_r91_hBHSsaAlmpsE_-ox4eHDhJKjbjY,8729
17
+ pycentral/user_management.py,sha256=WTbFTpriNCHcet97hqGpNB1UBs5lNDAGZQ2ha0hMi5c,17963
18
+ pycentral/visualrf.py,sha256=1rYS9AGyAptYXOde1v2neU3nNo3wZTnSPxKSYCmURUg,14313
19
+ pycentral/workflows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ pycentral/workflows/workflows_utils.py,sha256=a5_rznJR2D0YmZDVDNi4tqST1hAU_tBHiaNiOdbMzp0,6060
21
+ mv_pycentral-1.4.3.dist-info/METADATA,sha256=xERkp5FM3kcGJ9-8RKyJN5u8yKz_ynsYJzWVnqRfpV0,9973
22
+ mv_pycentral-1.4.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
23
+ mv_pycentral-1.4.3.dist-info/top_level.txt,sha256=rZLDkAQ0eJxDByJpX0JZMeeSDpniOf5Ih9C995YfcZc,10
24
+ mv_pycentral-1.4.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Aruba, a Hewlett Packard Enterprise company
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ pycentral
pycentral/__init__.py ADDED
File without changes
@@ -0,0 +1,182 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2020 Aruba, a Hewlett Packard Enterprise company
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ from pycentral.url_utils import AuditUrl, urlJoin
24
+ from pycentral.base_utils import console_logger
25
+
26
+ urls = AuditUrl()
27
+
28
+
29
+ class Audit:
30
+ """Get the audit logs and event logs with the functions in this class."""
31
+
32
+ def get_traillogs(self, conn, limit=100, offset=0, username=None,
33
+ start_time=None, end_time=None, description=None,
34
+ target=None, classification=None, customer_name=None,
35
+ ip_address=None, app_id=None):
36
+ """Get audit logs, sort by time in in reverse chronological order.
37
+ This API returns the first 10,000 results only. Please use filter
38
+ in the API for more relevant results. MSP Customer Would see logs
39
+ of MSP's and tenants as well.
40
+
41
+ :param conn: Instance of class:`pycentral.ArubaCentralBase` to make an\
42
+ API call.
43
+ :type conn: class:`pycentral.ArubaCentralBase`
44
+ :param limit: Maximum number of audit events to be returned, defaults\
45
+ to 100
46
+ :type limit: int, optional
47
+ :param offset: Number of items to be skipped before returning the \
48
+ data, useful for pagination, defaults to 0
49
+ :type offset: int, optional
50
+ :param username: Filter audit logs by User Name, defaults to None
51
+ :type username: str, optional
52
+ :param start_time: Filter audit logs by Time Range. Start time of the\
53
+ audit logs should be provided in epoch seconds, defaults to None
54
+ :type start_time: int, optional
55
+ :param end_time: Filter audit logs by Time Range. End time of the \
56
+ audit logs should be provided in epoch seconds, defaults to None
57
+ :type end_time: int, optional
58
+ :param description: Filter audit logs by Description, defaults to \
59
+ None
60
+ :type description: str, optional
61
+ :param target: Filter audit logs by target, defaults to None
62
+ :type target: str, optional
63
+ :param classification: Filter audit logs by Classification, defaults \
64
+ to None
65
+ :type classification: str, optional
66
+ :param customer_name: Filter audit logs by Customer NameFilter audit \
67
+ logs by Customer Name, defaults to None
68
+ :type customer_name: str, optional
69
+ :param ip_address: Filter audit logs by IP Address, defaults to None
70
+ :type ip_address: str, optional
71
+ :param app_id: Filter audit logs by app_id, defaults to None
72
+ :type app_id: str, optional
73
+ :return: HTTP Response as provided by 'command' function in \
74
+ class:`pycentral.ArubaCentralBase`
75
+ :rtype: dict
76
+ """
77
+ path = urls.TRAIL_LOG["GET_ALL"]
78
+ params = {"limit": limit, "offset": offset}
79
+ if username:
80
+ params["username"] = username
81
+ if start_time:
82
+ params["start_time"] = start_time
83
+ if end_time:
84
+ params["end_time"] = end_time
85
+ if description:
86
+ params["description"] = description
87
+ if target:
88
+ params["target"] = target
89
+ if classification:
90
+ params["classification"] = classification
91
+ if customer_name:
92
+ params["customer_name"] = customer_name
93
+ if ip_address:
94
+ params["ip_address"] = ip_address
95
+ if app_id:
96
+ params["app_id"] = app_id
97
+ resp = conn.command(apiMethod="GET", apiPath=path, apiParams=params)
98
+ return resp
99
+
100
+ def get_traillogs_detail(self, conn, id):
101
+ """Get details of an audit log
102
+
103
+ :param conn: Instance of class:`pycentral.ArubaCentralBase` to make an\
104
+ API call.
105
+ :type conn: class:`pycentral.ArubaCentralBase`
106
+ :param id: ID of audit event
107
+ :type id: str
108
+ :return: HTTP Response as provided by 'command' function in \
109
+ class:`pycentral.ArubaCentralBase`
110
+ :rtype: dict
111
+ """
112
+ path = urlJoin(urls.TRAIL_LOG["GET"], id)
113
+ resp = conn.command(apiMethod="GET", apiPath=path)
114
+ return resp
115
+
116
+ def get_eventlogs(self, conn, limit=100, offset=0, group_name=None,
117
+ device_id=None, classification=None, start_time=None,
118
+ end_time=None):
119
+ """Get audit events for all groups, sort by time in in reverse\
120
+ chronological order.This API returns the first 10,000 results\
121
+ only. Please use filter in the API for more relevant results.
122
+
123
+ :param conn: Instance of class:`pycentral.ArubaCentralBase` to make an\
124
+ API call.
125
+ :type conn: class:`pycentral.ArubaCentralBase`
126
+ :param limit: Maximum number of audit events to be returned, defaults\
127
+ to 100
128
+ :type limit: int, optional
129
+ :param offset: Number of items to be skipped before returning the\
130
+ data, useful for pagination, defaults to 0
131
+ :type offset: int, optional
132
+ :param group_name: Filter audit events by Group Name, defaults to None
133
+ :type group_name: str, optional
134
+ :param device_id: Filter audit events by Target / Device ID. Device ID\
135
+ for AP is VC Name and Serial Number
136
+ for Switches, defaults to None
137
+ :type device_id: str, optional
138
+ :param classification: Filter audit events by classification, defaults\
139
+ to None
140
+ :type classification: str, optional
141
+ :param start_time: Filter audit logs by Time Range. Start time of the\
142
+ audit logs should be provided
143
+ in epoch seconds, defaults to None
144
+ :type start_time: int, optional
145
+ :param end_time: Filter audit logs by Time Range. End time of the\
146
+ audit logs should be provided in epoch
147
+ seconds, defaults to None
148
+ :type end_time: int, optional
149
+ :return: HTTP Response as provided by 'command' function in\
150
+ class:`pycentral.ArubaCentralBase`
151
+ :rtype: dict
152
+ """
153
+ path = urls.EVENT_LOG["GET_ALL"]
154
+ params = {"limit": limit, "offset": offset}
155
+ if group_name:
156
+ params["group_name"] = group_name
157
+ if device_id:
158
+ params["device_id"] = device_id
159
+ if classification:
160
+ params["classification"] = classification
161
+ if start_time:
162
+ params["start_time"] = start_time
163
+ if end_time:
164
+ params["end_time"] = end_time
165
+ resp = conn.command(apiMethod="GET", apiPath=path, apiParams=params)
166
+ return resp
167
+
168
+ def get_eventlogs_detail(self, conn, id):
169
+ """Get details of an audit event/log
170
+
171
+ :param conn: Instance of class:`pycentral.ArubaCentralBase` to make an\
172
+ API call.
173
+ :type conn: class:`pycentral.ArubaCentralBase`
174
+ :param id: ID of audit event
175
+ :type id: str
176
+ :return: HTTP Response as provided by 'command' function in\
177
+ class:`pycentral.ArubaCentralBase`
178
+ :rtype: dict
179
+ """
180
+ path = urlJoin(urls.EVENT_LOG["GET"], id)
181
+ resp = conn.command(apiMethod="GET", apiPath=path)
182
+ return resp