summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJoe Groocock <me@frebib.net>2023-08-20 14:40:38 +0100
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2023-12-07 14:11:00 +0000
commitdfca06b0584116ac88bcb1585e8750ecfeeb4dd4 (patch)
treee477777e046b87a956fd4618220ddf2eba1495a1 /python
parent18b2bb669bb87cde14324cbc2ae3a16d11fa578a (diff)
downloadvyos-1x-dfca06b0584116ac88bcb1585e8750ecfeeb4dd4.tar.gz
vyos-1x-dfca06b0584116ac88bcb1585e8750ecfeeb4dd4.zip
nat64: T160: Implement Jool-based NAT64 translator
Signed-off-by: Joe Groocock <me@frebib.net> (cherry picked from commit 7d49f7079f1129c2fadc7f38ceb230804d89e177) # Conflicts: # debian/control
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/file.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/python/vyos/utils/file.py b/python/vyos/utils/file.py
index 667a2464b..e20899fe7 100644
--- a/python/vyos/utils/file.py
+++ b/python/vyos/utils/file.py
@@ -83,6 +83,20 @@ def read_json(fname, defaultonfailure=None):
return defaultonfailure
raise e
+def write_json(fname, data, indent=2, defaultonfailure=None):
+ """
+ encode data to json and write to a file
+ should defaultonfailure be not None, it is returned on failure to write
+ """
+ import json
+ try:
+ with open(fname, 'w') as f:
+ json.dump(data, f, indent=indent)
+ except Exception as e:
+ if defaultonfailure is not None:
+ return defaultonfailure
+ raise e
+
def chown(path, user, group):
""" change file/directory owner """
from pwd import getpwnam