Azure Service Fabric Management
The `azure-mgmt-servicefabric` library is the Microsoft Azure Service Fabric Management Client Library for Python. It allows developers to programmatically manage Azure Service Fabric resources, such as clusters, applications, and services. The current stable version is 2.1.0, released on December 18, 2023. As part of the broader Azure SDK for Python, it follows a frequent release cadence, with updates often aligning with new features and fixes across Azure services.
Warnings
- breaking Major breaking changes occurred around version 1.0.0b1 (before 2.0.0) with the transition to the 'Track 2' Azure SDK guidelines. Authentication methods using `azure.common.credentials` or `msrestazure.azure_active_directory` are no longer supported. The `credentials` parameter for client constructors was renamed to `credential`.
- breaking Direct imports from specific submodules like `azure.mgmt.servicefabric.service_fabric_management_client` for client classes, and `azure.mgmt.servicefabric.models.my_class` for models, were changed. Imports should now typically be from the top-level package or `azure.mgmt.servicefabric.models` for models.
- deprecated Support for Python 2.7 in Azure SDK Python packages ended on January 1, 2022. Using `azure-mgmt-servicefabric` with Python 2.7 is unsupported and may lead to unpatched security vulnerabilities or functional issues.
- gotcha Azure Service Fabric has two deployment models: 'classic' clusters and 'managed' clusters. This library (`azure-mgmt-servicefabric`) is for managing 'classic' Service Fabric clusters. For Service Fabric *managed* clusters, use the `azure-mgmt-servicefabricmanagedclusters` library, which provides a simplified cluster management experience.
- gotcha For production Service Fabric clusters, it is critical to configure Silver or Gold durability tiers. Azure Service Fabric blocks deployments that do not meet Silver or Gold durability requirements to prevent data loss during underlying VM infrastructure operations, especially for production workloads.
Install
-
pip install azure-mgmt-servicefabric azure-identity
Imports
- ServiceFabricManagementClient
from azure.mgmt.servicefabric import ServiceFabricManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.servicefabric import ServiceFabricManagementClient
# Ensure these environment variables are set:
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET (for DefaultAzureCredential)
# AZURE_SUBSCRIPTION_ID
# AZURE_RESOURCE_GROUP_NAME (for listing clusters)
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "<your-subscription-id>")
resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP_NAME", "<your-resource-group>")
try:
# Authenticate using DefaultAzureCredential
# This credential will attempt to authenticate in various ways, including
# environment variables, managed identity, and Azure CLI login.
credential = DefaultAzureCredential()
# Create a Service Fabric Management client
client = ServiceFabricManagementClient(credential=credential, subscription_id=subscription_id)
# Example: List all Service Fabric clusters in a specified resource group
print(f"Listing Service Fabric clusters in resource group: {resource_group_name}...")
clusters = client.clusters.list_by_resource_group(resource_group_name)
for cluster in clusters:
print(f" - Cluster Name: {cluster.name}, Location: {cluster.location}, Resource ID: {cluster.id}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your Azure environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP_NAME) are correctly set and your service principal has the necessary permissions.")