-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmlib.py
executable file
·67 lines (60 loc) · 2.23 KB
/
cmlib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# to use this script,
# ref: https://cloudera.github.io/cm_api/docs/python-client-swagger/
# ref: https://archive.cloudera.com/cm7/7.0.3/generic/jar/cm_api/swagger-html-sdk-docs/python/README.html
# $ source ~/PYTHON3.7/bin/activate
# python reconf_cluster.py
import cm_client
from cm_client.rest import ApiException
from pprint import pprint
import sys
import time
import os
def get_ozone_service_id():
cluster_api_instance = cm_client.ClustersResourceApi(api_client)
api_response = cluster_api_instance.read_clusters(view='SUMMARY')
for cluster in api_response.items:
cluster_name = cluster.name
api_instance = cm_client.ServicesResourceApi(api_client)
services = api_instance.read_services(cluster.name, view='FULL')
for service in services.items:
if service.type == 'OZONE':
ozone = service
ozone_service_name = ozone.name
api_response = api_instance.read_service_config(cluster_name, ozone_service_name, view="summary")
for config_item in api_response.items:
if config_item.name == "ozone.service.id":
ozone_service_id = config_item.value
print(ozone_service_id)
def get_service_list():
cluster_api_instance = cm_client.ClustersResourceApi(api_client)
api_response = cluster_api_instance.read_clusters(view='SUMMARY')
for cluster in api_response.items:
cluster_name = cluster.name
api_instance = cm_client.ServicesResourceApi(api_client)
services = api_instance.read_services(cluster.name, view='FULL')
for service in services.items:
print(service.type)
# Configure HTTP basic authorization: basic
cm_client.configuration.username = 'admin'
cm_client.configuration.password = 'admin'
cm_client.configuration.verify_ssl = False
# Create an instance of the API class
cm_http = os.environ["CM_HTTP"]
if len(sys.argv) < 3:
print("requires at least arguments: [CM host name] [function] ")
system.exit(-1)
api_host_name = sys.argv[1]
role_type = sys.argv[2]
api_host = cm_http + '://' + api_host_name
port = os.environ["CM_PORT"]
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)
match sys.argv[2]:
case 'ozone_service_id':
get_ozone_service_id()
case 'service_list':
get_service_list()