diff --git a/README.md b/README.md index 260f75f..3121790 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,32 @@ -# DTIAS Examples +# Dell TELCO Infrastructure Automation Suite (DTIAS) Examples + +- [Dell TELCO Infrastructure Automation Suite (DTIAS) Examples](#dell-telco-infrastructure-automation-suite-dtias-examples) + - [What is DTIAS?](#what-is-dtias) + - [About This Repository](#about-this-repository) + - [Useful Links](#useful-links) + - [Contributing](#contributing) + - [DTIAS Installation](#dtias-installation) + - [Install DTIAS on Ubuntu 20.04](#install-dtias-on-ubuntu-2004) + - [Install DTIAS on RHEL](#install-dtias-on-rhel) + +## What is DTIAS? + +DTIAS is designed to handle environments with large numbers of heterogenous servers. You don't need to be a TELCO to use it, but this is a core problem TELCOs face. DTIAS supports both HPE and Dell and has the ability to perform full lifecycle management of the servers. It has built in functionality to take a server from bare metal to with a few clicks standardized BIOS settings, up to date firmware, and a deployed and configured operating system. + +## About This Repository + +This repository is dedicated to demonstrating the capabilities of Dell DTIAS. It has [API usage examples](./dtias_api_examples/) which show off how to control DTIAS through the API and a [blueprint repository](./blueprints/) with a host of useful, prebuilt, blueprints you can deploy. + +## Useful Links + +- [DTIAS REST API Documentation](https://developer.dell.com/apis/7ce7d11a-ff9c-47cc-b958-bd30dc9770f0/versions/2.1.0/docs/introduction.md) + - Note: DTIAS has recently merged with Cloudify. If you notice discrepancies in the API documentation feel free to open a ticket on this repository. ## Contributing For required coding style and structure guidelines see [CONTRIBUTING.md](./CONTRIBUTING.md) -## Installation +## DTIAS Installation ```bash sudo dnf install epel-release -y diff --git a/dtias-examples/readme.md b/blueprints/README.md similarity index 96% rename from dtias-examples/readme.md rename to blueprints/README.md index d78e916..f4a618a 100644 --- a/dtias-examples/readme.md +++ b/blueprints/README.md @@ -17,4 +17,4 @@ The playbook_source_url should be the URL to your uploaded playbook package and ## Step 3: Create Deployment Create a deployment using the uploaded blueprint via DTIAS REST API (refer to [DTIAS API usage guide](https://stoplight.dell.com/docs/fulcrum-rest-api-guide/d6a8ba3f3c186-introduction-dell-telecom-infrastructure-automation-foundation-1-1-rest-ap-is) on syntax): -POST https://dtiaf_ip/v1/tenants/default/deployments. Include your input values from `bp-inputs.yaml` inside the request body. After the deployment succeeds, you should see the desired effect of your Ansible playbook on your specified remote host. \ No newline at end of file +POST https://dtiaf_ip/v1/tenants/default/deployments. Include your input values from `bp-inputs.yaml` inside the request body. After the deployment succeeds, you should see the desired effect of your Ansible playbook on your specified remote host. diff --git a/dtias-examples/remote-host-execution/antivirus-playbook.yaml b/blueprints/remote-host-execution/antivirus-playbook.yaml similarity index 100% rename from dtias-examples/remote-host-execution/antivirus-playbook.yaml rename to blueprints/remote-host-execution/antivirus-playbook.yaml diff --git a/dtias-examples/remote-host-execution/bp-inputs.yaml b/blueprints/remote-host-execution/bp-inputs.yaml similarity index 100% rename from dtias-examples/remote-host-execution/bp-inputs.yaml rename to blueprints/remote-host-execution/bp-inputs.yaml diff --git a/dtias-examples/remote-host-execution/remotehost-blueprint.yaml b/blueprints/remote-host-execution/remotehost-blueprint.yaml similarity index 100% rename from dtias-examples/remote-host-execution/remotehost-blueprint.yaml rename to blueprints/remote-host-execution/remotehost-blueprint.yaml diff --git a/dtias-examples/remote-host-execution/simple-playbook.yaml b/blueprints/remote-host-execution/simple-playbook.yaml similarity index 100% rename from dtias-examples/remote-host-execution/simple-playbook.yaml rename to blueprints/remote-host-execution/simple-playbook.yaml diff --git a/dtias-examples/api_examples/get_ditias_token.py b/dtias-examples/api_examples/get_ditias_token.py deleted file mode 100644 index 93fa66c..0000000 --- a/dtias-examples/api_examples/get_ditias_token.py +++ /dev/null @@ -1,55 +0,0 @@ -import argparse -import requests - - -def create_token(server_ip, tenant_id, username, password): - """ - Creates a token for the DTIAS server. - - Parameters: - server_ip (str): The IP address of the DTIAS server. - tenant_id (str): The tenant ID (e.g., "Fulcrum"). - username (str): The username to authenticate with. - password (str): The password for the username. - - Returns: - dict: A dictionary containing the access token, id token, and refresh token. - """ - url = f"https://{server_ip}/identity/v1/tenant/{tenant_id}/token/create" - headers = {"Content-Type": "application/json"} - data = { - "grant_type": "password", - "client_id": "ccpapi", - "username": username, - "password": password - } - - try: - response = requests.post(url, headers=headers, json=data, verify=False) # Set verify=False for self-signed certs. - response.raise_for_status() # Raise an error for HTTP codes 4xx/5xx. - return response.json() # Return the JSON response with tokens. - except requests.exceptions.RequestException as e: - print(f"Error: {e}") - return None - - -if __name__ == "__main__": - # Set up argparse - parser = argparse.ArgumentParser(description="Generate a token for the DTIAS server.") - parser.add_argument("--server_ip", required=True, help="The IP address of the DTIAS server.") - parser.add_argument("--tenant_id", default="Fulcrum", help="The tenant ID (default: Fulcrum).") - parser.add_argument("--username", required=True, help="The username to authenticate with.") - parser.add_argument("--password", required=True, help="The password for the username.") - - # Parse arguments - args = parser.parse_args() - - # Generate the token - tokens = create_token(args.server_ip, args.tenant_id, args.username, args.password) - if tokens: - print("Tokens created successfully!") - print("Access Token:", tokens.get("access_token")) - print("ID Token:", tokens.get("id_token")) - print("Refresh Token:", tokens.get("refresh_token")) - else: - print("Failed to create tokens.") diff --git a/dtias-examples/api_examples/notes.md b/dtias-examples/api_examples/notes.md deleted file mode 100644 index f01ea0a..0000000 --- a/dtias-examples/api_examples/notes.md +++ /dev/null @@ -1,3 +0,0 @@ -- You have to use Fulcrum as your client ID -- You have to add the API version -- What is the server namespace? \ No newline at end of file diff --git a/dtias-examples/api_examples/apply_hardware_profile.py b/dtias_api_examples/apply_hardware_profile.py similarity index 82% rename from dtias-examples/api_examples/apply_hardware_profile.py rename to dtias_api_examples/apply_hardware_profile.py index 1f7ef48..c54348b 100644 --- a/dtias-examples/api_examples/apply_hardware_profile.py +++ b/dtias_api_examples/apply_hardware_profile.py @@ -1,3 +1,32 @@ +""" +#### Synopsis +Script to retrieve and apply hardware profiles on servers using DTIAS + +#### Description +This script uses the DTIAS REST API to: +1. Authenticate with the server and generate an authentication token. +2. Retrieve the list of available hardware profiles. +3. Apply a specified hardware profile to a given list of servers. + +The script disables SSL warnings for ease of use in environments with self-signed certificates. It requires the user +to specify the target hardware profile and the servers on which it should be applied. + +#### Python Example +```bash +python apply_hardware_profile.py --server_ip --tenant_id --username \ +--password --profile_name --servers +``` + +where: + +- server_ip is the IP address of the DTIAS server. +- tenant_id is the tenant name (default: Fulcrum). +- username and password are the credentials for authentication. +- profile_name specifies the name of the hardware profile to apply. + +servers is a comma-separated list of server names to apply the profile to. +""" + import argparse import requests import urllib3 @@ -124,10 +153,10 @@ def apply_hardware_profile(server_ip, id_token, profile, servers): if __name__ == "__main__": # Set up argparse for command-line argument parsing parser = argparse.ArgumentParser(description="Retrieve and apply hardware profiles.") - parser.add_argument("--server_ip", default="172.21.0.215", required=True, + parser.add_argument("--server_ip", required=True, help="The IP address of the DTIAS server.") parser.add_argument("--tenant_id", default="Fulcrum", help="The tenant ID (default: Fulcrum).") - parser.add_argument("--username", default="admin", required=True, help="The username to authenticate with.") + parser.add_argument("--username", required=True, help="The username to authenticate with.") parser.add_argument("--password", required=True, help="The password for the username.") parser.add_argument("--profile_name", required=True, help="The name of the hardware profile.") diff --git a/dtias_api_examples/get_ditias_token.py b/dtias_api_examples/get_ditias_token.py new file mode 100644 index 0000000..1c34449 --- /dev/null +++ b/dtias_api_examples/get_ditias_token.py @@ -0,0 +1,140 @@ +""" +#### Synopsis +Script to authenticate with DTIAS and retrieve resources. + +#### Description +This script performs the following actions: +1. Authenticates with the DTIAS REST API using provided credentials. +2. Retrieves a list of resources based on optional filters and pagination parameters. + +The script allows flexible filtering and pagination for resource retrieval, enabling efficient querying. + +#### Python Example +```bash +python get_resources.py --server_ip --tenant_id --username \ +--password --filters '{"Key": "Value"}' --pagination '{"offset": 0, "limit": 10}' + +where: + +- server_ip is the IP address of the DTIAS server. +- tenant_id is the tenant name (default: Fulcrum). +- username and password are the credentials for authentication. +- filters specifies query filters as a JSON string (optional). +- pagination specifies pagination parameters as a JSON string (optional). +""" + +import argparse +import requests +import urllib3 + +# Disable SSL warnings globally +urllib3.disable_warnings() + +def create_token(server_ip, tenant_id, username, password): + """ + Creates a token for the DTIAS server. + + Parameters: + server_ip (str): The IP address of the DTIAS server. + tenant_id (str): The tenant ID (e.g., "Fulcrum"). + username (str): The username to authenticate with. + password (str): The password for the username. + + Returns: + dict: A dictionary containing the access token, id token, and refresh token. + """ + url = f"https://{server_ip}/identity/v1/tenant/{tenant_id}/token/create" + headers = {"Content-Type": "application/json"} + data = { + "grant_type": "password", + "client_id": "ccpapi", + "username": username, + "password": password + } + + try: + response = requests.post(url, headers=headers, json=data, verify=False) # Set verify=False for self-signed certs. + response.raise_for_status() # Raise an error for HTTP codes 4xx/5xx. + return response.json() # Return the JSON response with tokens. + except requests.exceptions.RequestException as e: + print(f"Error: {e}") + return None + +def get_resources(server_ip, tenant_id, id_token, filters=None, pagination=None): + """ + Retrieves resources from the DTIAS server. + + Parameters: + server_ip (str): The IP address of the DTIAS server. + tenant_id (str): The tenant ID (e.g., "Fulcrum"). + id_token (str): The ID token for authentication. + filters (list): List of filters for querying resources (optional). + pagination (dict): Pagination parameters such as offset and limit (optional). + + Returns: + dict: Resources data. + """ + url = f"https://{server_ip}/v1/tenants/{tenant_id}/search/resources" + headers = { + "accept": "application/json, text/plain, */*", + "authorization": f"Bearer {id_token}", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + } + data = {} + if filters: + data["Filters"] = filters + if pagination: + data.update(pagination) + + try: + response = requests.post(url, headers=headers, json=data, verify=False) + response.raise_for_status() + return response.json() + except requests.exceptions.RequestException as e: + print(f"Error retrieving resources: {e}") + return None + +if __name__ == "__main__": + # Set up argparse + parser = argparse.ArgumentParser(description="Retrieve resources from the DTIAS server.") + parser.add_argument("--server_ip", required=True, help="The IP address of the DTIAS server.") + parser.add_argument("--tenant_id", default="Fulcrum", help="The tenant ID (default: Fulcrum).") + parser.add_argument("--username", required=True, help="The username to authenticate with.") + parser.add_argument("--password", required=True, help="The password for the username.") + parser.add_argument("--filters", help="Filters for querying resources as JSON string (optional).", default=None) + parser.add_argument("--pagination", help="Pagination parameters as JSON string (optional).", default=None) + + # Parse arguments + args = parser.parse_args() + + # Generate the token + tokens = create_token(args.server_ip, args.tenant_id, args.username, args.password) + if not tokens: + print("Failed to generate token. Exiting...") + exit(1) + + id_token = tokens.get("id_token") + + # Step 2: Retrieve resources + filters = None + if args.filters: + try: + filters = eval(args.filters) # Safely parse JSON-like string + except Exception as e: + print(f"Error parsing filters: {e}") + exit(1) + + pagination = None + if args.pagination: + try: + pagination = eval(args.pagination) # Safely parse JSON-like string + except Exception as e: + print(f"Error parsing pagination: {e}") + exit(1) + + resources_data = get_resources(args.server_ip, args.tenant_id, id_token, filters, pagination) + if resources_data: + print("Resources Retrieved Successfully:") + print(resources_data) + else: + print("Failed to retrieve resources.") diff --git a/dtias-examples/api_examples/get_hardware_profiles.py b/dtias_api_examples/get_hardware_profiles.py similarity index 82% rename from dtias-examples/api_examples/get_hardware_profiles.py rename to dtias_api_examples/get_hardware_profiles.py index f42ddfd..bc71629 100644 --- a/dtias-examples/api_examples/get_hardware_profiles.py +++ b/dtias_api_examples/get_hardware_profiles.py @@ -1,6 +1,29 @@ +""" +#### Synopsis +Script to retrieve hardware profiles from DTIAS + +#### Description +This script uses the DTIAS REST API to retrieve a list of hardware profiles. It authenticates using a token obtained +via the API and retrieves the profiles associated with the specified tenant. + +#### Python Example +```bash +python get_hardware_profiles.py --server_ip --tenant_id --username --password +``` + +where: + +- server_ip is the IP address of the DTIAS server. +- tenant_id is the tenant name (default: metalweaver). +- username and password are the credentials for authentication. +""" + import argparse import requests +import urllib3 +# Disable SSL warnings globally +urllib3.disable_warnings() def create_token(server_ip, tenant_id, username, password): """ diff --git a/dtias_api_examples/get_metrics_data.py b/dtias_api_examples/get_metrics_data.py new file mode 100644 index 0000000..9de193b --- /dev/null +++ b/dtias_api_examples/get_metrics_data.py @@ -0,0 +1,138 @@ +import argparse +import requests +import urllib3 + +# Disable SSL warnings globally +urllib3.disable_warnings() + +""" +#### Synopsis +Script to retrieve metrics data from DTIAS + +#### Description +This script authenticates with the DTIAS REST API to retrieve metrics data for a specified resource. It supports +optional filters and metric IDs to customize the query. + +#### Python Example +```bash +python get_metrics_data.py --server_ip --tenant_id --username \ +--password --resource --metrics_filter '{"Key": "Value"}' +``` +where: +- `server_ip` is the IP address of the DTIAS server. +- `tenant_id` is the tenant name (default: Fulcrum). +- `username` and `password` are the credentials for authentication. +- `resource` specifies the resource for which metrics are queried. +- `metrics_filter` specifies additional filters as a JSON string (optional). + +The script workflow includes: +1. Generating an authentication token. +2. Using the token to retrieve metrics data for the specified resource. + +#### Notes +- SSL warnings are disabled for environments with self-signed certificates. +- The script handles errors gracefully, providing useful error messages for failed requests. +""" + +def create_token(server_ip, tenant_id, username, password): + """ + Creates a token for the DTIAS server. + + Parameters: + server_ip (str): The IP address of the DTIAS server. + tenant_id (str): The tenant ID (e.g., "Fulcrum"). + username (str): The username to authenticate with. + password (str): The password for the username. + + Returns: + dict: A dictionary containing the access token, id token, and refresh token. + """ + url = f"https://{server_ip}/identity/v1/tenant/{tenant_id}/token/create" + headers = {"Content-Type": "application/json"} + data = { + "grant_type": "password", + "client_id": "ccpapi", + "username": username, + "password": password + } + + try: + response = requests.post(url, headers=headers, json=data, verify=False) # Set verify=False for self-signed certs. + response.raise_for_status() # Raise an error for HTTP codes 4xx/5xx. + return response.json() # Return the JSON response with tokens. + except requests.exceptions.RequestException as e: + print(f"Error: {e}") + return None + +def get_metrics_data(server_ip, tenant_id, resource, id_token, metric_id=None, metrics_filter=None): + """ + Retrieves metrics data from the DTIAS server. + + Parameters: + server_ip (str): The IP address of the DTIAS server. + tenant_id (str): The tenant ID (e.g., "Fulcrum"). + resource (str): The resource type to query metrics for. + id_token (str): The ID token for authentication. + metric_id (str): The ID of the specific metric to query (optional). + metrics_filter (dict): Additional filter criteria for metrics (optional). + + Returns: + dict: Metrics data. + """ + url = f"https://{server_ip}/v1/tenants/Fulcrum/{resource}/metrics/query" + headers = { + "accept": "application/json, text/plain, */*", + "authorization": f"Bearer {id_token}", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + } + data = {} + if metric_id: + data["MetricId"] = metric_id + if metrics_filter: + data["MetricsFilter"] = metrics_filter + + try: + response = requests.post(url, headers=headers, json=data, verify=False) + response.raise_for_status() + return response.json() + except requests.exceptions.RequestException as e: + print(f"Error retrieving metrics data: {e}") + return None + +if __name__ == "__main__": + # Set up argparse + parser = argparse.ArgumentParser(description="Retrieve metrics data from the DTIAS server.") + parser.add_argument("--server_ip", required=True, help="The IP address of the DTIAS server.") + parser.add_argument("--tenant_id", default="Fulcrum", help="The tenant ID (e.g., 'Fulcrum').") + parser.add_argument("--resource", required=True, help="The resource type to query metrics for.") + parser.add_argument("--username", required=True, help="The username to authenticate with.") + parser.add_argument("--password", required=True, help="The password for the username.") + parser.add_argument("--metric_id", help="The ID of the specific metric to query (optional).", default=None) + parser.add_argument("--metrics_filter", help="Additional filter criteria for metrics as JSON string (optional).", default=None) + + # Parse arguments + args = parser.parse_args() + + # Step 1: Generate the token + tokens = create_token(args.server_ip, args.tenant_id, args.username, args.password) + if not tokens: + print("Failed to generate token. Exiting...") + exit(1) + + id_token = tokens.get("id_token") + + # Step 2: Retrieve metrics data + metrics_filter = None + if args.metrics_filter: + try: + metrics_filter = eval(args.metrics_filter) # Safely parse JSON-like string + except Exception as e: + print(f"Error parsing metrics_filter: {e}") + exit(1) + + metrics_data = get_metrics_data(args.server_ip, args.tenant_id, args.resource, id_token, args.metric_id, metrics_filter) + if metrics_data: + print("Metrics Data Retrieved Successfully:") + print(metrics_data) + else: + print("Failed to retrieve metrics data.") diff --git a/dtias_api_examples/get_resources.py b/dtias_api_examples/get_resources.py new file mode 100644 index 0000000..bbd4543 --- /dev/null +++ b/dtias_api_examples/get_resources.py @@ -0,0 +1,138 @@ +""" +#### Synopsis +Script to retrieve resources from DTIAS + +#### Description +This script uses the DTIAS REST API to retrieve resources based on the specified filters. It authenticates using a +token obtained via the API. The script supports optional filters and pagination for resource queries. + +#### Python Example +```bash +python get_resources.py --server_ip --tenant_id --username \ +--password --filters '{"Key": "Value"}' --pagination '{"offset": 0, "limit": 10}' +``` +where: +- `server_ip` is the IP address of the DTIAS server. +- `tenant_id` is the tenant name (default: Fulcrum). +- `username` and `password` are the credentials for authentication. +- `filters` specifies query filters as a JSON string (optional). +- `pagination` specifies pagination parameters as a JSON string (optional). +""" + +import argparse +import pprint +import requests + +import urllib3 + +# Disable SSL warnings globally +urllib3.disable_warnings() + +def create_token(server_ip, tenant_id, username, password): + """ + Creates a token for the DTIAS server. + + Parameters: + server_ip (str): The IP address of the DTIAS server. + tenant_id (str): The tenant ID (e.g., "Fulcrum"). + username (str): The username to authenticate with. + password (str): The password for the username. + + Returns: + dict: A dictionary containing the access token, id token, and refresh token. + """ + url = f"https://{server_ip}/identity/v1/tenant/{tenant_id}/token/create" + headers = {"Content-Type": "application/json"} + data = { + "grant_type": "password", + "client_id": "ccpapi", + "username": username, + "password": password + } + + try: + response = requests.post(url, headers=headers, json=data, verify=False) # Set verify=False for self-signed certs. + response.raise_for_status() # Raise an error for HTTP codes 4xx/5xx. + return response.json() # Return the JSON response with tokens. + except requests.exceptions.RequestException as e: + print(f"Error: {e}") + return None + +def get_resources(server_ip, tenant_id, id_token, filters=None, pagination=None): + """ + Retrieves resources from the DTIAS server. + + Parameters: + server_ip (str): The IP address of the DTIAS server. + tenant_id (str): The tenant ID (e.g., "Fulcrum"). + id_token (str): The ID token for authentication. + filters (list): List of filters for querying resources (optional). + pagination (dict): Pagination parameters such as offset and limit (optional). + + Returns: + dict: Resources data. + """ + url = f"https://{server_ip}/v1/tenants/{tenant_id}/search/resources" + headers = { + "accept": "application/json, text/plain, */*", + "authorization": f"Bearer {id_token}", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + } + data = {} + if filters: + data["Filters"] = filters + if pagination: + data.update(pagination) + + try: + response = requests.post(url, headers=headers, json=data, verify=False) + response.raise_for_status() + return response.json() + except requests.exceptions.RequestException as e: + print(f"Error retrieving resources: {e}") + return None + +if __name__ == "__main__": + # Set up argparse + parser = argparse.ArgumentParser(description="Retrieve resources from the DTIAS server.") + parser.add_argument("--server_ip", required=True, help="The IP address of the DTIAS server.") + parser.add_argument("--tenant_id", default="Fulcrum", help="The tenant ID (default: Fulcrum).") + parser.add_argument("--username", required=True, help="The username to authenticate with.") + parser.add_argument("--password", required=True, help="The password for the username.") + parser.add_argument("--filters", help="Filters for querying resources as JSON string (optional).", default=None) + parser.add_argument("--pagination", help="Pagination parameters as JSON string (optional).", default=None) + + # Parse arguments + args = parser.parse_args() + + # Generate the token + tokens = create_token(args.server_ip, args.tenant_id, args.username, args.password) + if not tokens: + print("Failed to generate token. Exiting...") + exit(1) + + id_token = tokens.get("id_token") + + # Step 2: Retrieve resources + filters = None + if args.filters: + try: + filters = eval(args.filters) # Safely parse JSON-like string + except Exception as e: + print(f"Error parsing filters: {e}") + exit(1) + + pagination = None + if args.pagination: + try: + pagination = eval(args.pagination) # Safely parse JSON-like string + except Exception as e: + print(f"Error parsing pagination: {e}") + exit(1) + + resources_data = get_resources(args.server_ip, args.tenant_id, id_token, filters, pagination) + if resources_data: + print("Resources Retrieved Successfully:") + pprint.pprint((resources_data)) + else: + print("Failed to retrieve resources.")