def get_host_api(self): try: host_api_instance = cm_client.HostsResourceApi(self.api_client) host_api_response = host_api_instance.read_hosts(view='full') return host_api_response except ApiException as e: self.log.error( 'ERROR with ClustersResourceApi > read_hosts at {}'.format( self.url)) raise e
def init_conn(self, host, port, version): """初始化连接,构建cm的连接实例 """ url = host + ':' + port + '/api/' + version client = cm_client.ApiClient(url) # 生成资源API self._cluster_api_instance = cm_client.ClustersResourceApi(client) # 为了获取namemode的资源API self._services_api_instance = cm_client.ServicesResourceApi(client) self._roles_api_instance = cm_client.RolesResourceApi(client) self._host_api_instance = cm_client.HostsResourceApi(client)
def get_host_resource(hostname): api_instance = cm_client.HostsResourceApi(api_client) try: # Returns the hostIds for all hosts in the system. # api_response = api_instance.read_hosts(view=view) api_host_response = [ x for x in api_instance.read_hosts(view='summary').items if hostname == x.hostname ] except ApiException as e: print("Exception when calling HostsResourceApi->read_hosts: %s\n" % e) return api_host_response[0]
def __init__(self, cm_host, env, send_alert): cm_client.configuration.username = '******' cm_client.configuration.password = '******' self.env = env api_host = 'http://' + cm_host port = '7180' api_version = 'v19' api_url = api_host + ':' + port + '/api/' + api_version self.send_alert_email = send_alert print(api_url) self.api_client = cm_client.ApiClient(api_url) self.cluster_api_instance = cm_client.ClustersResourceApi( self.api_client) self.services_api_instance = cm_client.ServicesResourceApi( self.api_client) self.roles_api_instance = cm_client.RolesResourceApi(self.api_client) self.host_api_instance = cm_client.HostsResourceApi(self.api_client) self.host_details = self.get_hostname_by_id() self.bad_alert_count = 0 self.msg_body = ""
def main(): cm_client.configuration.username = ADMIN_USER cm_client.configuration.password = ADMIN_PASS # Create an instance of the API class api_host = 'http://'+ CM_HOST port = '7180' api_version = 'v18' api_url = api_host + ':' + port + '/api/' + api_version api_client = cm_client.ApiClient(api_url) host_api_instance = cm_client.HostsResourceApi(api_client) service_api_instance = cm_client.ServicesResourceApi(api_client) sentry_host_id=fetch_hostid(HostsApi=host_api_instance, hostname=SENTRY_HA_HOST) cluster_name = CLUSTER_NAME service_name = "Sentry" body = cm_client.ApiEnableSentryHaArgs(new_sentry_host_id=sentry_host_id, new_sentry_role_name= "Sentry-Server-2", zk_service_name="ZOOKEEPER") setup_logger.info("Enabling Sentry HA.....") time.sleep(60) res=service_api_instance.enable_sentry_ha_command(cluster_name, service_name, body=body) time.sleep(60) setup_logger.info("Sentry HA Enabled...")
def get_api_handle(cmserver, port='7180', user='******', passwd='admin', api_version='v30'): """ Get a handle to the CM API client :param cmserver: Hostname of the Cloudera Manager Server (CMS) :param port: Port of the server :param user: SCM username :param passwd: SCM password :param tls: Whether to use TLS :return: Resource object referring to the root """ cm_client.configuration.username = user cm_client.configuration.password = passwd api_url = 'http://' + cmserver + ':' + port + '/api/' + api_version api_client = cm_client.ApiClient(api_url) api = None try: api = cm_client.HostsResourceApi(api_client) except ApiException: pass return api
def hosts_api(self): if self._hosts_api is None: self._hosts_api = cm_client.HostsResourceApi(self.api_client) return self._hosts_api