summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-03-08 19:01:33 +0100
committerChristian Poessinger <christian@poessinger.com>2019-03-08 19:04:43 +0100
commitd17f30a5002bc2ca6c65d486b917fbd8034fdcaf (patch)
treef2dbbc9d79d665708cfd70e3950a5e120d9887b1
parent784d15af11ce115419b2b27ec274a0fba81db267 (diff)
downloadvyos-1x-d17f30a5002bc2ca6c65d486b917fbd8034fdcaf.tar.gz
vyos-1x-d17f30a5002bc2ca6c65d486b917fbd8034fdcaf.zip
T1277: [dhcp-server] bugfix 'show dhcp server leases'
The script did not check if the service was actually configured or not. This caused a FileNotFoundError for unconfigured services. vyos@vyos:~$ show dhcp server leases Traceback (most recent call last): File "/usr/libexec/vyos/op_mode/show_dhcp.py", line 123, in <module> leases = get_leases(lease_file, state='active') File "/usr/libexec/vyos/op_mode/show_dhcp.py", line 60, in get_leases leases = IscDhcpLeases(lease_file).get() File "/usr/lib/python3/dist-packages/isc_dhcp_leases/iscdhcpleases.py", line 110, in get with open(self.filename) as lease_file: FileNotFoundError: [Errno 2] No such file or directory: '/config/dhcpd.leases' (cherry picked from commit ed620ef7e8ba741e165698c558b110a31cc35dfd)
-rwxr-xr-xsrc/op_mode/show_dhcp.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/op_mode/show_dhcp.py b/src/op_mode/show_dhcp.py
index 0005d62a3..4c4ee6355 100755
--- a/src/op_mode/show_dhcp.py
+++ b/src/op_mode/show_dhcp.py
@@ -18,14 +18,12 @@
import json
import argparse
import ipaddress
-
import tabulate
+import sys
-import vyos.config
-
+from vyos.config import Config
from isc_dhcp_leases import Lease, IscDhcpLeases
-
lease_file = "/config/dhcpd.leases"
pool_key = "shared-networkname"
@@ -110,6 +108,12 @@ if __name__ == '__main__':
args = parser.parse_args()
+ # Do nothing if service is not configured
+ config = Config()
+ if not config.exists_effective('service dhcp-server'):
+ print("DHCP service is not configured")
+ sys.exit(0)
+
if args.leases:
if args.expired:
if args.pool:
@@ -127,8 +131,6 @@ if __name__ == '__main__':
else:
show_leases(leases)
elif args.statistics:
- config = vyos.config.Config()
-
pools = []
# Get relevant pools