Revision 312ac745
b/man/gnt-instance.sgml | ||
---|---|---|
424 | 424 |
<cmdsynopsis> |
425 | 425 |
<command>startup</command> |
426 | 426 |
<arg>--extra=<replaceable>PARAMS</replaceable></arg> |
427 |
<arg choice="req"><replaceable>instance</replaceable></arg> |
|
427 |
<sbr> |
|
428 |
<group choice="opt"> |
|
429 |
<arg>--instance</arg> |
|
430 |
<arg>--node</arg> |
|
431 |
<arg>--primary</arg> |
|
432 |
<arg>--secondary</arg> |
|
433 |
<arg>--all</arg> |
|
434 |
</group> |
|
435 |
<sbr> |
|
436 |
<arg choice="opt" |
|
437 |
rep="repeat"><replaceable>name</replaceable></arg> |
|
428 | 438 |
</cmdsynopsis> |
429 | 439 |
|
430 | 440 |
<para> |
431 |
Starts an instance. The node where to start the instance is |
|
432 |
taken from the configuration. |
|
441 |
Starts one or more instances, depending on the |
|
442 |
<option>--by-*</option> mode. The four available modes are: |
|
443 |
<variablelist> |
|
444 |
<varlistentry> |
|
445 |
<term><option>--instance</option></term> |
|
446 |
<listitem> |
|
447 |
<simpara>will start the instances given as arguments |
|
448 |
(at least one argument required); this is the default |
|
449 |
selection</simpara> |
|
450 |
</listitem> |
|
451 |
</varlistentry> |
|
452 |
<varlistentry> |
|
453 |
<term>--node</term> |
|
454 |
<listitem> |
|
455 |
<simpara>will start the instances who have the given |
|
456 |
node as either primary or secondary</simpara> |
|
457 |
</listitem> |
|
458 |
</varlistentry> |
|
459 |
<varlistentry> |
|
460 |
<term><option>--primary</option></term> |
|
461 |
<listitem> |
|
462 |
<simpara>will start all instances whose primary node |
|
463 |
is in the list of nodes passed as arguments (at least |
|
464 |
one node required)</simpara> |
|
465 |
</listitem> |
|
466 |
</varlistentry> |
|
467 |
<varlistentry> |
|
468 |
<term><option>--secondary</option></term> |
|
469 |
<listitem> |
|
470 |
<simpara>will start all instances whose secondary node |
|
471 |
is in the list of nodes passed as arguments (at least |
|
472 |
one node required)</simpara> |
|
473 |
</listitem> |
|
474 |
</varlistentry> |
|
475 |
<varlistentry> |
|
476 |
<term>--all</term> |
|
477 |
<listitem> |
|
478 |
<simpara>will start all instances in the cluster (no |
|
479 |
arguments accepted)</simpara> |
|
480 |
</listitem> |
|
481 |
</varlistentry> |
|
482 |
</variablelist> |
|
483 |
</para> |
|
484 |
|
|
485 |
<para> |
|
486 |
Note that although you can pass more than one |
|
487 |
<option>--by-</option> option, the last one wins, so in |
|
488 |
order to guarantee the desired result, don't pass more than |
|
489 |
one such option. |
|
433 | 490 |
</para> |
434 | 491 |
|
435 | 492 |
<para> |
... | ... | |
446 | 503 |
<screen> |
447 | 504 |
# gnt-instance start instance1.example.com |
448 | 505 |
# gnt-instance start --extra single test1.example.com |
506 |
# gnt-instance start --by-node node1.example.com node2.example.com |
|
507 |
# gnt-instance start --by-cluster |
|
449 | 508 |
</screen> |
450 | 509 |
</para> |
451 | 510 |
</refsect3> |
... | ... | |
455 | 514 |
|
456 | 515 |
<cmdsynopsis> |
457 | 516 |
<command>shutdown</command> |
458 |
<arg choice="req"><replaceable>instance</replaceable></arg> |
|
517 |
<sbr> |
|
518 |
<group choice="opt"> |
|
519 |
<arg>--instance</arg> |
|
520 |
<arg>--node</arg> |
|
521 |
<arg>--primary</arg> |
|
522 |
<arg>--secondary</arg> |
|
523 |
<arg>--all</arg> |
|
524 |
</group> |
|
525 |
<sbr> |
|
526 |
|
|
527 |
<arg choice="opt" |
|
528 |
rep="repeat"><replaceable>name</replaceable></arg> |
|
459 | 529 |
</cmdsynopsis> |
460 | 530 |
|
461 | 531 |
<para> |
462 |
Stops the instance. If the instance cannot be cleanly |
|
463 |
stopped during a hardcoded interval (currently 2 minutes), |
|
464 |
it will forcibly stop the instance (equivalent to switching |
|
465 |
off the power on a physical machine). |
|
532 |
Stops one or more instances. If the instance cannot be |
|
533 |
cleanly stopped during a hardcoded interval (currently 2 |
|
534 |
minutes), it will forcibly stop the instance (equivalent to |
|
535 |
switching off the power on a physical machine). |
|
536 |
</para> |
|
537 |
|
|
538 |
<para> |
|
539 |
The <option>--instance</option>, <option>--node</option>, |
|
540 |
<option>--primary</option>, <option>--secondary</option> and |
|
541 |
<option>--all</option> options are similar as for the |
|
542 |
<command>startup</command> command and they influence the |
|
543 |
actual instances being shutodnw. |
|
466 | 544 |
</para> |
467 | 545 |
|
468 | 546 |
<para> |
469 | 547 |
Example: |
470 | 548 |
<screen> |
471 | 549 |
# gnt-instance shutdown instance1.example.com |
550 |
# gnt-instance shutdown --by-cluster |
|
472 | 551 |
</screen> |
473 | 552 |
</para> |
474 | 553 |
</refsect3> |
b/scripts/gnt-instance | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import sys |
23 | 23 |
import os |
24 |
import itertools |
|
24 | 25 |
from optparse import make_option |
25 | 26 |
from cStringIO import StringIO |
26 | 27 |
|
... | ... | |
29 | 30 |
from ganeti import logger |
30 | 31 |
from ganeti import constants |
31 | 32 |
from ganeti import utils |
33 |
from ganeti import errors |
|
34 |
|
|
35 |
|
|
36 |
_SHUTDOWN_CLUSTER = "cluster" |
|
37 |
_SHUTDOWN_NODES_BOTH = "nodes" |
|
38 |
_SHUTDOWN_NODES_PRI = "nodes-pri" |
|
39 |
_SHUTDOWN_NODES_SEC = "nodes-sec" |
|
40 |
_SHUTDOWN_INSTANCES = "instances" |
|
41 |
|
|
42 |
def _ExpandMultiNames(mode, names): |
|
43 |
"""Expand the given names using the passed mode. |
|
44 |
|
|
45 |
Args: |
|
46 |
- mode, which can be one of _SHUTDOWN_CLUSTER, _SHUTDOWN_NODES_BOTH, |
|
47 |
_SHUTDOWN_NODES_PRI, _SHUTDOWN_NODES_SEC or _SHUTDOWN_INSTANCES |
|
48 |
- names, which is a list of names; for cluster, it must be empty, |
|
49 |
and for node and instance it must be a list of valid item |
|
50 |
names (short names are valid as usual, e.g. node1 instead of |
|
51 |
node1.example.com) |
|
52 |
|
|
53 |
For _SHUTDOWN_CLUSTER, all instances will be returned. For |
|
54 |
_SHUTDOWN_NODES_PRI/SEC, all instances having those nodes as |
|
55 |
primary/secondary will be shutdown. For _SHUTDOWN_NODES_BOTH, all |
|
56 |
instances having those nodes as either primary or secondary will be |
|
57 |
returned. For _SHUTDOWN_INSTANCES, the given instances will be |
|
58 |
returned. |
|
59 |
|
|
60 |
""" |
|
61 |
if mode == _SHUTDOWN_CLUSTER: |
|
62 |
if names: |
|
63 |
raise errors.OpPrereqError("Cluster filter mode takes no arguments") |
|
64 |
op = opcodes.OpQueryInstances(output_fields=["name"], names=[]) |
|
65 |
idata = SubmitOpCode(op) |
|
66 |
inames = [row[0] for row in idata] |
|
67 |
|
|
68 |
elif mode in (_SHUTDOWN_NODES_BOTH, |
|
69 |
_SHUTDOWN_NODES_PRI, |
|
70 |
_SHUTDOWN_NODES_SEC): |
|
71 |
if not names: |
|
72 |
raise errors.OpPrereqError("No node names passed") |
|
73 |
op = opcodes.OpQueryNodes(output_fields=["name", "pinst_list", |
|
74 |
"sinst_list"], names=names) |
|
75 |
ndata = SubmitOpCode(op) |
|
76 |
ipri = [row[1] for row in ndata] |
|
77 |
pri_names = list(itertools.chain(*ipri)) |
|
78 |
isec = [row[2] for row in ndata] |
|
79 |
sec_names = list(itertools.chain(*isec)) |
|
80 |
if mode == _SHUTDOWN_NODES_BOTH: |
|
81 |
inames = pri_names + sec_names |
|
82 |
elif mode == _SHUTDOWN_NODES_PRI: |
|
83 |
inames = pri_names |
|
84 |
elif mode == _SHUTDOWN_NODES_SEC: |
|
85 |
inames = sec_names |
|
86 |
else: |
|
87 |
raise errors.ProgrammerError("Unhandled shutdown type") |
|
88 |
|
|
89 |
elif mode == _SHUTDOWN_INSTANCES: |
|
90 |
if not names: |
|
91 |
raise errors.OpPrereqError("No instance names passed") |
|
92 |
op = opcodes.OpQueryInstances(output_fields=["name"], names=names) |
|
93 |
idata = SubmitOpCode(op) |
|
94 |
inames = [row[0] for row in idata] |
|
95 |
|
|
96 |
else: |
|
97 |
raise errors.OpPrereqError("Unknown mode '%s'" % mode) |
|
98 |
|
|
99 |
return inames |
|
32 | 100 |
|
33 | 101 |
|
34 | 102 |
def ListInstances(opts, args): |
... | ... | |
209 | 277 |
args - list containing a single element, the instance name |
210 | 278 |
|
211 | 279 |
""" |
212 |
instance_name = args[0] |
|
213 |
op = opcodes.OpStartupInstance(instance_name=instance_name, force=opts.force, |
|
214 |
extra_args=opts.extra_args) |
|
215 |
SubmitOpCode(op) |
|
280 |
if opts.multi_mode is None: |
|
281 |
opts.multi_mode = _SHUTDOWN_INSTANCES |
|
282 |
inames = _ExpandMultiNames(opts.multi_mode, args) |
|
283 |
multi_on = len(inames) > 1 |
|
284 |
for name in inames: |
|
285 |
op = opcodes.OpStartupInstance(instance_name=name, |
|
286 |
force=opts.force, |
|
287 |
extra_args=opts.extra_args) |
|
288 |
if multi_on: |
|
289 |
logger.ToStdout("Starting up %s" % name) |
|
290 |
SubmitOpCode(op) |
|
216 | 291 |
return 0 |
217 | 292 |
|
218 | 293 |
|
... | ... | |
224 | 299 |
args - list containing a single element, the instance name |
225 | 300 |
|
226 | 301 |
""" |
227 |
instance_name = args[0] |
|
228 |
op = opcodes.OpShutdownInstance(instance_name=instance_name) |
|
229 |
SubmitOpCode(op) |
|
302 |
if opts.multi_mode is None: |
|
303 |
opts.multi_mode = _SHUTDOWN_INSTANCES |
|
304 |
inames = _ExpandMultiNames(opts.multi_mode, args) |
|
305 |
multi_on = len(inames) > 1 |
|
306 |
for name in inames: |
|
307 |
op = opcodes.OpShutdownInstance(instance_name=name) |
|
308 |
if multi_on: |
|
309 |
logger.ToStdout("Shutting down %s" % name) |
|
310 |
SubmitOpCode(op) |
|
230 | 311 |
return 0 |
231 | 312 |
|
232 | 313 |
|
... | ... | |
455 | 536 |
os_opt = cli_option("-o", "--os-type", dest="os", help="What OS to run", |
456 | 537 |
metavar="<os>") |
457 | 538 |
|
539 |
# multi-instance selection options |
|
540 |
m_pri_node_opt = make_option("--primary", dest="multi_mode", |
|
541 |
help="Filter by nodes (primary only)", |
|
542 |
const=_SHUTDOWN_NODES_PRI, action="store_const") |
|
543 |
|
|
544 |
m_sec_node_opt = make_option("--secondary", dest="multi_mode", |
|
545 |
help="Filter by nodes (secondary only)", |
|
546 |
const=_SHUTDOWN_NODES_SEC, action="store_const") |
|
547 |
|
|
548 |
m_node_opt = make_option("--node", dest="multi_mode", |
|
549 |
help="Filter by nodes (primary and secondary)", |
|
550 |
const=_SHUTDOWN_NODES_BOTH, action="store_const") |
|
551 |
|
|
552 |
m_clust_opt = make_option("--all", dest="multi_mode", |
|
553 |
help="Select all instances in the cluster", |
|
554 |
const=_SHUTDOWN_CLUSTER, action="store_const") |
|
555 |
|
|
556 |
m_inst_opt = make_option("--instance", dest="multi_mode", |
|
557 |
help="Filter by instance name [default]", |
|
558 |
const=_SHUTDOWN_INSTANCES, action="store_const") |
|
559 |
|
|
560 |
|
|
458 | 561 |
# this is defined separately due to readability only |
459 | 562 |
add_opts = [ |
460 | 563 |
DEBUG_OPT, |
... | ... | |
555 | 658 |
default=None, type="string", metavar="<bridge>") |
556 | 659 |
], |
557 | 660 |
"<instance>", "Alters the parameters of an instance"), |
558 |
'shutdown': (ShutdownInstance, ARGS_ONE, [DEBUG_OPT], |
|
661 |
'shutdown': (ShutdownInstance, ARGS_ANY, |
|
662 |
[DEBUG_OPT, m_node_opt, m_pri_node_opt, m_sec_node_opt, |
|
663 |
m_clust_opt, m_inst_opt], |
|
559 | 664 |
"<instance>", "Stops an instance"), |
560 |
'startup': (StartupInstance, ARGS_ONE,
|
|
665 |
'startup': (StartupInstance, ARGS_ANY,
|
|
561 | 666 |
[DEBUG_OPT, FORCE_OPT, |
562 | 667 |
make_option("-e", "--extra", dest="extra_args", |
563 | 668 |
help="Extra arguments for the instance's kernel", |
564 | 669 |
default=None, type="string", metavar="<PARAMS>"), |
670 |
m_node_opt, m_pri_node_opt, m_sec_node_opt, |
|
671 |
m_clust_opt, m_inst_opt, |
|
565 | 672 |
], |
566 | 673 |
"<instance>", "Starts an instance"), |
567 | 674 |
'activate-disks': (ActivateDisks, ARGS_ONE, [DEBUG_OPT], |
Also available in: Unified diff