summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJoe Groocock <me@frebib.net>2023-08-20 14:40:38 +0100
committerViacheslav Hletenko <v.gletenko@vyos.io>2023-12-06 06:55:31 +0000
commit7d49f7079f1129c2fadc7f38ceb230804d89e177 (patch)
treeab142ba5a5f9dcd0fc1994be0bc0f17852f0d368 /python
parent99c674cdf6147a69fd57b4151886ff42917caeec (diff)
downloadvyos-1x-7d49f7079f1129c2fadc7f38ceb230804d89e177.tar.gz
vyos-1x-7d49f7079f1129c2fadc7f38ceb230804d89e177.zip
nat64: T160: Implement Jool-based NAT64 translator
Signed-off-by: Joe Groocock <me@frebib.net>
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 9f27a7fb9..2b1f23b34 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