pycentral


Namepycentral JSON
Version 1.4 PyPI version JSON
download
home_pagehttps://github.com/aruba/pycentral
SummaryAruba Central Python Package
upload_time2024-04-05 14:24:06
maintainerNone
docs_urlNone
authoraruba-automation
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pycentral
#### Aruba Central Python Package Index SDK

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.

### How To Install
In order to run the workflow scripts, please complete the steps below:
1. install virtual env (refer https://docs.python.org/3/library/venv.html). Make sure python version 3 is installed in system.
    ```
    $ python3 -m venv centralenv
    ```

2. Activate the virtual env
    ```
    $ source centralenv/bin/activate
    in Windows:
    $ centralenv/Scripts/activate.bat
    ```

3. Install the **pycentral** package
    ```
    (centralenv)$ pip3 install pycentral
    ```

    To install package with *extras* `colorLog` which will display log in color
    ```
    (centralenv)$ pip3 install pycentral[colorLog]
    ```

Now you can start making your script based on modules in pycentral or use different workflows from the subpackage `workflows`.

## Executing Scripts

1. Gathering variables required for the package base class `ArubaCentralBase`.

    * **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.

   * **access_token**: You can create an API access token for Aruba Central from -
      * <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>
      * <a href="https://developer.arubanetworks.com/aruba-central/docs/api-oauth-access-token" target="_blank">OAuth APIs</a>

    * 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.
      * **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.
  
      * **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.
    
      * **customer_id**: Obtain the **customer_id** by clicking on the figure icon on top right corner of Aruba Central WebUI.

    ![Customer ID](https://github.com/aruba/pycentral/raw/master/pictures/customer-id.png)


2. Providing input variables to the Python scripts. One of the following options can be used.
    * Provide variables directly to Aruba Central Base class in dictionary format.

        Access token approach:
        ```python
        central_info = {
            "base_url": "<api-gateway-domain-url>",
            "token": {
                "access_token": "<api-gateway-access-token>"
            }
        }
        ```

        OAUTH APIs approach with capability to generate new access token:
        ```python
            central_info = {
                "username": "<aruba-central-account-username>",
                "password": "<aruba-central-account-password>",
                "client_id": "<api-gateway-client-id>",
                "client_secret": "<api-gateway-client-secret>",
                "customer_id": "<aruba-central-customer-id>",
                "base_url": "<api-gateway-domain-url>"
            }
        ```
        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. 
        Refer the sample scripts in *step3* and *step4* for examples.

    * **OR** Provide the required variables using JSON/YAML file. Refer to the sample input files to understand how the files have to be structured -
      * <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/input_token_only.yaml" target="_blank">sample_scripts/input_token_only.yaml</a>
      * <a href="https://github.com/aruba/pycentral/blob/master/sample_scripts/input_credentials.yaml" target="_blank">sample_scripts/input_credentials.yaml</a> 
      * <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>
      * <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>

        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
        the `ArubaCentralBase` instance object.

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>

    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.

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>

    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>

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.

## Documentation:
* **Python package documentation:** 
* <a href="https://pycentral.readthedocs.io/en/latest/" target="_blank">pycentral module documentation</a>
* **Use-Cases and Workflows:**
  - <a href="https://developer.arubanetworks.com/aruba-central/docs/python-getting-started" target="_blank">Aruba Developer Hub</a>
  - <a href="https://github.com/aruba/central-python-workflows" target="_blank">central-python-workflows</a>

## Note:
 The package takes one of the two approaches to gain access to Aruba Central APIs.

  * **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.

    Override the `ArubaCentralBase.storeToken()` and `ArubaCentralBase.loadToken()` function definitions to change this behavior of caching in local file(JSON) and manage tokens more securely.

 * **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.

## How to contribute
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.

## Troubleshooting Issues
If you encounter module import errors, make sure that the package has been installed correctly.

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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aruba/pycentral",
    "name": "pycentral",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "aruba-automation",
    "author_email": "aruba-automation@hpe.com",
    "download_url": "https://files.pythonhosted.org/packages/64/e9/c257ec9fca5b74441526add8d5b09d731ae7df6dc2131a55cccb962934ef/pycentral-1.4.tar.gz",
    "platform": null,
    "description": "# pycentral\n#### Aruba Central Python Package Index SDK\n\nAruba 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.\n\n### How To Install\nIn order to run the workflow scripts, please complete the steps below:\n1. install virtual env (refer https://docs.python.org/3/library/venv.html). Make sure python version 3 is installed in system.\n    ```\n    $ python3 -m venv centralenv\n    ```\n\n2. Activate the virtual env\n    ```\n    $ source centralenv/bin/activate\n    in Windows:\n    $ centralenv/Scripts/activate.bat\n    ```\n\n3. Install the **pycentral** package\n    ```\n    (centralenv)$ pip3 install pycentral\n    ```\n\n    To install package with *extras* `colorLog` which will display log in color\n    ```\n    (centralenv)$ pip3 install pycentral[colorLog]\n    ```\n\nNow you can start making your script based on modules in pycentral or use different workflows from the subpackage `workflows`.\n\n## Executing Scripts\n\n1. Gathering variables required for the package base class `ArubaCentralBase`.\n\n    * **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.\n\n   * **access_token**: You can create an API access token for Aruba Central from -\n      * <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>\n      * <a href=\"https://developer.arubanetworks.com/aruba-central/docs/api-oauth-access-token\" target=\"_blank\">OAuth APIs</a>\n\n    * 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.\n      * **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.\n  \n      * **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.\n    \n      * **customer_id**: Obtain the **customer_id** by clicking on the figure icon on top right corner of Aruba Central WebUI.\n\n    ![Customer ID](https://github.com/aruba/pycentral/raw/master/pictures/customer-id.png)\n\n\n2. Providing input variables to the Python scripts. One of the following options can be used.\n    * Provide variables directly to Aruba Central Base class in dictionary format.\n\n        Access token approach:\n        ```python\n        central_info = {\n            \"base_url\": \"<api-gateway-domain-url>\",\n            \"token\": {\n                \"access_token\": \"<api-gateway-access-token>\"\n            }\n        }\n        ```\n\n        OAUTH APIs approach with capability to generate new access token:\n        ```python\n            central_info = {\n                \"username\": \"<aruba-central-account-username>\",\n                \"password\": \"<aruba-central-account-password>\",\n                \"client_id\": \"<api-gateway-client-id>\",\n                \"client_secret\": \"<api-gateway-client-secret>\",\n                \"customer_id\": \"<aruba-central-customer-id>\",\n                \"base_url\": \"<api-gateway-domain-url>\"\n            }\n        ```\n        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. \n        Refer the sample scripts in *step3* and *step4* for examples.\n\n    * **OR** Provide the required variables using JSON/YAML file. Refer to the sample input files to understand how the files have to be structured -\n      * <a href=\"https://github.com/aruba/pycentral/blob/master/sample_scripts/input_token_only.yaml\" target=\"_blank\">sample_scripts/input_token_only.yaml</a>\n      * <a href=\"https://github.com/aruba/pycentral/blob/master/sample_scripts/input_credentials.yaml\" target=\"_blank\">sample_scripts/input_credentials.yaml</a> \n      * <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>\n      * <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>\n\n        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\n        the `ArubaCentralBase` instance object.\n\n3. **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>\n\n    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.\n\n4. **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>\n\n    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>\n\n5. **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.\n\n## Documentation:\n* **Python package documentation:** \n* <a href=\"https://pycentral.readthedocs.io/en/latest/\" target=\"_blank\">pycentral module documentation</a>\n* **Use-Cases and Workflows:**\n  - <a href=\"https://developer.arubanetworks.com/aruba-central/docs/python-getting-started\" target=\"_blank\">Aruba Developer Hub</a>\n  - <a href=\"https://github.com/aruba/central-python-workflows\" target=\"_blank\">central-python-workflows</a>\n\n## Note:\n The package takes one of the two approaches to gain access to Aruba Central APIs.\n\n  * **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.\n\n    Override the `ArubaCentralBase.storeToken()` and `ArubaCentralBase.loadToken()` function definitions to change this behavior of caching in local file(JSON) and manage tokens more securely.\n\n * **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.\n\n## How to contribute\nPlease 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.\n\n## Troubleshooting Issues\nIf you encounter module import errors, make sure that the package has been installed correctly.\n\nAdditionally, 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.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Aruba Central Python Package",
    "version": "1.4",
    "project_urls": {
        "Homepage": "https://github.com/aruba/pycentral"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "51ace6e479e1dcc83cb172a84e0ccf8c10743deecde397f441874bf80394dbb5",
                "md5": "1533a4b718447f8d0cbdd334c3a97e6d",
                "sha256": "48036ee12c19db70e4b323ffaca1cdd3f721d1b3c7660785ba100dbe1c372ac4"
            },
            "downloads": -1,
            "filename": "pycentral-1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1533a4b718447f8d0cbdd334c3a97e6d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 60349,
            "upload_time": "2024-04-05T14:24:04",
            "upload_time_iso_8601": "2024-04-05T14:24:04.410917Z",
            "url": "https://files.pythonhosted.org/packages/51/ac/e6e479e1dcc83cb172a84e0ccf8c10743deecde397f441874bf80394dbb5/pycentral-1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "64e9c257ec9fca5b74441526add8d5b09d731ae7df6dc2131a55cccb962934ef",
                "md5": "2bbf4f44da7db52b6831aef02b8a0f27",
                "sha256": "34f560fc09f595d7de306ad373c29b1ae68fc43aab3596a4946fd9683377e220"
            },
            "downloads": -1,
            "filename": "pycentral-1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "2bbf4f44da7db52b6831aef02b8a0f27",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 46492,
            "upload_time": "2024-04-05T14:24:06",
            "upload_time_iso_8601": "2024-04-05T14:24:06.544351Z",
            "url": "https://files.pythonhosted.org/packages/64/e9/c257ec9fca5b74441526add8d5b09d731ae7df6dc2131a55cccb962934ef/pycentral-1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-05 14:24:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aruba",
    "github_project": "pycentral",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pycentral"
}
        
Elapsed time: 0.21648s