summaryrefslogtreecommitdiffstats
path: root/bin/opssh.py
blob: 6ee390c4c33c317706cf6670b2cbc6e8838aeaae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# vim: expandtab:tabstop=4:shiftwidth=4

import argparse
import os
import ansibleutil
import sys

class Program(object):
    def __init__(self):
        self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
        self.parse_cli_args()
        self.ansible = ansibleutil.AnsibleUtil()

        inv = self.ansible.get_inventory()
        #print inv.keys()
        #sys.exit()

        if self.args.list_environments:
            self.list_environments()
            sys.exit()

        if self.args.list_groups:
            self.list_security_groups()
            sys.exit()

    def parse_cli_args(self):
        parser = argparse.ArgumentParser(
            description='OpenShift Online Operations Parallel SSH'
        )

        parser.add_argument("-v", '--verbosity', action="count",
                            help="increase output verbosity")

        group = parser.add_mutually_exclusive_group()

        group.add_argument('--list-environments', action="store_true",
                            help='List all environments')
        group.add_argument('--list-groups', action="store_true",
                            help='List all security groups')
        group.add_argument('-e', '--environment',
                            help='Set the environment')

        self.args = parser.parse_args()

    def list_environments(self):
        envs = self.ansible.get_environments()
        print
        print "Environments"
        print "------------"
        for env in envs:
            print env
        print

    def list_security_groups(self):
        envs = self.ansible.get_security_groups()
        print
        print "Groups"
        print "------"
        for env in envs:
            print env
        print


if __name__ == '__main__':
    p = Program()