Hello.
I want to add information to onecluster command output.
Information like this:
CLUSTER 113 INFORMATION
ID : 113
NAME : ceph
CLUSTER RESOURCES:
TOTAL CPUs: 100
OCCUPIED CPUs: 34
AVAILABLE CPUs: 64
TOTAL RAM: 500G
OCCUPIED RAM: 125G
AVAILABLE RAM: 375G
I’ve checked that object which is providing into format_resource(cluster, options={}) doesn’t have any methots which can get objects of contained hosts.
Can you help me if there has any tools to get cluster resources inside onecluster_helper.rb, if no, maybe there are another ways to get resources from cluster object ?
Not sure what do you exactly mean, since Clusters have no resources themselves. But if you want to list all resources belonging to Hosts under certain Cluster, then snippet like this would do it
id = whatever
c = Cluster.new_with_id(id, Client.new)
c.info!
hosts = c.to_hash['CLUSTER']['HOSTS']['ID']
hosts.each do | h |
h = Host.new_with_id(h, Client.new)
h.info!
# get resources via xpath
end
Another approach could be to iterate through HostPool and filter them by CLUSTER_ID
hp = HostPool.new(Client.new)
hp.info_all!
hp.each do | h |
h['//CLUSTER_ID'] == requested_cluster_id
# get by xpath
end