File 0028-lio_dump-Implement-file-option.patch of Package lio-utils.216
From 47c3dbd3ba322d7d00881dada8282968a2f07349 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Thu, 15 May 2014 10:06:22 +0200
Subject: lio_dump: Implement '--file' option
Implement an optino '--file' to dump the script into a file.
This is required for systemd support as the system service
unit syntax doesn't support redirection.
References: bnc#876881
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
lio-py/lio_dump.py | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/lio-py/lio_dump.py b/lio-py/lio_dump.py
index c6a3600..13c5a31 100755
--- a/lio-py/lio_dump.py
+++ b/lio-py/lio_dump.py
@@ -279,6 +279,38 @@ def lio_backup_to_file(option, opt_str, value, parser):
back.close()
return backup_file
+def lio_dump_to_file(option, opt_str, value, parser):
+ dump_file = str(value)
+
+ op = "lio_dump --stdout"
+ p = sub.Popen(op, shell=True, stdout=sub.PIPE).stdout
+ if not p:
+ print "Unable to dump LIO-Target/ConfigFS running state"
+ sys.exit(1)
+
+ try:
+ back = open(dump_file, 'w+')
+ except IOError:
+ print "cannot open " + dump_file
+ p.close()
+ sys.exit(1)
+ else:
+ line = p.readline()
+ while line:
+ print >>back, line.rstrip()
+ line = p.readline()
+
+ back.close()
+
+ p.close()
+
+ op = "chmod 755 " + dump_file
+ ret = os.system(op)
+ if ret:
+ print "Unable to mark " + dump_file + " as executable"
+
+ return dump_file
+
def main():
parser = OptionParser()
@@ -286,6 +318,8 @@ def main():
help="Dump running LIO-Target/ConfigFS syntax to STDOUT")
parser.add_option("--t", "--tofile", action="callback", callback=lio_backup_to_file, nargs=1,
type="string", dest="DATE_TIME", help="Backup running LIO-Target/ConfigFS syntax to /etc/target/backup/lio_backup-<DATE_TIME>.sh")
+ parser.add_option("--f", "--file", action="callback", callback=lio_dump_to_file, nargs=1,
+ type="string", dest="DUMP_FILE", help="Save running LIO-Target/ConfigFS syntax to <DUMP_FILE>")
(options, args) = parser.parse_args()
if len(sys.argv) == 1:
--
1.7.12.4