~charmers/charms/oneiric/python-moinmoin/trunk

« back to all changes in this revision

Viewing changes to tests/get-unit-info

  • Committer: Juan L. Negron
  • Date: 2012-03-05 20:24:50 UTC
  • mfrom: (2.1.11 python-moinmoin)
  • Revision ID: juan.negron@canonical.com-20120305202450-smihpdfaueex9zb6
Merged update from patrick-hetu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# machines:
 
3
#   0: {dns-name: ec2-50-17-84-127.compute-1.amazonaws.com, instance-id: i-8c5c3fec}
 
4
#   1: {dns-name: ec2-184-73-102-113.compute-1.amazonaws.com, instance-id: i-14a2c174}
 
5
#   2: {dns-name: ec2-75-101-184-93.compute-1.amazonaws.com, instance-id: i-e0a2c180}
 
6
# services:
 
7
#   mysql:
 
8
#     charm: local:mysql-11
 
9
#     relations: {db: wordpress}
 
10
#     units:
 
11
#       mysql/0:
 
12
#         machine: 2
 
13
#         relations:
 
14
#           db: {state: up}
 
15
#         state: started
 
16
#   wordpress:
 
17
#     charm: local:wordpress-31
 
18
#     exposed: true
 
19
#     relations: {db: mysql}
 
20
#     units:
 
21
#       wordpress/0:
 
22
#         machine: 1
 
23
#         open-ports: []
 
24
#         relations: {}
 
25
#         state: null
 
26
 
 
27
import yaml
 
28
import sys
 
29
from subprocess import Popen, PIPE
 
30
 
 
31
 
 
32
def main():
 
33
    d = yaml.safe_load(Popen(['juju','status'],stdout=PIPE).stdout)
 
34
    srv = d.get("services", {}).get(sys.argv[1])
 
35
    if srv is None:
 
36
        return
 
37
    units = srv.get("units", {})
 
38
    if units is None:
 
39
        return
 
40
    item = units.items()[0][1].get(sys.argv[2])
 
41
    if item is None:
 
42
        return
 
43
    print item
 
44
 
 
45
if __name__ == "__main__":
 
46
    main()