Reply
Contributor
Posts: 40
Registered: ‎07-23-2014

How to get hostID after inspecting hosts? Do you have examples for creating a cluster using CM API

To create a cluster, I am trying to use cm.inspect_host() method to get all hosts. I found all host generates random hostID in this way, how can i get the hostID for the hosts?


api.get_all_hosts('full') seems not working in my case.

 

Do you have examples for creating a cluster using CM API? My phython code and all examples from cloudera website seems not working.

Cloudera Employee
Posts: 578
Registered: ‎01-20-2014

Re: How to get hostID after inspecting hosts? Do you have examples for creating a cluster using CM A

Beginning with Cloudera Manager 5, the hostid stored in CM is a randomly
generated string. This string is generated by the Cloudera Manager Agent on
the host. This is to help identify the host even if the IP address or host
name change in the future

Regards,
Gautam Gopalakrishnan
Explorer
Posts: 15
Registered: ‎09-11-2014

Re: How to get hostID after inspecting hosts? Do you have examples for creating a cluster using CM A

Do you have cloudera-scm-agent running on all your nodes? And do you have their /etc/cloudera-scm-agent/config.ini's server_host property set to your CM Server? If both those are done, the python code should be:

 

from cm_api.api_client import ApiResource
VERSION = "CDH5"
CM_USER = "admin"
CM_PASS = "admin"
CM_SERV = "my.cm.server.my.domain.com"
api = ApiResource(CM_SERV, username=CM_USER, password=CM_PASS)
cluster = api.create_cluster("cluster1",VERSION)
hosts = api.get_all_hosts()

 The hostId's will be random strings, but the hostnames should be perhaps what you're expecting? If you really want the hostIds to not be random, you can do:

 

HOSTNAMES = [
  "centos56-17.ent.cloudera.com",
  "centos56-18.ent.cloudera.com",
  "centos56-19.ent.cloudera.com",
  "centos56-20.ent.cloudera.com"
]
hosts = [ ]                             # API host handles
 
for name in HOSTNAMES:
  host = api.create_host(
      name,                             # Host id
      name,                             # Host name (FQDN)
      socket.gethostbyname(name),       # IP address
      "/default_rack")                  # Rack
  hosts.append(host)