summaryrefslogtreecommitdiff
path: root/src/op_mode/show_dhcpv6.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-03-08 18:54:57 +0100
committerChristian Poessinger <christian@poessinger.com>2019-03-08 19:04:41 +0100
commit784d15af11ce115419b2b27ec274a0fba81db267 (patch)
tree345b4174e51896801f9ae32dafe7d619e02b7fb5 /src/op_mode/show_dhcpv6.py
parent7794b835e246214493b91f120a18a02248dca076 (diff)
downloadvyos-1x-784d15af11ce115419b2b27ec274a0fba81db267.tar.gz
vyos-1x-784d15af11ce115419b2b27ec274a0fba81db267.zip
T1277: [dhcpv6-server] bugfix 'show dhcpv6 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 dhcpv6 server leases Traceback (most recent call last): File "/usr/libexec/vyos/op_mode/show_dhcpv6.py", line 77, in <module> leases = get_leases(lease_file, state='active') File "/usr/libexec/vyos/op_mode/show_dhcpv6.py", line 46, 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/dhcpdv6.leases' (cherry picked from commit a6700c7d3b75854c3b213b65951a51464cd073be)
Diffstat (limited to 'src/op_mode/show_dhcpv6.py')
-rwxr-xr-xsrc/op_mode/show_dhcpv6.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/op_mode/show_dhcpv6.py b/src/op_mode/show_dhcpv6.py
index 8879a45c5..bf73b92ea 100755
--- a/src/op_mode/show_dhcpv6.py
+++ b/src/op_mode/show_dhcpv6.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/dhcpdv6.leases"
def get_lease_data(lease):
@@ -73,6 +71,12 @@ if __name__ == '__main__':
args = parser.parse_args()
+ # Do nothing if service is not configured
+ c = Config()
+ if not c.exists_effective('service dhcpv6-server'):
+ print("DHCPv6 service is not configured")
+ sys.exit(0)
+
if args.leases:
leases = get_leases(lease_file, state='active')
show_leases(leases)