Azure Service Fabric Client Library for Python
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
- gotcha This library is part of the older Azure SDK Track 1. It does not use the newer `azure-identity` credential types. Authentication typically requires `msrest.service_fabric.ServiceFabricCredential` which supports certificate-based authentication. This can be complex to configure correctly.
- deprecated The `azure-servicefabric` library is in maintenance mode and was last updated in April 2021. For managing Service Fabric clusters via Azure Resource Manager (ARM), consider using `azure-mgmt-servicefabric` which is part of the newer Azure SDK Track 2 and actively maintained.
- gotcha Unlike newer Azure SDK libraries that often use `Async` variants, `azure-servicefabric` is synchronous. All client operations will block until the call completes.
Install
-
pip install azure-servicefabric
Imports
- ServiceFabricClient
from azure.servicefabric import ServiceFabricClient
- ServiceFabricCredential
from msrest.service_fabric import ServiceFabricCredential
Quickstart
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.")