Revision 25bd815c lib/client/gnt_instance.py

b/lib/client/gnt_instance.py
142 142
  return inames
143 143

  
144 144

  
145
def _ConfirmOperation(inames, text, extra=""):
146
  """Ask the user to confirm an operation on a list of instances.
147

  
148
  This function is used to request confirmation for doing an operation
149
  on a given list of instances.
150

  
151
  @type inames: list
152
  @param inames: the list of names that we display when
153
      we ask for confirmation
154
  @type text: str
155
  @param text: the operation that the user should confirm
156
      (e.g. I{shutdown} or I{startup})
157
  @rtype: boolean
158
  @return: True or False depending on user's confirmation.
159

  
160
  """
161
  count = len(inames)
162
  msg = ("The %s will operate on %d instances.\n%s"
163
         "Do you want to continue?" % (text, count, extra))
164
  affected = ("\nAffected instances:\n" +
165
              "\n".join(["  %s" % name for name in inames]))
166

  
167
  choices = [('y', True, 'Yes, execute the %s' % text),
168
             ('n', False, 'No, abort the %s' % text)]
169

  
170
  if count > 20:
171
    choices.insert(1, ('v', 'v', 'View the list of affected instances'))
172
    ask = msg
173
  else:
174
    ask = msg + affected
175

  
176
  choice = AskUser(ask, choices)
177
  if choice == 'v':
178
    choices.pop(1)
179
    choice = AskUser(msg + affected, choices)
180
  return choice
181

  
182

  
183 145
def _EnsureInstancesExist(client, names):
184 146
  """Check for and ensure the given instance names exist.
185 147

  
......
221 183
                                 " any instances", errors.ECODE_INVAL)
222 184
    multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1
223 185
    if not (opts.force_multi or not multi_on
224
            or _ConfirmOperation(inames, operation)):
186
            or ConfirmOperation(inames, "instances", operation)):
225 187
      return 1
226 188
    jex = JobExecutor(verbose=multi_on, cl=cl, opts=opts)
227 189
    for name in inames:
......
491 453
  if multi_on:
492 454
    warn_msg = "Note: this will remove *all* data for the below instances!\n"
493 455
    if not (opts.force_multi or
494
            _ConfirmOperation(inames, "reinstall", extra=warn_msg)):
456
            ConfirmOperation(inames, "instances", "reinstall", extra=warn_msg)):
495 457
      return 1
496 458
  else:
497 459
    if not (opts.force or opts.force_multi):

Also available in: Unified diff