summaryrefslogtreecommitdiff
path: root/scripts/rtslib-saveconfig
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/rtslib-saveconfig')
-rwxr-xr-xscripts/rtslib-saveconfig56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/rtslib-saveconfig b/scripts/rtslib-saveconfig
new file mode 100755
index 0000000..b8791d1
--- /dev/null
+++ b/scripts/rtslib-saveconfig
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+'''
+rtslib-saveconfig
+
+This file is part of RTSLib.
+Copyright (c) 2013 by Red Hat, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may
+not use this file except in compliance with the License. You may obtain
+a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations
+under the License.
+'''
+
+#
+# A script to save LIO configuration to a file in json format
+#
+
+from __future__ import print_function
+
+from rtslib import RTSRoot
+import os
+import sys
+import stat
+import json
+
+default_save_file = "/etc/target/saveconfig.json"
+err = sys.stderr
+
+if os.geteuid() != 0:
+ print("Must run as root", file=err)
+ sys.exit(-1)
+
+if not len(sys.argv) <= 2 and sys.argv[1] == "--help":
+ print("syntax: %s [file_to_save_to]" % sys.argv[0], file=err)
+ print(" default file is: %s" % default_save_file, file=err)
+ sys.exit(-1)
+
+if len(sys.argv) == 2:
+ save_file = os.path.expanduser(sys.argv[1])
+else:
+ save_file = default_save_file
+
+with open(save_file+".temp", "w+") as f:
+ os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IWUSR)
+ f.write(json.dumps(RTSRoot().dump(), sort_keys=True, indent=2))
+ f.write("\n")
+ os.fsync(f.fileno())
+
+os.rename(save_file+".temp", save_file)