Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions profile-operations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,22 @@ source venv/bin/activate # On Windows use: venv\Scripts\activate
pip install -r requirements.txt
```

_This workflow is tested on the `pycentral` SDK (version: `2.0a7`). Please check compatibility before executing on older/newer versions as there may be changes_
_This workflow is tested on the `pycentral` SDK (version: `2.0a17`). Please check compatibility before executing on older/newer versions as there may be changes_

## Configuration

### Credentials Configuration (central_token.json)
### Credentials Configuration (account_credentials.yaml)

For API operations in new HPE Aruba Networking Central:

```json
{
"new_central": {
"base_url": "",
"client_id": "",
"client_secret": "",
}
}
```yaml
new_central:
cluster_name: <cluster-name> #e.g. EU-1
client_id: <new-central-client-id>
client_secret: <new-central-client-secret>
```

**Sample Input:** See [`central_token.json`](./central_token.json) in this repository for an example credential file.
**Sample Input:** See [`account_credentials.yaml`](./account_credentials.yaml) in this repository for an example credential file.

> [!TIP]
> **Where to find these:**
Expand Down
4 changes: 4 additions & 0 deletions profile-operations/account_credentials.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
new_central:
cluster_name: <cluster-name> # or base_url: <central-api-base-url>
client_id: <new-central-client-id>
client_secret: <new-central-client-secret>
7 changes: 0 additions & 7 deletions profile-operations/central_token.json

This file was deleted.

39 changes: 13 additions & 26 deletions profile-operations/profile_operations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json

from pycentral import NewCentralBase
from pycentral.profiles import Profiles
from pycentral.utils.url_utils import NewCentralURLs
from pycentral.utils.url_utils import generate_url


def main():
Expand All @@ -11,30 +9,19 @@ def main():
# to do to use either of these is initialize a Central connection. Let's see how
# to do that.

# Generating a central connection with pycentral requires passing a dictionary
# containing information to the NewCentralBase class. This dictionary should
# include the base URL, client ID, and client secret for the Central API. Best
# practice is to load this information from another file. For this example we will
# load the credentials from a JSON file named 'central_token.json'. Please
# reference the 'central_token.json' file in this directory for an example of how
# the credential information should be structured.

# Load the credentials from the JSON file
try:
with open("central_token.json", "r") as file:
credentials = json.load(file)
except FileNotFoundError:
print("Error: Credentials file central_token.json not found.")
return 1
except json.JSONDecodeError as e:
print(f"Error parsing JSON file 'central_token.json': {e}")
return 1
# Generating a central connection with pycentral requires passing credential
# information to the NewCentralBase class. Required credential information includes
# the Central base URL/cluster, client ID, and client secret for the Central API.
# Best practice is to load this information from another file. For this example we
# will load the credentials from a YAML file named 'account_credentials.yaml'.
# Please reference the 'account_credentials.yaml' file in this directory for an
# example of how the credential information should be structured.

# Now that we have the credentials, we can create a connection to Central.
# Create a connection to Central using the account credentials file.
try:
print("Connecting to Central...")
central_conn = NewCentralBase(
token_info=credentials, enable_scope=True, log_level="ERROR"
token_info="account_credentials.yaml", enable_scope=True, log_level="ERROR"
)
print("Connected to Central successfully!")
except Exception as e:
Expand Down Expand Up @@ -66,7 +53,7 @@ def main():
}
# Finally, we use the generate_url function to create the full URL for the API
# endpoint that will be consumed by the Pycentral functions.
dns_url = NewCentralURLs.generate_url(api_endpoint=dns_endpoint)
dns_url = generate_url(api_endpoint=dns_endpoint)

# Let's try creating a DNS profile using the create_profile function. We simply
# need to pass the data we have prepared to the function along with the Central
Expand Down Expand Up @@ -155,7 +142,7 @@ def main():
"is-l3-vlan": None,
}
# Generate the URL for the VLAN endpoint.
vlan_url = NewCentralURLs.generate_url(api_endpoint=vlan_endpoint)
vlan_url = generate_url(api_endpoint=vlan_endpoint)

# Let's try creating several VLAN profiles using the bulk create_profiles
# function. We can create a list of dictionaries containing the profile
Expand Down Expand Up @@ -216,7 +203,7 @@ def main():
print("\nDeleting VLAN profiles...")
# Create a list of URLs with identifiers to delete the profiles.
path_list = [
NewCentralURLs.generate_url(api_endpoint=vlan_endpoint) + f"/{profile['vlan']}"
generate_url(api_endpoint=vlan_endpoint) + f"/{profile['vlan']}"
for profile in vlan_profiles
]
bulk_delete = Profiles.delete_profiles(
Expand Down
2 changes: 1 addition & 1 deletion profile-operations/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pycentral==2.0a7
pycentral==2.0a17
Loading