-
Notifications
You must be signed in to change notification settings - Fork 283
List of all hosts in Cluster 1 and list hostname for a Service Role
gdgt edited this page Sep 30, 2014
·
3 revisions
# CM API endpoints
http://cloudera.github.io/cm_api/apidocs/v6/path__clusters_-clusterName-_hosts.html
http://cloudera.github.io/cm_api/apidocs/v6/path__clusters_-clusterName-_hosts_-hostId-.html
This does not require to install CM API (Python or Java). curl stdout json results is piped into python json module.
#!/usr/bin/env bash
HOST_ID=$(curl -su admin:admin -X GET http://cm.cloudera.com:7180/api/v6/clusters/Cluster%201/hosts | python -c 'import json, sys; obj=json.load(sys.stdin);print " ".join([x["hostId"] for x in obj["items"]])')
for host in $HOST_ID; do
echo "HostID: $host"
curl -su admin:admin -X GET http://cm.cloudera.com:7180/api/v6/hosts/$host | python -c 'import json, sys; obj=json.load(sys.stdin);print obj["hostname"]'
done
Since hostRef associated with the Service Role is a unique UUID, retrieve the original hostname from it's hostId
#!/usr/bin/env bash
ROLE_HOST_ID=$(curl -su admin:admin -X GET http://cm.cloudera.com:7180/api/v6/clusters/Cluster%201/services/__SERVICE-NAME__/roles/__SERVICE__ROLE-NAME__UUID__ | python -c 'import json, sys; obj=json.load(sys.stdin);print obj["hostRef"]["hostId"]')
curl -su admin:admin -X GET http://cm.cloudera.com:7180/api/v6/hosts/$ROLE_HOST_ID | python -c 'import json, sys; obj=json.load(sys.stdin);print obj["hostname"]'