27 |
27 |
from ganeti import logger
|
28 |
28 |
from ganeti import utils
|
29 |
29 |
from ganeti import constants
|
|
30 |
from ganeti import errors
|
30 |
31 |
|
31 |
32 |
|
32 |
33 |
def AddNode(opts, args):
|
... | ... | |
93 |
94 |
return 0
|
94 |
95 |
|
95 |
96 |
|
|
97 |
def FailoverNode(opts, args):
|
|
98 |
"""Failover all primary instance on a node.
|
|
99 |
|
|
100 |
"""
|
|
101 |
force = opts.force
|
|
102 |
selected_fields = ["name", "pinst_list"]
|
|
103 |
|
|
104 |
op = opcodes.OpQueryNodes(output_fields=selected_fields, names=args)
|
|
105 |
result = SubmitOpCode(op)
|
|
106 |
node, pinst = result[0]
|
|
107 |
|
|
108 |
if not pinst:
|
|
109 |
logger.ToStderr("No primary instances on node %s, exiting." % node)
|
|
110 |
return 0
|
|
111 |
|
|
112 |
pinst = utils.NiceSort(pinst)
|
|
113 |
|
|
114 |
retcode = 0
|
|
115 |
|
|
116 |
if not force and not AskUser("Fail over instance(s) %s?" %
|
|
117 |
(",".join("'%s'" % name for name in pinst))):
|
|
118 |
return 2
|
|
119 |
|
|
120 |
good_cnt = bad_cnt = 0
|
|
121 |
for iname in pinst:
|
|
122 |
op = opcodes.OpFailoverInstance(instance_name=iname,
|
|
123 |
ignore_consistency=opts.ignore_consistency)
|
|
124 |
try:
|
|
125 |
logger.ToStdout("Failing over instance %s" % iname)
|
|
126 |
SubmitOpCode(op)
|
|
127 |
logger.ToStdout("Instance %s has been failed over" % iname)
|
|
128 |
good_cnt += 1
|
|
129 |
except errors.GenericError, err:
|
|
130 |
nret, msg = FormatError(err)
|
|
131 |
retcode |= nret
|
|
132 |
logger.ToStderr("Error failing over instance %s: %s" % (iname, msg))
|
|
133 |
bad_cnt += 1
|
|
134 |
|
|
135 |
if retcode == 0:
|
|
136 |
logger.ToStdout("All %d instance(s) failed over successfully." % good_cnt)
|
|
137 |
else:
|
|
138 |
logger.ToStdout("There were errors during the failover:\n"
|
|
139 |
"%d error(s) out of %d instance(s)." %
|
|
140 |
(bad_cnt, good_cnt + bad_cnt))
|
|
141 |
return retcode
|
|
142 |
|
|
143 |
|
96 |
144 |
def ShowNodeConfig(opts, args):
|
97 |
145 |
"""Show node information.
|
98 |
146 |
|
... | ... | |
172 |
220 |
help="Specify the secondary ip for the node",
|
173 |
221 |
metavar="ADDRESS", default=None),],
|
174 |
222 |
"<node_name>", "Add a node to the cluster"),
|
|
223 |
'failover': (FailoverNode, ARGS_ONE,
|
|
224 |
[DEBUG_OPT, FORCE_OPT,
|
|
225 |
make_option("--ignore-consistency", dest="ignore_consistency",
|
|
226 |
action="store_true", default=False,
|
|
227 |
help="Ignore the consistency of the disks on"
|
|
228 |
" the secondary"),
|
|
229 |
],
|
|
230 |
"[-f] <node>",
|
|
231 |
"Stops the primary instances on a node and start them on their"
|
|
232 |
" secondary node (only for instances of type remote_raid1)"),
|
175 |
233 |
'info': (ShowNodeConfig, ARGS_ANY, [DEBUG_OPT],
|
176 |
234 |
"[<node_name>...]", "Show information about the node(s)"),
|
177 |
235 |
'list': (ListNodes, ARGS_NONE,
|