trigger 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trigger/__init__.py +7 -0
- trigger/acl/__init__.py +32 -0
- trigger/acl/autoacl.py +70 -0
- trigger/acl/db.py +324 -0
- trigger/acl/dicts.py +357 -0
- trigger/acl/grammar.py +112 -0
- trigger/acl/ios.py +222 -0
- trigger/acl/junos.py +422 -0
- trigger/acl/models.py +118 -0
- trigger/acl/parser.py +168 -0
- trigger/acl/queue.py +296 -0
- trigger/acl/support.py +1431 -0
- trigger/acl/tools.py +746 -0
- trigger/bin/__init__.py +0 -0
- trigger/bin/acl.py +233 -0
- trigger/bin/acl_script.py +574 -0
- trigger/bin/aclconv.py +82 -0
- trigger/bin/check_access.py +93 -0
- trigger/bin/check_syntax.py +66 -0
- trigger/bin/fe.py +197 -0
- trigger/bin/find_access.py +191 -0
- trigger/bin/gnng.py +434 -0
- trigger/bin/gong.py +86 -0
- trigger/bin/load_acl.py +841 -0
- trigger/bin/load_config.py +18 -0
- trigger/bin/netdev.py +317 -0
- trigger/bin/optimizer.py +638 -0
- trigger/bin/run_cmds.py +18 -0
- trigger/changemgmt/__init__.py +352 -0
- trigger/changemgmt/bounce.py +57 -0
- trigger/cmds.py +1217 -0
- trigger/conf/__init__.py +94 -0
- trigger/conf/global_settings.py +674 -0
- trigger/contrib/__init__.py +7 -0
- trigger/exceptions.py +307 -0
- trigger/gorc.py +172 -0
- trigger/netdevices/__init__.py +1288 -0
- trigger/netdevices/loader.py +174 -0
- trigger/netscreen.py +1030 -0
- trigger/packages/__init__.py +6 -0
- trigger/packages/peewee.py +8084 -0
- trigger/rancid.py +463 -0
- trigger/tacacsrc.py +584 -0
- trigger/twister.py +2203 -0
- trigger/twister2.py +745 -0
- trigger/utils/__init__.py +88 -0
- trigger/utils/cli.py +349 -0
- trigger/utils/importlib.py +77 -0
- trigger/utils/network.py +157 -0
- trigger/utils/rcs.py +178 -0
- trigger/utils/templates.py +81 -0
- trigger/utils/url.py +78 -0
- trigger/utils/xmltodict.py +298 -0
- trigger-2.0.0.dist-info/METADATA +146 -0
- trigger-2.0.0.dist-info/RECORD +61 -0
- trigger-2.0.0.dist-info/WHEEL +5 -0
- trigger-2.0.0.dist-info/entry_points.txt +15 -0
- trigger-2.0.0.dist-info/licenses/AUTHORS.md +20 -0
- trigger-2.0.0.dist-info/licenses/LICENSE.md +28 -0
- trigger-2.0.0.dist-info/top_level.txt +2 -0
- twisted/plugins/trigger_xmlrpc.py +124 -0
trigger/bin/__init__.py
ADDED
|
File without changes
|
trigger/bin/acl.py
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Interface with the access-control list (ACL) database and task queue.
|
|
5
|
+
|
|
6
|
+
This is a simple command to manage explicit ACL associations within the ACL
|
|
7
|
+
database (acls.db), to search for both implicit and explicit ACL associations,
|
|
8
|
+
and to manage the ACL task queue.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "1.6.1"
|
|
12
|
+
|
|
13
|
+
import optparse
|
|
14
|
+
import sys
|
|
15
|
+
from collections import defaultdict
|
|
16
|
+
from textwrap import wrap
|
|
17
|
+
|
|
18
|
+
from trigger import exceptions
|
|
19
|
+
from trigger.acl.db import AclsDB, get_matching_acls
|
|
20
|
+
from trigger.acl.queue import Queue
|
|
21
|
+
from trigger.conf import settings
|
|
22
|
+
from trigger.utils.cli import get_terminal_width
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def parse_args(argv, optp):
|
|
26
|
+
usage = """
|
|
27
|
+
%prog --display [--exact | --device-name-only] (<acl_name> | <device>)
|
|
28
|
+
%prog (--add | --remove) <acl_name> [<device> [<device> ...]]
|
|
29
|
+
%prog (--clear | --inject) [--quiet] [<acl_name> [<acl_name> ...]]
|
|
30
|
+
%prog (--list | --listmanual)"""
|
|
31
|
+
|
|
32
|
+
# Parse arguments.
|
|
33
|
+
optp.usage = usage
|
|
34
|
+
optp.description = __doc__.strip()
|
|
35
|
+
optp.version = __version__
|
|
36
|
+
optp.add_option(
|
|
37
|
+
"-l",
|
|
38
|
+
"--list",
|
|
39
|
+
help="list ACLs currently in integrated (automated) queue",
|
|
40
|
+
action="store_const",
|
|
41
|
+
const="list",
|
|
42
|
+
dest="mode",
|
|
43
|
+
)
|
|
44
|
+
optp.add_option(
|
|
45
|
+
"-m",
|
|
46
|
+
"--listmanual",
|
|
47
|
+
help="list entries currently in manual queue",
|
|
48
|
+
action="store_const",
|
|
49
|
+
const="listmanual",
|
|
50
|
+
dest="mode",
|
|
51
|
+
)
|
|
52
|
+
optp.add_option(
|
|
53
|
+
"-i",
|
|
54
|
+
"--inject",
|
|
55
|
+
help="inject into load queue",
|
|
56
|
+
action="store_const",
|
|
57
|
+
const="inject",
|
|
58
|
+
dest="mode",
|
|
59
|
+
)
|
|
60
|
+
optp.add_option(
|
|
61
|
+
"-c",
|
|
62
|
+
"--clear",
|
|
63
|
+
help="clear from load queue",
|
|
64
|
+
action="store_const",
|
|
65
|
+
const="clear",
|
|
66
|
+
dest="mode",
|
|
67
|
+
)
|
|
68
|
+
optp.add_option(
|
|
69
|
+
"-D",
|
|
70
|
+
"--display",
|
|
71
|
+
help="display the ACL associations for a device or ACL",
|
|
72
|
+
action="store_true",
|
|
73
|
+
)
|
|
74
|
+
optp.add_option(
|
|
75
|
+
"-x",
|
|
76
|
+
"--exact",
|
|
77
|
+
help="match entire name, not just start",
|
|
78
|
+
action="store_true",
|
|
79
|
+
dest="exact",
|
|
80
|
+
)
|
|
81
|
+
optp.add_option(
|
|
82
|
+
"-d",
|
|
83
|
+
"--device-name-only",
|
|
84
|
+
help="don't match on ACL",
|
|
85
|
+
action="store_true",
|
|
86
|
+
dest="dev_only",
|
|
87
|
+
)
|
|
88
|
+
optp.add_option(
|
|
89
|
+
"-a",
|
|
90
|
+
"--add",
|
|
91
|
+
type="string",
|
|
92
|
+
action="append",
|
|
93
|
+
metavar="<acl_name>",
|
|
94
|
+
help="add an acl to explicit ACL database, example: 'acl -a acl-name device1 device2'",
|
|
95
|
+
)
|
|
96
|
+
optp.add_option(
|
|
97
|
+
"-r",
|
|
98
|
+
"--remove",
|
|
99
|
+
type="string",
|
|
100
|
+
action="append",
|
|
101
|
+
metavar="<acl_name>",
|
|
102
|
+
help="remove an acl from explicit ACL database, example: 'acl -r acl1-name -r acl2-name device'",
|
|
103
|
+
)
|
|
104
|
+
optp.add_option(
|
|
105
|
+
"-q",
|
|
106
|
+
"--quiet",
|
|
107
|
+
help="be quiet! (For use with scripts/cron)",
|
|
108
|
+
action="store_true",
|
|
109
|
+
)
|
|
110
|
+
(opts, args) = optp.parse_args()
|
|
111
|
+
|
|
112
|
+
return opts, args
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def pretty_print_acls(name, acls, term_width, offset=41):
|
|
116
|
+
output = wrap(" ".join(acls), term_width - offset)
|
|
117
|
+
print("%-39s %s" % (name, output[0]))
|
|
118
|
+
for line in output[1:]:
|
|
119
|
+
print(" " * 39, line)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def p_error(optp, msg=None):
|
|
123
|
+
optp.print_help()
|
|
124
|
+
if msg:
|
|
125
|
+
optp.error(msg)
|
|
126
|
+
sys.exit(1)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def main():
|
|
130
|
+
"""Main entry point for the CLI tool."""
|
|
131
|
+
# Setup
|
|
132
|
+
aclsdb = AclsDB()
|
|
133
|
+
term_width = get_terminal_width() # How wide is your term!
|
|
134
|
+
valid_modes = ["list", "listmanual"] # Valid listing modes
|
|
135
|
+
|
|
136
|
+
optp = optparse.OptionParser()
|
|
137
|
+
opts, args = parse_args(sys.argv, optp)
|
|
138
|
+
|
|
139
|
+
if opts.add and opts.remove:
|
|
140
|
+
p_error(optp, "cannot both add & remove: pick one.")
|
|
141
|
+
|
|
142
|
+
if opts.add or opts.remove:
|
|
143
|
+
if len(args) == 0:
|
|
144
|
+
p_error(optp, "must specify at least one device to modify")
|
|
145
|
+
|
|
146
|
+
elif (len(args) == 0 and opts.mode not in valid_modes) or (
|
|
147
|
+
len(args) != 0 and opts.mode in valid_modes
|
|
148
|
+
):
|
|
149
|
+
p_error(optp)
|
|
150
|
+
sys.exit(1)
|
|
151
|
+
|
|
152
|
+
queue = Queue()
|
|
153
|
+
|
|
154
|
+
if opts.mode == "list":
|
|
155
|
+
acl_data = defaultdict(list)
|
|
156
|
+
[acl_data[acl].append(router) for router, acl in queue.list()]
|
|
157
|
+
if acl_data:
|
|
158
|
+
[
|
|
159
|
+
pretty_print_acls(dev, acl_data[dev], term_width)
|
|
160
|
+
for dev in sorted(acl_data)
|
|
161
|
+
]
|
|
162
|
+
else:
|
|
163
|
+
print("Nothing in the integrated queue.")
|
|
164
|
+
|
|
165
|
+
elif opts.mode == "listmanual":
|
|
166
|
+
for item, user, ts, done in queue.list(queue="manual"):
|
|
167
|
+
print(item)
|
|
168
|
+
print(f"\tadded by {user} on {ts}")
|
|
169
|
+
print()
|
|
170
|
+
if not queue.list(queue="manual"):
|
|
171
|
+
print("Nothing in the manual queue.")
|
|
172
|
+
|
|
173
|
+
elif opts.mode == "inject":
|
|
174
|
+
for arg in args:
|
|
175
|
+
devs = [dev[0] for dev in get_matching_acls([arg])]
|
|
176
|
+
queue.insert(arg, devs)
|
|
177
|
+
|
|
178
|
+
elif opts.mode == "clear":
|
|
179
|
+
[queue.delete(arg) for arg in args]
|
|
180
|
+
|
|
181
|
+
elif opts.add or opts.remove:
|
|
182
|
+
from trigger.netdevices import NetDevices
|
|
183
|
+
|
|
184
|
+
nd = NetDevices()
|
|
185
|
+
|
|
186
|
+
invalid_dev_count = 0
|
|
187
|
+
|
|
188
|
+
for arg in args:
|
|
189
|
+
try:
|
|
190
|
+
dev = nd.find(arg.lower())
|
|
191
|
+
except KeyError:
|
|
192
|
+
print(f"skipping {arg}: invalid device")
|
|
193
|
+
invalid_dev_count += 1
|
|
194
|
+
continue
|
|
195
|
+
# the continue here leads that single error if its the only attempt
|
|
196
|
+
|
|
197
|
+
if opts.add:
|
|
198
|
+
for acl in opts.add:
|
|
199
|
+
try:
|
|
200
|
+
print(aclsdb.add_acl(dev, acl))
|
|
201
|
+
except exceptions.ACLSetError as err:
|
|
202
|
+
print(err)
|
|
203
|
+
|
|
204
|
+
elif opts.remove:
|
|
205
|
+
for acl in opts.remove:
|
|
206
|
+
try:
|
|
207
|
+
print(aclsdb.remove_acl(dev, acl))
|
|
208
|
+
except exceptions.ACLSetError as err:
|
|
209
|
+
# Check if it is an implicit ACL
|
|
210
|
+
if acl in aclsdb.get_acl_set(dev, "implicit"):
|
|
211
|
+
print(f"This ACL is associated via {settings.AUTOACL_FILE}")
|
|
212
|
+
else:
|
|
213
|
+
print(err)
|
|
214
|
+
|
|
215
|
+
if invalid_dev_count == len(args):
|
|
216
|
+
print("\nPlease use --help to find the right syntax.")
|
|
217
|
+
|
|
218
|
+
elif opts.display:
|
|
219
|
+
# Pretty-print the device/acls justified to the terminal
|
|
220
|
+
acl_data = get_matching_acls(
|
|
221
|
+
args, opts.exact, match_acl=(not opts.dev_only), match_device=True
|
|
222
|
+
)
|
|
223
|
+
if not acl_data:
|
|
224
|
+
msg = f"No results for {args}" if not opts.quiet else 1
|
|
225
|
+
sys.exit(msg)
|
|
226
|
+
|
|
227
|
+
[pretty_print_acls(name, acls, term_width) for name, acls in acl_data]
|
|
228
|
+
else: # No options were handled, display help and exit
|
|
229
|
+
p_error(optp)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
if __name__ == "__main__":
|
|
233
|
+
main()
|