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.
Files changed (61) hide show
  1. trigger/__init__.py +7 -0
  2. trigger/acl/__init__.py +32 -0
  3. trigger/acl/autoacl.py +70 -0
  4. trigger/acl/db.py +324 -0
  5. trigger/acl/dicts.py +357 -0
  6. trigger/acl/grammar.py +112 -0
  7. trigger/acl/ios.py +222 -0
  8. trigger/acl/junos.py +422 -0
  9. trigger/acl/models.py +118 -0
  10. trigger/acl/parser.py +168 -0
  11. trigger/acl/queue.py +296 -0
  12. trigger/acl/support.py +1431 -0
  13. trigger/acl/tools.py +746 -0
  14. trigger/bin/__init__.py +0 -0
  15. trigger/bin/acl.py +233 -0
  16. trigger/bin/acl_script.py +574 -0
  17. trigger/bin/aclconv.py +82 -0
  18. trigger/bin/check_access.py +93 -0
  19. trigger/bin/check_syntax.py +66 -0
  20. trigger/bin/fe.py +197 -0
  21. trigger/bin/find_access.py +191 -0
  22. trigger/bin/gnng.py +434 -0
  23. trigger/bin/gong.py +86 -0
  24. trigger/bin/load_acl.py +841 -0
  25. trigger/bin/load_config.py +18 -0
  26. trigger/bin/netdev.py +317 -0
  27. trigger/bin/optimizer.py +638 -0
  28. trigger/bin/run_cmds.py +18 -0
  29. trigger/changemgmt/__init__.py +352 -0
  30. trigger/changemgmt/bounce.py +57 -0
  31. trigger/cmds.py +1217 -0
  32. trigger/conf/__init__.py +94 -0
  33. trigger/conf/global_settings.py +674 -0
  34. trigger/contrib/__init__.py +7 -0
  35. trigger/exceptions.py +307 -0
  36. trigger/gorc.py +172 -0
  37. trigger/netdevices/__init__.py +1288 -0
  38. trigger/netdevices/loader.py +174 -0
  39. trigger/netscreen.py +1030 -0
  40. trigger/packages/__init__.py +6 -0
  41. trigger/packages/peewee.py +8084 -0
  42. trigger/rancid.py +463 -0
  43. trigger/tacacsrc.py +584 -0
  44. trigger/twister.py +2203 -0
  45. trigger/twister2.py +745 -0
  46. trigger/utils/__init__.py +88 -0
  47. trigger/utils/cli.py +349 -0
  48. trigger/utils/importlib.py +77 -0
  49. trigger/utils/network.py +157 -0
  50. trigger/utils/rcs.py +178 -0
  51. trigger/utils/templates.py +81 -0
  52. trigger/utils/url.py +78 -0
  53. trigger/utils/xmltodict.py +298 -0
  54. trigger-2.0.0.dist-info/METADATA +146 -0
  55. trigger-2.0.0.dist-info/RECORD +61 -0
  56. trigger-2.0.0.dist-info/WHEEL +5 -0
  57. trigger-2.0.0.dist-info/entry_points.txt +15 -0
  58. trigger-2.0.0.dist-info/licenses/AUTHORS.md +20 -0
  59. trigger-2.0.0.dist-info/licenses/LICENSE.md +28 -0
  60. trigger-2.0.0.dist-info/top_level.txt +2 -0
  61. twisted/plugins/trigger_xmlrpc.py +124 -0
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Uses Trigger libraries to load configs on network devices.
5
+
6
+ Please see `~trigger.contrib.docommand.ConfigLoader` for details
7
+ """
8
+
9
+ from trigger.contrib import docommand
10
+
11
+
12
+ def main():
13
+ """Main entry point for the CLI tool."""
14
+ docommand.main(action_class=docommand.ConfigLoader)
15
+
16
+
17
+ if __name__ == "__main__":
18
+ main()
trigger/bin/netdev.py ADDED
@@ -0,0 +1,317 @@
1
+ #!/usr/bin/env python
2
+
3
+ """
4
+ netdev - Command-line search interface for NetDevices.
5
+ """
6
+
7
+ __version__ = "1.2"
8
+
9
+ import sys
10
+ from optparse import OptionParser
11
+
12
+ from trigger.netdevices import NetDevices, device_match
13
+
14
+
15
+ def parse_args(argv):
16
+ """Parse arguments, duh. There is a better way to do this using Twisted's
17
+ usage module, but replacing it is not a high priority."""
18
+ parser = OptionParser(
19
+ usage="%prog [options]",
20
+ description="\nCommand-line search interface for 'NetDevices' metadata.",
21
+ version="%prog " + __version__,
22
+ )
23
+
24
+ parser.add_option(
25
+ "-a",
26
+ "--acls",
27
+ action="store_true",
28
+ help="Search will return acls instead of devices.",
29
+ )
30
+ parser.add_option(
31
+ "-l",
32
+ "--list",
33
+ type="string",
34
+ metavar="<DEVICE>",
35
+ help="List all information for individual DEVICE",
36
+ )
37
+ parser.add_option(
38
+ "-s",
39
+ "--search",
40
+ action="store_true",
41
+ help="Perform a search based on matching criteria",
42
+ )
43
+ parser.add_option(
44
+ "-L",
45
+ "--location",
46
+ type="string",
47
+ metavar="<LOCATION>",
48
+ help="For use with -s: Match on site location.",
49
+ )
50
+ parser.add_option(
51
+ "-n",
52
+ "--nodename",
53
+ type="string",
54
+ metavar="<NODENAME>",
55
+ help="For use with -s: Match on full or partial nodeName. NO REGEXP.",
56
+ )
57
+ parser.add_option(
58
+ "-t",
59
+ "--type",
60
+ type="string",
61
+ metavar="<TYPE>",
62
+ help="For use with -s: Match on deviceType. Must be FIREWALL, ROUTER, or SWITCH.",
63
+ )
64
+ parser.add_option(
65
+ "-o",
66
+ "--owning-team",
67
+ type="string",
68
+ metavar="<OWNING TEAM NAME>",
69
+ help="For use with -s: Match on Owning Team (owningTeam).",
70
+ )
71
+ parser.add_option(
72
+ "-O",
73
+ "--oncall-team",
74
+ type="string",
75
+ metavar="<ONCALL TEAM NAME>",
76
+ help="For use with -s: Match on Oncall Team (onCallName).",
77
+ )
78
+ parser.add_option(
79
+ "-C",
80
+ "--owning-org",
81
+ type="string",
82
+ metavar="<OWNING ORG>",
83
+ help="For use with -s: Match on cost center Owning Org. (owner).",
84
+ )
85
+ parser.add_option(
86
+ "-v",
87
+ "--vendor",
88
+ type="string",
89
+ metavar="<VENDOR>",
90
+ help="For use with -s: Match on canonical vendor name.",
91
+ )
92
+ parser.add_option(
93
+ "-m",
94
+ "--manufacturer",
95
+ type="string",
96
+ metavar="<MANUFACTURER>",
97
+ help="For use with -s: Match on manufacturer.",
98
+ )
99
+ parser.add_option(
100
+ "-b",
101
+ "--budget-code",
102
+ type="string",
103
+ metavar="<BUDGET CODE>",
104
+ help="For use with -s: Match on budget code",
105
+ )
106
+ parser.add_option(
107
+ "-B",
108
+ "--budget-name",
109
+ type="string",
110
+ metavar="<BUDGET NAME>",
111
+ help="For use with -s: Match on budget name",
112
+ )
113
+ parser.add_option(
114
+ "-k",
115
+ "--make",
116
+ type="string",
117
+ metavar="<MAKE>",
118
+ help="For use with -s: Match on make.",
119
+ )
120
+ parser.add_option(
121
+ "-M",
122
+ "--model",
123
+ type="string",
124
+ metavar="<MODEL>",
125
+ help="For use with -s: Match on model.",
126
+ )
127
+ parser.add_option(
128
+ "-c",
129
+ "--coordinate",
130
+ type="string",
131
+ metavar="<COORDINATE>",
132
+ help="For use with -s: Match on coordinate (rack number).",
133
+ )
134
+ parser.add_option(
135
+ "-N",
136
+ "--nonprod",
137
+ action="store_false",
138
+ default=True,
139
+ help="Look for production and non-production devices.",
140
+ )
141
+ # parser.add_option('-A', '--aclname', action='append', default=[],
142
+ # help='For use with -s: Match on acl filter name. You may add multiple.')
143
+
144
+ opts, args = parser.parse_args(argv)
145
+
146
+ if opts.list and opts.search:
147
+ parser.error("-l and -s cannot be used together")
148
+
149
+ # Turn opts.list into NetDevice object
150
+ if opts.list:
151
+ dev = device_match(opts.list.lower(), production_only=opts.nonprod)
152
+ if not dev:
153
+ sys.exit(1)
154
+ dev.dump()
155
+
156
+ if not opts.list and not opts.search:
157
+ parser.print_help()
158
+ parser.error("must choose either -l or -s (but not both!)")
159
+ sys.exit(1)
160
+
161
+ if opts.search:
162
+ # Get a list of search options, stripping out modifiers. This makes us
163
+ # resilient to adding new arguments without having to explicitly check
164
+ # for them by name, so long as they aren't one of the modifying opts.
165
+ # If you add a Boolean option, add it to skip_opts.
166
+ skip_opts = ("list", "search", "help", "acls", "nonprod")
167
+ search_opts = [x for x in sorted(opts.__dict__) if x not in skip_opts]
168
+ oget = opts.__dict__.get
169
+
170
+ # Any valid search argument is good
171
+ if any(oget(o) for o in search_opts):
172
+ search_builder(opts)
173
+ else:
174
+ parser.print_help()
175
+ parser.error("-s needs at least one other option, excluding -l.")
176
+
177
+ return opts, args
178
+
179
+
180
+ def search_builder(opts):
181
+ """Builds a list comprehension from the options passed at command-line and
182
+ then evaluates it to return a list of matching device names."""
183
+ NetDevices(production_only=opts.nonprod)
184
+
185
+ query = "[x for x in nd.all()"
186
+
187
+ # Prep variables
188
+ vars = list()
189
+ # print opts
190
+
191
+ # For all search arguments, when an explicit match would not be confusing
192
+ # or return inconsistent results, the argument is being upper-cased
193
+ # and a membership (in) test is being performed.
194
+ #
195
+ # For explicit matches, use an equality (==) test instead.
196
+
197
+ # nodeName (hostname)
198
+ if opts.nodename:
199
+ vars.append(f" '{opts.nodename.lower()}' in x.nodeName.lower()")
200
+
201
+ # deviceType
202
+ if opts.type:
203
+ vars.append(f" '{opts.type.upper()}' in x.deviceType")
204
+
205
+ # onCallName (oncall team)
206
+ if opts.oncall_team:
207
+ vars.append(f" '{opts.oncall_team.lower()}' in x.onCallName.lower()")
208
+
209
+ # owningTeam (owning_team)
210
+ if opts.owning_team:
211
+ vars.append(f" '{opts.owning_team.lower()}' in x.owningTeam.lower()")
212
+
213
+ # owner (owning org)
214
+ if opts.owning_org:
215
+ vars.append(f" '{opts.owning_org.upper()}' in x.owner")
216
+
217
+ # budgetCode (budget code)
218
+ if opts.budget_code:
219
+ vars.append(f" '{opts.budget_code}' in x.budgetCode")
220
+
221
+ # budgetName (budget name)
222
+ if opts.budget_name:
223
+ vars.append(f" '{opts.budget_name.lower()}' in x.budgetName.lower()")
224
+
225
+ # vendor
226
+ if opts.vendor:
227
+ vars.append(f" '{opts.vendor.lower()}' in x.vendor")
228
+
229
+ # manufacturer
230
+ if opts.manufacturer:
231
+ vars.append(f" '{opts.manufacturer.upper()}' in x.manufacturer")
232
+
233
+ # site
234
+ if opts.location:
235
+ vars.append(f" '{opts.location.upper()}' in x.site")
236
+
237
+ # make
238
+ if opts.make:
239
+ vars.append(f" '{opts.make.upper()}' in x.make")
240
+
241
+ # model
242
+ if opts.model:
243
+ vars.append(f" '{opts.model.upper()}' in x.model")
244
+
245
+ # coordinate/rack
246
+ if opts.coordinate:
247
+ vars.append(f" '{opts.coordinate.upper()}' in x.coordinate")
248
+ # if opts.aclname: vars.append(" '%s' in x.model" % opts.model)
249
+
250
+ # print vars
251
+ # print 'vlen =', len(vars)
252
+
253
+ # Build a list comprehension based on the vars list.
254
+ # so:
255
+ # [" 'SWITCH' in x.deviceType", 'juniper' in x.vendor"]
256
+ # becomes:
257
+ # [x for x in nd.all() if 'SWITCH' in x.deviceType and 'juniper' in
258
+ # x.vendor]
259
+ query += " if"
260
+ vlen = len(vars)
261
+ counter = 1
262
+ for i in range(vlen):
263
+ query += vars[i]
264
+ if counter != vlen:
265
+ query += " and"
266
+ counter += 1
267
+
268
+ # Finalize query
269
+ query += "]"
270
+ # print query
271
+
272
+ try:
273
+ devlist = eval(query)
274
+ except TypeError:
275
+ from trigger.conf import settings
276
+
277
+ print(
278
+ f"A required field in {settings.NETDEVICES_SOURCE} is missing or invalid. Please fix the data and try again."
279
+ )
280
+ sys.exit(1)
281
+
282
+ devlist.sort()
283
+
284
+ # Store opts_dict for print_results
285
+ opts_dict = vars(opts)
286
+
287
+ # Print acls
288
+ if opts.acls:
289
+ acls = set()
290
+ for dev in devlist:
291
+ for acl in dev.acls:
292
+ acls.add(acl)
293
+
294
+ dump = [x for x in acls]
295
+ dump.sort()
296
+ for acl in dump:
297
+ print(acl)
298
+ # Print devices
299
+ else:
300
+ if devlist:
301
+ for dev in devlist:
302
+ print(dev)
303
+ else:
304
+ squery = []
305
+ for key, value in opts_dict.items():
306
+ if key not in ("search", "nonprod") and value:
307
+ squery.append(key + "=" + value)
308
+ print("No matches for the query {}.".format(" and ".join(squery)))
309
+
310
+
311
+ def main():
312
+ """Main entry point for the CLI tool."""
313
+ opts, args = parse_args(sys.argv)
314
+
315
+
316
+ if __name__ == "__main__":
317
+ main()