Author Topic: Listing of groups and clusters  (Read 6523 times)

methodhai

  • Sr. Member
  • ****
  • Posts: 28
Listing of groups and clusters
« on: March 06, 2008, 04:58:03 AM »
Is it possible to retrieve the list of groups and clusters from the within the Python API?

Thanks,
Hai

Scot Brew

  • Hero Member
  • *****
  • Posts: 272
    • PipelineFX
Re: Listing of groups and clusters
« Reply #1 on: March 06, 2008, 08:17:42 PM »
Currently the way to do this is to gather the host information through qb.hostinfo() and then extract out the groups and clusters from there.  Here is some sample python to extract out the groups and cluster information using just the qb python module.

Clusters:
        clusters = [i['cluster'].strip() for i in qb.hostinfo()]
        clusters = [i for i in clusters if len(i) > 0]  # remove empty items
        clusters = list(set(clusters))                  # make sure unique

Groups:
        groups = []
        for i in qb.hostinfo():
            groups.extend(i['groups'].strip().split(','))
        groups = [i.strip() for i in groups if len(i) > 0]  # remove empty&whitespace
        groups = list(set(groups))                  # make sure unique

methodhai

  • Sr. Member
  • ****
  • Posts: 28
Re: Listing of groups and clusters
« Reply #2 on: March 06, 2008, 08:23:53 PM »
Excellent. Thanks Scot.

Scot Brew

  • Hero Member
  • *****
  • Posts: 272
    • PipelineFX
Re: Listing of groups and clusters
« Reply #3 on: March 11, 2008, 04:47:09 AM »
You're welcome Hai.