- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsuperloop.py
More file actions
Latest commit
executable file
·116 lines (104 loc) · 6.18 KB
/
Copy pathsuperloop.py
File metadata and controls
executable file
·116 lines (104 loc) · 6.18 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
"""
Main executable file for superloop. A symbolic link should be created as a global command for ease of use.
"""
importsys
importargparse
importinitialize
importos
fromauditdiffimportauditdiff
frompull_cfgsimportpull_cfgs
frompush_cfgsimportpush_cfgs
frompush_localimportpush_local
frompush_aclimportpush_acl
frompush_regeximportpush_regex
frompush_renderimportpush_render
fromexec_cmdimportexec_cmd
fromssh_connectimportssh_connect
frommodifydbimportappend
frommodifydbimportdiscover
frommodifydbimportremove
frommodifydbimportupdate
fromnode_listimportnode_list
sys.path.append('/usr/local/superloop')
defmain():
# try:
initialize.variables()
parser=argparse.ArgumentParser()
subparsers=parser.add_subparsers()
# acl_cmd = subparsers.add_parser('acl')
# acl_subparsers = acl_cmd.add_subparsers(dest='parser_acl')
# acl_render_cmd = acl_subparsers.add_parser('render')
# acl_render_cmd.set_defaults(func=render_acl)
# acl_render_cmd.add_argument('-n','--node', dest='node', help='Specify node(s) to match against. Accepts regular expressions.')
audit_cmd=subparsers.add_parser('audit')
audit_subparser=audit_cmd.add_subparsers(dest='parser_audit')
audit_diff_cmd=audit_subparser.add_parser('diff')
audit_diff_cmd.set_defaults(func=auditdiff)
audit_diff_cmd.add_argument('-n','--node', dest='node', help='Specify node(s) to match against. Accepts regular expressions.' )
audit_diff_cmd.add_argument('-f','--file', dest='file', help='Specify template file to audit against [exclude *.jinja2 extension].')
audit_diff_cmd.add_argument('-p','--policy', dest='policy', help='Specify policy file to audit against [exclude *.json extension].')
pull_cmd=subparsers.add_parser('pull')
pull_subparsers=pull_cmd.add_subparsers(dest='parser_pull')
pull_cfgs_cmd=pull_subparsers.add_parser('cfgs')
pull_cfgs_cmd.set_defaults(func=pull_cfgs)
pull_cfgs_cmd.add_argument('-n','--node', dest='node', help='Specify node(s) to match against. Accepts regular expressions.')
pull_cfgs_cmd.add_argument('-c','--confirm', dest='confirm', help='Skip confirmation [default is True].')
push_cmd=subparsers.add_parser('push')
push_subparsers=push_cmd.add_subparsers(dest='parser_push')
push_acl_cmd=push_subparsers.add_parser('acl')
push_acl_cmd.set_defaults(func=push_acl)
push_acl_cmd.add_argument('-n','--node', dest='node', help='Specify node(s) to match against. Accepts regular expressions.')
push_acl_cmd.add_argument('-c','--confirm', dest='confirm', help='Skip confirmation [default is True].')
push_regex_cmd=push_subparsers.add_parser('regex')
push_regex_cmd.set_defaults(func=push_regex)
push_regex_cmd.add_argument('regex', help='Specify regular expression to test/match against nodes.')
push_render_cmd=push_subparsers.add_parser('render')
push_render_cmd.set_defaults(func=push_render)
push_render_cmd.add_argument('-n','--node', dest='node', help='Specify node(s) to match against. Accepts regular expressions.')
push_render_cmd.add_argument('-f','--file', dest='file', help='Specify template file to audit against [exclude *.jinja2 extension].')
push_render_cmd.add_argument('-p','--policy', dest='policy', help='Specify policy file to audit against [exclude *.json extension].')
push_cfgs_cmd=push_subparsers.add_parser('cfgs')
push_cfgs_cmd.set_defaults(func=push_cfgs)
push_cfgs_cmd.add_argument('-n','--node', dest='node', help='Specify node(s) to match against. Accepts regular expressions.')
push_cfgs_cmd.add_argument('-f','--file', dest='file', help='Specify template file to audit against [exclude *.jinja2 extension].')
push_cfgs_cmd.add_argument('-c','--confirm', dest='confirm', help='Skip confirmation [default is True].')
push_local_cmd=push_subparsers.add_parser('local')
push_local_cmd.set_defaults(func=push_local)
push_local_cmd.add_argument('filename', help='Specify local filename to be pushed.')
push_local_cmd.add_argument('-n','--node', dest='node', help='Specify node(s) to match against. Accepts regular expressions.')
ssh_cmd=subparsers.add_parser('ssh')
ssh_cmd.set_defaults(func=ssh_connect)
ssh_cmd.add_argument('name', help='Specify name(s) to match against. Accepts regular expressions.')
host_cmd=subparsers.add_parser('host')
host_subparsers=host_cmd.add_subparsers(dest='parser_host')
host_add_cmd=host_subparsers.add_parser('add', help='Add node to database')
host_add_cmd.set_defaults(func=append)
host_add_cmd.add_argument('node', help='Specify IP address of host')
host_discover_cmd=host_subparsers.add_parser('discover', help='Re-discover existing node from database')
host_discover_cmd.set_defaults(func=discover)
host_discover_cmd.add_argument('node', help='Specify FQDN or IP address of host')
host_remove_cmd=host_subparsers.add_parser('remove', help='Remove node from database')
host_remove_cmd.set_defaults(func=remove)
host_remove_cmd.add_argument('node')
host_update_cmd=host_subparsers.add_parser('update', help='Update node attribute in database')
host_update_cmd.set_defaults(func=update)
host_update_cmd.add_argument('node')
host_update_cmd.add_argument('-a','--attribute', dest='attribute', help='Specify the attribute that requires updating')
host_update_cmd.add_argument('-am','--amend', dest='amend', help='The value that is being amended')
host_exec_cmd=host_subparsers.add_parser('exec')
host_exec_cmd.set_defaults(func=exec_cmd)
host_exec_cmd.add_argument('command', help='Specify command to execute on device')
host_exec_cmd.add_argument('-n','--node', dest='node', help='Specify node(s) to match against. Accepts regular expressions.')
node_cmd=subparsers.add_parser('node')
node_subparsers=node_cmd.add_subparsers(dest='parser_node')
node_list_cmd=node_subparsers.add_parser('list')
node_list_cmd.set_defaults(func=node_list)
node_list_cmd.add_argument('name', help='Specify name(s) to match again. Accepts regular expressions.')
node_list_cmd.add_argument('-e','--extended', dest='attribute', help='Specify extended option for additional attributes. {ports|protocols}')
args=parser.parse_args()
args.func(args)
# except AttributeError as error:
# print('Please check help menu for further operations; superloop --help')
if__name__=='__main__':
main()