Azure Red Hat OpenShift Management Client Library for Python

3.0.0 · active · verified Thu Apr 09

The Microsoft Azure Red Hat OpenShift Management Client Library for Python (azure-mgmt-redhatopenshift) provides an interface to programmatically manage Azure Red Hat OpenShift resources. Currently at version 3.0.0, this library is part of the larger Azure SDK for Python ecosystem and is actively maintained with regular updates, often aligning with new OpenShift minor versions. It requires Python 3.9 or higher for operation.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `AzureRedHatOpenShiftClient` using `DefaultAzureCredential` for authentication. It assumes necessary Azure environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID) are configured. The client can then be used to interact with Azure Red Hat OpenShift resources. An example to list clusters is commented out as it requires specific Azure resources and permissions to run successfully.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.redhatopenshift import AzureRedHatOpenShiftClient

# Ensure environment variables are set for authentication:
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
# AZURE_SUBSCRIPTION_ID

# For demonstration, using os.getenv with a placeholder subscription ID.
# In a production environment, ensure these are securely configured.
subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")

# Authenticate using DefaultAzureCredential
# This attempts to authenticate via environment variables, managed identity, etc.
credential = DefaultAzureCredential()

# Create a client
client = AzureRedHatOpenShiftClient(credential=credential, subscription_id=subscription_id)

print(f"AzureRedHatOpenShiftClient initialized for subscription: {subscription_id}")

# Example: List OpenShift clusters in the subscription (requires existing clusters and permissions)
# try:
#     for cluster in client.open_shift_clusters.list():
#         print(f"Found cluster: {cluster.name} in resource group: {cluster.resource_group_name}")
# except Exception as e:
#     print(f"Could not list clusters: {e}")

print("To list clusters, ensure you have the necessary permissions and uncomment the example code.")

view raw JSON →