Azure Service Fabric Client Library for Python

8.2.0.0 · maintenance · verified Sat Apr 11

The `azure-servicefabric` library provides a client for programmatically interacting directly with Microsoft Azure Service Fabric clusters using Python. It allows for management of applications, services, nodes, and other cluster resources. This library is part of the older Azure SDK for Python (Track 1) and was last updated in April 2021. It is currently in maintenance mode, receiving critical bug fixes but not active feature development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `ServiceFabricClient` and connect to a secure Service Fabric cluster using client certificates, then list the nodes. Ensure you have the cluster endpoint, client certificate (.pem) and private key (.key) files accessible and their paths set in environment variables.

import os
from azure.servicefabric import ServiceFabricClient
from msrest.service_fabric import ServiceFabricCredential

# Connect to a secure Service Fabric cluster using client certificates
# Replace with your cluster endpoint and certificate paths
cluster_endpoint = os.environ.get('SF_CLUSTER_ENDPOINT', 'https://your_cluster_fqdn:19080')
cert_file = os.environ.get('SF_CLIENT_CERT_FILE', 'path/to/your/client.pem')
key_file = os.environ.get('SF_CLIENT_KEY_FILE', 'path/to/your/client.key') # or .pfx if combined

if not all([cluster_endpoint, cert_file, key_file]):
    print("Please set SF_CLUSTER_ENDPOINT, SF_CLIENT_CERT_FILE, and SF_CLIENT_KEY_FILE environment variables.")
    print("Example: export SF_CLUSTER_ENDPOINT='https://mycluster.westus.cloudapp.azure.com:19080'")
    print("Example: export SF_CLIENT_CERT_FILE='/etc/sf/client.pem'")
    print("Example: export SF_CLIENT_KEY_FILE='/etc/sf/client.key'")
else:
    try:
        # Service Fabric client expects a tuple of (cert_file, key_file) for ServiceFabricCredential
        credentials = ServiceFabricCredential((cert_file, key_file))
        client = ServiceFabricClient(base_url=cluster_endpoint, credentials=credentials)

        print(f"Connecting to Service Fabric cluster at: {cluster_endpoint}")

        # Example: List all nodes in the cluster
        nodes = client.nodes.get_node_list()
        print(f"Found {len(nodes)} nodes in the cluster:")
        for node in nodes:
            print(f"- Node Name: {node.name}, Status: {node.health_state}, Type: {node.type}")

    except Exception as e:
        print(f"An error occurred: {e}")
        print("Ensure the certificate paths are correct and the cluster endpoint is reachable.")

view raw JSON →