Ask Your Question
0

How can I determine instances in a sahara cluster

asked 2015-05-26 13:58:31 -0500

I am working on a Hadoop cluster provisioning project using the python APIs and I'm able to create a new cluster based on a template, list running clusters, etc.

How can I use the API to determine the individual nodes in the cluster? Is there some map I can get that will list the cluster nodes by instance ID or something or do I need to build that list by somehow querying nova and sahara and joining the results together?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-05-27 14:23:15 -0500

This example code will work.

from keystoneclient.auth.identity import v2 as ks_ident_v2
from keystoneclient import session as ksc_session
from keystoneclient.v3 import client as keystone_v3
from saharaclient.api import client as sahara_v2

auth = ks_ident_v2.Password(auth_url=os.environ['OS_AUTH_URL'],
                            username=os.environ['OS_USERNAME'],
                            password=os.environ['OS_PASSWORD'],
                            tenant_name=os.environ['OS_TENANT_NAME'])

session = ksc_session.Session(auth=auth)

ks = keystone_v3.Client(session=session)
sahara = sahara_v2.Client(session=session)

cluster = sahara.clusters.list()[0]
cluster_manager = cluster.manager.list()[0]
node_groups = cluster_manager.node_groups

def make_instance_list():
   instance_list = []
    for ng in node_groups:
        instance_list += [ng]['instances']
    return instance_list

def list_instances():
    for i in make_instance_list():
        print i['instance_name'], '||', i['id']

I believe that this is the correct approach. Walking through the data structures to find the instances that belong to the node groups. Obviously there is more work to be done WRT making sure this is generic and can loop through more than just one, but this should serve as an ok example.

I would appreciate guidance or at least validation of my approach by someone who understands this API better than I do.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2015-05-26 13:58:31 -0500

Seen: 38 times

Last updated: May 27 '15