09-03-2014 10:43 PM
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.
09-04-2014 04:19 AM
09-18-2014 02:12 PM
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)