Revision 804a1e8e scripts/gnt-instance
b/scripts/gnt-instance | ||
---|---|---|
99 | 99 |
return inames |
100 | 100 |
|
101 | 101 |
|
102 |
def _ConfirmOperation(inames, text): |
|
103 |
"""Ask the user to confirm an operation on a list of instances. |
|
104 |
|
|
105 |
This function is used to request confirmation for doing an operation |
|
106 |
on a given list of instances. |
|
107 |
|
|
108 |
The inames argument is what the selection algorithm computed, and |
|
109 |
the text argument is the operation we should tell the user to |
|
110 |
confirm (e.g. 'shutdown' or 'startup'). |
|
111 |
|
|
112 |
Returns: boolean depending on user's confirmation. |
|
113 |
|
|
114 |
""" |
|
115 |
count = len(inames) |
|
116 |
msg = ("The %s will operate on %d instances.\n" |
|
117 |
"Do you want to continue?" % (text, count)) |
|
118 |
affected = ("\nAffected instances:\n" + |
|
119 |
"\n".join([" %s" % name for name in inames])) |
|
120 |
|
|
121 |
choices = [('y', True, 'Yes, execute the %s' % text), |
|
122 |
('n', False, 'No, abort the %s' % text)] |
|
123 |
|
|
124 |
if count > 20: |
|
125 |
choices.insert(1, ('v', 'v', 'View the list of affected instances')) |
|
126 |
ask = msg |
|
127 |
else: |
|
128 |
ask = msg + affected |
|
129 |
|
|
130 |
choice = AskUser(ask, choices) |
|
131 |
if choice == 'v': |
|
132 |
choices.pop(1) |
|
133 |
choice = AskUser(choices, msg + affected) |
|
134 |
return choice |
|
135 |
|
|
136 |
|
|
102 | 137 |
def ListInstances(opts, args): |
103 | 138 |
"""List nodes and their properties. |
104 | 139 |
|
... | ... | |
297 | 332 |
if opts.multi_mode is None: |
298 | 333 |
opts.multi_mode = _SHUTDOWN_INSTANCES |
299 | 334 |
inames = _ExpandMultiNames(opts.multi_mode, args) |
300 |
multi_on = len(inames) > 1 |
|
335 |
multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1 |
|
336 |
if not (opts.force_multi or not multi_on |
|
337 |
or _ConfirmOperation(inames, "startup")): |
|
338 |
return 1 |
|
301 | 339 |
for name in inames: |
302 | 340 |
op = opcodes.OpStartupInstance(instance_name=name, |
303 | 341 |
force=opts.force, |
... | ... | |
319 | 357 |
if opts.multi_mode is None: |
320 | 358 |
opts.multi_mode = _SHUTDOWN_INSTANCES |
321 | 359 |
inames = _ExpandMultiNames(opts.multi_mode, args) |
322 |
multi_on = len(inames) > 1 |
|
360 |
multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1 |
|
361 |
if not (opts.force_multi or not multi_on |
|
362 |
or _ConfirmOperation(inames, "shutdown")): |
|
363 |
return 1 |
|
323 | 364 |
for name in inames: |
324 | 365 |
op = opcodes.OpShutdownInstance(instance_name=name) |
325 | 366 |
if multi_on: |
... | ... | |
554 | 595 |
metavar="<os>") |
555 | 596 |
|
556 | 597 |
# multi-instance selection options |
598 |
m_force_multi = make_option("--force-multiple", dest="force_multi", |
|
599 |
help="Do not ask for confirmation when more than" |
|
600 |
" one instance is affected", |
|
601 |
action="store_true", default=False) |
|
602 |
|
|
557 | 603 |
m_pri_node_opt = make_option("--primary", dest="multi_mode", |
558 | 604 |
help="Filter by nodes (primary only)", |
559 | 605 |
const=_SHUTDOWN_NODES_PRI, action="store_const") |
... | ... | |
691 | 737 |
"<instance>", "Alters the parameters of an instance"), |
692 | 738 |
'shutdown': (ShutdownInstance, ARGS_ANY, |
693 | 739 |
[DEBUG_OPT, m_node_opt, m_pri_node_opt, m_sec_node_opt, |
694 |
m_clust_opt, m_inst_opt], |
|
740 |
m_clust_opt, m_inst_opt, m_force_multi],
|
|
695 | 741 |
"<instance>", "Stops an instance"), |
696 | 742 |
'startup': (StartupInstance, ARGS_ANY, |
697 |
[DEBUG_OPT, FORCE_OPT, |
|
743 |
[DEBUG_OPT, FORCE_OPT, m_force_multi,
|
|
698 | 744 |
make_option("-e", "--extra", dest="extra_args", |
699 | 745 |
help="Extra arguments for the instance's kernel", |
700 | 746 |
default=None, type="string", metavar="<PARAMS>"), |
Also available in: Unified diff