# Create an instance of the API class api_host = 'http://192.168.1.240' port = '7180' api_version = 'v30' # Construct base URL for API # http://cmhost:7180/api/v30 api_url = api_host + ':' + port + '/api/' + api_version api_client = cm_client.ApiClient(api_url) cluster_api_instance = cm_client.ClustersResourceApi(api_client)
# Lists all known clusters. api_response = cluster_api_instance.read_clusters(view='SUMMARY') for cluster in api_response.items: print (cluster.name , "-", cluster.full_version) if cluster.full_version.startswith("6."): services_api_instance = cm_client.ServicesResourceApi(api_client) services = services_api_instance.read_services(cluster.name, view='FULL') for service in services.items: print (service.name, "-", service.type) if service.type == 'HDFS': hive = service print ("lihm") print (hive.name, hive.service_state, hive.health_summary) for health_check in hive.health_checks: print (health_check.name, "---", health_check.summary) role_api_instance = cm_client.RolesResourceApi(api_client) roles = role_api_instance.read_roles(cluster.name, hive.name) for role in roles.items: if role.type == 'NAMENODE': nn = role print (nn.name, nn.role_state, nn.health_summary, nn.host_ref.host_id) for hc in nn.health_checks: print (hc.name, "---", hc.summary) # cmd = services_api_instance.restart_command(cluster.name, hive.name) # print ("cmd.active")