Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

The first step is to get create the Ambari client

Code Block
languagepython
titleCreate Ambari client
firstline1
linenumberstrue
from ambari_client.ambari_api import  AmbariClient
client = AmbariClient("localhost", 8080, "admin", "admin", version=1)
print client.version
print client.host_url
print"\n"

...

  1. Code Block
    languagepython
    titleShow all clusters in Amabri
    firstline1
    linenumberstrue
    all_clusters = client.get_all_clusters()
    print all_clusters.to_json_dict()
    print all_clusters
  2. Code Block
    languagepython
    titleShow all hosts in Amabri
    firstline1
    linenumberstrue
    all_hosts = client.get_all_hosts()
    print all_hosts
    print all_hosts.to_json_dict()
    print"\n"

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

We can also get the information of a specific cluster

  1. Code Block
    languagepython
    titleShow a specific cluster in Amabri
    firstline1
    linenumberstrue
    cluster = 
    going into a specific cluster
    ######################################
    cluster =
    client.get_cluster('test6')

    
    print cluster

    
    print cluster.to_json_dict()

    
    print"\n"
  2. Code Block
    languagepython
    titleShow all hosts in the cluster
    firstline1
    linenumberstrue
    clusters_hosts = cluster.get_all_hosts()

...

  1. 
    print clusters_hosts.to_json_dict()

...

  1. 
    print clusters_hosts

...

  1. 
    print"\n"
  2. Code Block
    languagepython
    titleShow a specific host in the cluster
    firstline1
    linenumberstrue
    r01wn01_host = cluster.get_host('r01wn01')

...

  1. 
    print r01wn01_host

...

  1. 
    print r01wn01_host.clusterRef.cluster_name

...

  1. 
    print r01wn01_host.to_json_dict()

...

  1. 
    print"\n"
  2. Code Block
    languagepython
    titleShow all components of a host
    firstline1
    linenumberstrue
    r01wn01_host_comp = r01wn01_host.get_host_components()

...

  1. 
    print r01wn01_host_comp

...

  1. 
    print r01wn01_host_comp.to_json_dict()

...

  1. 
    print"\n"
  2. Code Block
    languagepython
    titleShow a specific service of a cluster
    firstline1
    linenumberstrue
    nn = r01wn01_host.get_host_component("NAMENODE")

...

  1. 
    print nn

...

  1. 
    print nn.to_json_dict()

...

  1. 
    print nn.clusterRef.cluster_name

...

  1. 
    print"\n"
  2. Code Block
    languagepython
    titleShow all services in the cluster
    firstline1
    linenumberstrue
    serviceList = cluster.get_all_services()

...

  1. 
    print serviceList

...

  1. 
    print serviceList.to_json_dict()

...

  1. 
    print"\n"
  2. Code Block
    languagepython
    titleShow a specific service of a cluster
    firstline1
    linenumberstrue
    ganglia = cluster.get_service("GANGLIA")

...

  1. 
    print  ganglia

...

  1. 
    print ganglia.to_json_dict()

...

  1. 
    print"\n"
  2. Code Block
    languagepython
    titleShow all components of a service
    firstline1
    linenumberstrue
    ganglia_comps = ganglia.get_service_components()

...

  1. 
    print ganglia_comps

...

  1. 
    print ganglia_comps.to_json_dict()

...

  1. 
    print"\n"
  2. Code Block
    languagepython
    titleShow a specific component of a service
    firstline1
    linenumberstrue
    ganglia_comp1 = ganglia.get_service_component('GANGLIA_MONITOR')

...

  1. 
    print ganglia_comp1

...

  1. 
    print ganglia_comp1.to_json_dict()

...

  1. 
    print ganglia_comp1.clusterRef.cluster_name

...

  1. 
    print"\n"
  2. Code Block
    languagepython
    titleStop a service
    firstline1
    linenumberstrue
    ganglia.stop()
  3. Code Block
    languagepython
    titleSatrt a service
    firstline1
    linenumberstrue
    ganglia.start()