Revision 25bd815c

b/lib/cli.py
161 161
  "VG_NAME_OPT",
162 162
  "YES_DOIT_OPT",
163 163
  # Generic functions for CLI programs
164
  "ConfirmOperation",
164 165
  "GenericMain",
165 166
  "GenericInstanceCreate",
166 167
  "GenericList",
......
2974 2975
  for key in sorted(actual):
2975 2976
    val = param_dict.get(key, "default (%s)" % actual[key])
2976 2977
    buf.write("%s- %s: %s\n" % (indent, key, val))
2978

  
2979

  
2980
def ConfirmOperation(names, list_type, text, extra=""):
2981
  """Ask the user to confirm an operation on a list of list_type.
2982

  
2983
  This function is used to request confirmation for doing an operation
2984
  on a given list of list_type.
2985

  
2986
  @type names: list
2987
  @param names: the list of names that we display when
2988
      we ask for confirmation
2989
  @type list_type: str
2990
  @param list_type: Human readable name for elements in the list (e.g. nodes)
2991
  @type text: str
2992
  @param text: the operation that the user should confirm
2993
  @rtype: boolean
2994
  @return: True or False depending on user's confirmation.
2995

  
2996
  """
2997
  count = len(names)
2998
  msg = ("The %s will operate on %d %s.\n%s"
2999
         "Do you want to continue?" % (text, count, list_type, extra))
3000
  affected = (("\nAffected %s:\n" % list_type) +
3001
              "\n".join(["  %s" % name for name in names]))
3002

  
3003
  choices = [("y", True, "Yes, execute the %s" % text),
3004
             ("n", False, "No, abort the %s" % text)]
3005

  
3006
  if count > 20:
3007
    choices.insert(1, ("v", "v", "View the list of affected %s" % list_type))
3008
    question = msg
3009
  else:
3010
    question = msg + affected
3011

  
3012
  choice = AskUser(question, choices)
3013
  if choice == "v":
3014
    choices.pop(1)
3015
    choice = AskUser(msg + affected, choices)
3016
  return choice
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