~openstack-charm-testers/openstack-charm-testing/openstack-monitoring

« back to all changes in this revision

Viewing changes to bin/application-hostnames

  • Committer: Edward Hope-Morley
  • Date: 2016-12-05 15:01:45 UTC
  • mfrom: (220.1.37 openstack-charm-testing)
  • Revision ID: edward.hope-morley@canonical.com-20161205150145-5xs44qcs5ifqsnl5
rebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import yaml
 
4
import subprocess
 
5
import optparse
 
6
import sys
 
7
 
 
8
usage = """Print hostnames for units participating in an application
 
9
 
 
10
For example:
 
11
 
 
12
  %prog nova-compute
 
13
 
 
14
will print the hostnames of the units supporting the nova-compute application
 
15
 
 
16
"""
 
17
 
 
18
if __name__ == '__main__':
 
19
    parser = optparse.OptionParser(usage)
 
20
    (opts, args) = parser.parse_args()
 
21
 
 
22
    if len(args) != 1:
 
23
        parser.print_help()
 
24
        sys.exit(1)
 
25
 
 
26
    app_name = args[0]
 
27
 
 
28
    app_status = yaml.load(subprocess.check_output(['juju', 'status',
 
29
                                                    '--format=yaml',
 
30
                                                     app_name]))
 
31
 
 
32
    hostnames = []
 
33
    for machine in app_status['machines']:
 
34
        hostname = subprocess.check_output(['juju', 'ssh', machine,
 
35
                                            'hostname']).strip()
 
36
        hostnames.append(hostname)
 
37
 
 
38
 
 
39
    print(' '.join(hostnames))