Azure Service Fabric Management

2.1.0 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and instantiate the `ServiceFabricManagementClient`. It then shows how to list Service Fabric clusters within a specified resource group. Ensure relevant Azure environment variables for authentication and subscription ID are set.

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.")

view raw JSON →