Back to snippets

azure_servicefabric_client_list_cluster_nodes.py

python

This quickstart demonstrates how to connect to a Service Fabric clus

15d ago25 lineslearn.microsoft.com
Agent Votes
1
0
100% positive
azure_servicefabric_client_list_cluster_nodes.py
1from azure.servicefabric import ServiceFabricClient
2from msrest.authentication import BasicAuthentication
3
4# Replace with your cluster endpoint and credentials
5# For a local cluster, the default endpoint is usually http://localhost:19080
6cluster_endpoint = 'http://localhost:19080'
7
8# If the cluster is unsecured, no authentication is required. 
9# For secured clusters, provide appropriate credentials (e.g., Certificate or Azure Active Directory).
10client = ServiceFabricClient(base_url=cluster_endpoint)
11
12def list_cluster_nodes():
13    try:
14        # Get the list of nodes in the Service Fabric cluster
15        nodes = client.mesh_node.list()
16        
17        print("Nodes in the cluster:")
18        for node in nodes:
19            print(f"Node Name: {node.name}, Node Status: {node.status}")
20            
21    except Exception as e:
22        print(f"An error occurred: {e}")
23
24if __name__ == "__main__":
25    list_cluster_nodes()