How to list all the Analytics Engine instances that I have access to?

46 views Asked by At

I'm would like to print all the Analytics Engine instances that I have available to me in my account.

I can print all the organisations and spaces that I have available using:

! pip install --quiet --upgrade git+https://github.com/snowch/ibm-analytics-engine-python@master

Then

from ibm_analytics_engine import CloudFoundryAPI, CloudFoundryAPI
from ibm_analytics_engine import IAE, IAEServicePlanGuid, IAEClusterSpecificationExamples

cf = CloudFoundryAPI(api_key_filename='api_key.json')
iae = IAE(cf_client=cf)
cf.print_orgs_and_spaces()

Outputs:

-------------------------------------------------------------------------
Org: [email protected]                       12345-12345-12345678910
> Spc: dev                           12345-12345-12345678912
> Spc: test                          12345-12345-12345678913

-------------------------------------------------------------------------
Org: [email protected]                   aaaaa-bbbbb-ccccccccccc
> Spc: dev                           aaaaa-bbbbb-ccccccccccd
...

How can I also list the clusters in these spaces?

1

There are 1 answers

0
Chris Snow On BEST ANSWER

You can do something like this:

! pip install --quiet --upgrade git+https://github.com/snowch/ibm-analytics-engine-python@master

Then

from ibm_analytics_engine import CloudFoundryAPI, CloudFoundryAPI
from ibm_analytics_engine import IAE, IAEServicePlanGuid, IAEClusterSpecificationExamples

cf = CloudFoundryAPI(api_key_filename='api_key.json')
iae = IAE(cf_client=cf)

import pprint
pp = pprint.PrettyPrinter(indent=4)

for org in cf.orgs_and_spaces():
    for space in org['spaces']:
        print('ORG {} | SPACE {}'.format(org['name'], space['name']))
        print()

        clusters = iae.clusters(space_guid=space['guid'])
        if len(clusters) > 0:
            for cluster in clusters:
                pp.pprint(cluster)
                print()

The output:

ORG [email protected] | SPACE dev

{   'guid': 'abcd-abcd-abcdefghi',
    'name': 'Analytics Engine',
    'state': 'succeeded'}

ORG [email protected] | SPACE test

....