-def _ConfirmOperation(inames, text, extra=""):
- """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.
-
- @type inames: list
- @param inames: the list of names that we display when
- we ask for confirmation
- @type text: str
- @param text: the operation that the user should confirm
- (e.g. I{shutdown} or I{startup})
- @rtype: boolean
- @return: True or False depending on user's confirmation.
-
- """
- count = len(inames)
- msg = ("The %s will operate on %d instances.\n%s"
- "Do you want to continue?" % (text, count, extra))
- 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(msg + affected, choices)
- return choice
-
-