+def _ConfirmOperation(inames, text):
+ """Ask the user to confirm an operation on a list of instances.
+
+ This function is used to request confirmation for doing an operation
+ on a given list of instances.
+
+ The inames argument is what the selection algorithm computed, and
+ the text argument is the operation we should tell the user to
+ confirm (e.g. 'shutdown' or 'startup').
+
+ Returns: boolean depending on user's confirmation.
+
+ """
+ count = len(inames)
+ msg = ("The %s will operate on %d instances.\n"
+ "Do you want to continue?" % (text, count))
+ affected = ("\nAffected instances:\n" +
+ "\n".join([" %s" % name for name in inames]))
+
+ choices = [('y', True, 'Yes, execute the %s' % text),
+ ('n', False, 'No, abort the %s' % text)]
+
+ if count > 20:
+ choices.insert(1, ('v', 'v', 'View the list of affected instances'))
+ ask = msg
+ else:
+ ask = msg + affected
+
+ choice = AskUser(ask, choices)
+ if choice == 'v':
+ choices.pop(1)
+ choice = AskUser(choices, msg + affected)
+ return choice
+
+
+def _TransformPath(user_input):
+ """Transform a user path into a canonical value.
+
+ This function transforms the a path passed as textual information
+ into the constants that the LU code expects.
+
+ """
+ if user_input:
+ if user_input.lower() == "default":
+ result_path = constants.VALUE_DEFAULT
+ elif user_input.lower() == "none":
+ result_path = constants.VALUE_NONE
+ else:
+ if not os.path.isabs(user_input):
+ raise errors.OpPrereqError("Path '%s' is not an absolute filename" %
+ user_input)
+ result_path = user_input
+ else:
+ result_path = constants.VALUE_DEFAULT
+
+ return result_path
+
+