[PATCH 17/37] Add documentation and print something on save/restore

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Also, save a backup if overwriting an existing file when saving.

Signed-off-by: Andy Grover <agrover@xxxxxxxxxx>
---
 targetcli/ui_root.py |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/targetcli/ui_root.py b/targetcli/ui_root.py
index 4ef836a..a170d1e 100644
--- a/targetcli/ui_root.py
+++ b/targetcli/ui_root.py
@@ -73,16 +73,34 @@ class UIRoot(UINode):
                 UIFabricModule(fabric_module, self)
 
     def ui_command_save(self, savefile=default_save_file):
+        '''
+        Saves the current configuration to a file so that it can be restored
+        on next boot.
+        '''
         from rtslib.root import RTSRoot
         import json
+        import shutil
 
         self.assert_root()
 
+        backupfile = savefile + ".backup"
+        try:
+            shutil.move(savefile, backupfile)
+            self.shell.log.info("Existing file %s backed up to %s" % \
+                                    (savefile, backupfile))
+        except IOError:
+            pass
+
         with open(savefile, "w+") as f:
             f.write(json.dumps(RTSRoot().dump(), sort_keys=True, indent=2))
             f.write("\n")
 
+        self.shell.log.info("Configuration saved to %s" % savefile)
+
     def ui_command_restore(self, savefile=default_save_file, clear_existing=False):
+        '''
+        Restores configuration from a file.
+        '''
         from rtslib.root import RTSRoot
         import json
 
@@ -91,6 +109,8 @@ class UIRoot(UINode):
         with open(savefile, "r") as f:
             RTSRoot().restore(json.loads(f.read()), clear_existing)
 
+        self.shell.log.info("Configuration restored from %s" % savefile)
+
         self.refresh()
 
     def ui_command_saveconfig(self):
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux