2017-12-16 17 views
0

python-ambariclientライブラリがhost_componentsを取得するためのAPIを持っていますAmbariを使用して名前ノードのホスト名を取得する方法は?

ambari.services(service_name).components(component_name).host_components 

は、どのように私はIBM解析Engineクラスタのためのname_nodeを抽出することができますか?

私が呼び出しを行う必要があると思う:

GET https://xxxx.bi.services.us-south.bluemix.net:9443/api/v1/clusters/AnalyticsEngine/services/HDFS/components/NAMENODE?fields=host_components 

次の情報を取得するとき:

{ 
    "href" : "https://xxxx.bi.services.us-south.bluemix.net:9443/api/v1/clusters/AnalyticsEngine/services/HDFS/components/NAMENODE?fields=host_components", 
    "ServiceComponentInfo" : { 
    "cluster_name" : "AnalyticsEngine", 
    "component_name" : "NAMENODE", 
    "service_name" : "HDFS" 
    }, 
    "host_components" : [ 
    { 
     "href" : "https://xxxx.bi.services.us-south.bluemix.net:9443/api/v1/clusters/AnalyticsEngine/hosts/xxxx.bi.services.us-south.bluemix.net/host_components/NAMENODE", 
     "HostRoles" : { 
     "cluster_name" : "AnalyticsEngine", 
     "component_name" : "NAMENODE", 
     "host_name" : "xxxx.bi.services.us-south.bluemix.net" 
     } 
    } 
    ] 
} 

答えて

0

私はこの情報を抽出するためのライブラリを作成しました。実行し

pip install --quiet --upgrade git+https://github.com/snowch/[email protected] 

:にインストール

from ibm_analytics_engine import AmbariOperations 
ambari_ops = AmbariOperations(vcap_filename='./vcap.json') 
ambari_ops.get_namenode_hostname() 
0

まず、python-ambariclientライブラリインストール:

! pip install --quiet python-ambariclient 

次へ]を、あなたは次のコマンドを使用して、名前ノードのホスト名を取得できます。

from future.standard_library import install_aliases 
install_aliases() 
from urllib.parse import urlparse 

import json 
vcap = json.load(open('./vcap.json')) 

USER   = vcap['cluster']['user'] 
PASSWORD  = vcap['cluster']['password'] 
AMBARI_URL = vcap['cluster']['service_endpoints']['ambari_console'] 
CLUSTER_ID = vcap['cluster']['cluster_id'] 

url = urlparse(AMBARI_URL) 

HOST = url.hostname 
PORT = url.port 
PROTOCOL = url.scheme 

from ambariclient.client import Ambari 
ambari = Ambari(HOST, port=PORT, username=USER, password=PASSWORD, protocol=PROTOCOL) 

CLUSTER_NAME = ambari.clusters.next().cluster_name # gets first cluster - there will only be one 

namenode_hc = ambari.clusters(CLUSTER_NAME).services('HDFS').components('NAMENODE').host_components 

namenode_host_name = [hc.host_name for hc in namenode_hc if hc.host_name][0] 

print(namenode_host_name) 
関連する問題