Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

WARNING: The client library is still in the works and not production ready. 

Ambari Amabri python client can be used make use of Ambari APIs.

The first step is to create the Ambari client

Code Block
languagepython
titleCreate Ambari client
firstline1
linenumberstrue
from ambari_client.ambari_api import  AmbariClient
headers_dict={'X-Requested-By':'mycompany'} #Ambari needs X-Requested-By header
client = AmbariClient("localhost", 8080, "admin", "admin", version=1,http_header=headers_dict)
print client.version
print client.host_url
print"\n"

######################################

Some useful methods

  1. Code Block
    languagepython
    titleShow all clusters in Ambari
    firstline1
    linenumberstrue
    High level
    ######################################
    all_clusters = client.get_all_clusters()

    
    print all_clusters.to_json_dict()

    
    print all_clusters

all_hosts = client.get_all_hosts()
print all_hosts
print all_hosts.to_json_dict()
print"\n"

######################################

  1. going into a specific cluster
    ######################################
    cluster = client.get_cluster('test6')
    print cluster
    print cluster.to_json_dict()
    print"\n"
  1. Code Block
    languagepython
    titleShow all hosts in Ambari
    firstline1
    linenumberstrue
    all_hosts = client

...

  1. .get_all_hosts()

...

  1. 
    print

...

  1.  all_hosts

...

  1. 
    print all_hosts.to_json_dict()

...

r01wn01_host_comp = r01wn01_host.get_host_components()
print r01wn01_host_comp
print r01wn01_host_comp.to_json_dict()
print"\n"

nn = r01wn01_host.get_host_component("NAMENODE")
print nn
print nn.to_json_dict()
print nn.clusterRef.cluster_name
print"\n"

serviceList = cluster.get_all_services()
print serviceList
print serviceList.to_json_dict()
print"\n"

ganglia = cluster.get_service("GANGLIA")
print ganglia
print ganglia.to_json_dict()
print"\n"

ganglia_comps = ganglia.get_service_components()
print ganglia_comps
print ganglia_comps.to_json_dict()
print"\n"

...

  1. 
    print"\n"