summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2011-12-09 12:16:54 -0800
committerAndy Grover <agrover@redhat.com>2011-12-09 12:16:54 -0800
commit743a420e57329e7d1235f3d2b98473e6dfa886e3 (patch)
tree15b7336cd82319847fc89bdb0bbcf42e1b069999
parent38411ea1f75d1e905e9b5c76db926ccc5a9a85b3 (diff)
downloadrtslib-fb-743a420e57329e7d1235f3d2b98473e6dfa886e3.tar.gz
Add docs. Add clear_existing()
Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r--rtslib/root.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/rtslib/root.py b/rtslib/root.py
index 033659b..b055c24 100644
--- a/rtslib/root.py
+++ b/rtslib/root.py
@@ -140,6 +140,11 @@ class RTSRoot(CFSNode):
# RTSRoot public stuff
def dump(self):
+ '''
+ Returns a dict representing the complete state of the target
+ config, suitable for serialization/deserialization, and then
+ handing to restore().
+ '''
d = super(RTSRoot, self).dump()
# backstores:storage_object is *usually* 1:1. In any case, they're an
# implementation detail that the user doesn't need to care about.
@@ -154,15 +159,27 @@ class RTSRoot(CFSNode):
d['targets'] = [t.dump() for t in self.targets]
return d
- def restore(self, config, clear_existing=False):
+ def clear_existing(self, confirm=False):
+ '''
+ Remove entire current configuration.
+ '''
+ if not confirm:
+ raise RTSLibError("As a precaution, confirm=True needs to be set")
+ # targets depend on storage objects, delete them first
+ for t in self.targets:
+ t.delete()
+ for so in self.storage_objects:
+ so.delete()
+
+ def restore(self, config, clear_existing=False):
+ '''
+ Takes a dict generated by dump() and reconfigures the target to match.
+ '''
if clear_existing:
- for so in self.storage_objects:
- so.delete()
- for t in self.targets:
- t.delete()
+ self.clear_existing(confirm=True)
- if not clear_existing and (self.backstores or self.targets):
+ if not clear_existing and (self.storage_objects or self.targets):
raise RTSLibError("backstores or targets present, not restoring." +
" Set clear_existing=True?")