From b9322a9f95ff084e3e0276c6e831902fbf5c8933 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Tue, 2 Dec 2008 10:19:30 +0000 Subject: [PATCH] ImportExport: make src_node and src_path optional If src_node is not there we'll default to using the currently exported instance name as src_path. Also, if src_path is not absolute we'll look for it in EXPORT_DIR. Reviewed-by: iustinp --- lib/cmdlib.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 7e6fe7851..6d4c0598b 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -3650,16 +3650,22 @@ class LUCreateInstance(LogicalUnit): src_node = getattr(self.op, "src_node", None) src_path = getattr(self.op, "src_path", None) - if src_node is None or src_path is None: - raise errors.OpPrereqError("Importing an instance requires source" - " node and path options") + if src_path is None: + self.op.src_path = src_path = self.op.instance_name - if not os.path.isabs(src_path): - raise errors.OpPrereqError("The source path must be absolute") - - self.op.src_node = src_node = self._ExpandNode(src_node) - if self.needed_locks[locking.LEVEL_NODE] is not locking.ALL_SET: - self.needed_locks[locking.LEVEL_NODE].append(src_node) + if src_node is None: + self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET + self.op.src_node = None + if os.path.isabs(src_path): + raise errors.OpPrereqError("Importing an instance from an absolute" + " path requires a source node option.") + else: + self.op.src_node = src_node = self._ExpandNode(src_node) + if self.needed_locks[locking.LEVEL_NODE] is not locking.ALL_SET: + self.needed_locks[locking.LEVEL_NODE].append(src_node) + if not os.path.isabs(src_path): + self.op.src_path = src_path = \ + os.path.join(constants.EXPORT_DIR, src_path) else: # INSTANCE_CREATE if getattr(self.op, "os_type", None) is None: -- GitLab