forked from Uninett/nav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavdf
executable file
·62 lines (50 loc) · 1.73 KB
/
navdf
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
#!/usr/bin/env python
#
# Copyright (C) 2014, 2016 Uninett AS
#
# This file is part of Network Administration Visualized (NAV).
#
# NAV is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 3 as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. You should have received a copy of the GNU General Public
# License along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
"""
A command line interface to list and filter IP devices monitored by NAV
"""
from __future__ import print_function
import argparse
from nav.bootstrap import bootstrap_django
bootstrap_django(__file__)
from nav.models.manage import Netbox
def main():
"""Main program"""
args = parse_args()
if args.filter:
qs = eval('Netbox.objects.' + args.filter)
else:
qs = Netbox.objects.all()
for netbox in qs.order_by('sysname').values_list('sysname', flat=1):
print(netbox)
def parse_args():
"""Builds an ArgumentParser and returns parsed program arguments"""
parser = argparse.ArgumentParser(
description="Lists and filters IP devices monitored by NAV",
usage="%(prog)s [filter]",
)
parser.add_argument(
'filter',
nargs='?',
help="The filter expression must be a method call "
"applicable to the Django-based Netbox model's "
"manager class. Example: "
"\"filter(category__id='GSW')\"",
)
return parser.parse_args()
if __name__ == '__main__':
main()