Azure Red Hat OpenShift Management Client Library for Python
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
- breaking Starting with version 1.5.0, this package exclusively targets the latest Azure API-Version, removing APIs for older versions. Applications requiring a specific, non-latest API-Version should pin to an earlier package version.
- breaking The credential system was completely revamped. Old `azure.common.credentials` or `msrestazure.azure_active_directory` instances are no longer supported. The `credentials` parameter was renamed to `credential`.
- breaking Operations that previously returned `msrest.polling.LROPoller` now return `azure.core.polling.LROPoller` and are prefixed with `begin_` (e.g., `create_or_update` becomes `begin_create_or_update`).
- gotcha Azure Red Hat OpenShift cluster creation typically requires a minimum of 44 vCPUs (or 40 cores in some older documentation) across various VM families. Default Azure subscription quotas are often lower, leading to deployment failures if not increased.
- gotcha This library (and the broader Azure SDK for Python) requires Python 3.9+. Support for Python 2.7 officially ended on January 01, 2022.
- gotcha Certain operation groups (e.g., `OpenShiftClustersOperations`, `OpenShiftVersionsOperations`) should not be instantiated directly. Instead, they are accessed as attributes of the `AzureRedHatOpenShiftClient` instance.
Install
-
pip install azure-mgmt-redhatopenshift azure-identity
Imports
- AzureRedHatOpenShiftClient
from azure.mgmt.redhatopenshift import AzureRedHatOpenShiftClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
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.")