root / lib / client / gnt_cluster.py @ 60cc531d
History | View | Annotate | Download (69.1 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2006, 2007, 2010, 2011, 2012, 2013 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
"""Cluster related commands"""
|
22 |
|
23 |
# pylint: disable=W0401,W0613,W0614,C0103
|
24 |
# W0401: Wildcard import ganeti.cli
|
25 |
# W0613: Unused argument, since all functions follow the same API
|
26 |
# W0614: Unused import %s from wildcard import (since we need cli)
|
27 |
# C0103: Invalid name gnt-cluster
|
28 |
|
29 |
from cStringIO import StringIO |
30 |
import os |
31 |
import time |
32 |
import OpenSSL |
33 |
import itertools |
34 |
|
35 |
from ganeti.cli import * |
36 |
from ganeti import opcodes |
37 |
from ganeti import constants |
38 |
from ganeti import errors |
39 |
from ganeti import utils |
40 |
from ganeti import bootstrap |
41 |
from ganeti import ssh |
42 |
from ganeti import objects |
43 |
from ganeti import uidpool |
44 |
from ganeti import compat |
45 |
from ganeti import netutils |
46 |
from ganeti import ssconf |
47 |
from ganeti import pathutils |
48 |
from ganeti import serializer |
49 |
from ganeti import qlang |
50 |
|
51 |
|
52 |
ON_OPT = cli_option("--on", default=False, |
53 |
action="store_true", dest="on", |
54 |
help="Recover from an EPO")
|
55 |
|
56 |
GROUPS_OPT = cli_option("--groups", default=False, |
57 |
action="store_true", dest="groups", |
58 |
help="Arguments are node groups instead of nodes")
|
59 |
|
60 |
FORCE_FAILOVER = cli_option("--yes-do-it", dest="yes_do_it", |
61 |
help="Override interactive check for --no-voting",
|
62 |
default=False, action="store_true") |
63 |
|
64 |
FORCE_DISTRIBUTION = cli_option("--yes-do-it", dest="yes_do_it", |
65 |
help="Unconditionally distribute the"
|
66 |
" configuration, even if the queue"
|
67 |
" is drained",
|
68 |
default=False, action="store_true") |
69 |
|
70 |
TO_OPT = cli_option("--to", default=None, type="string", |
71 |
help="The Ganeti version to upgrade to")
|
72 |
|
73 |
RESUME_OPT = cli_option("--resume", default=False, action="store_true", |
74 |
help="Resume any pending Ganeti upgrades")
|
75 |
|
76 |
_EPO_PING_INTERVAL = 30 # 30 seconds between pings |
77 |
_EPO_PING_TIMEOUT = 1 # 1 second |
78 |
_EPO_REACHABLE_TIMEOUT = 15 * 60 # 15 minutes |
79 |
|
80 |
|
81 |
def _InitEnabledDiskTemplates(opts): |
82 |
"""Initialize the list of enabled disk templates.
|
83 |
|
84 |
"""
|
85 |
if opts.enabled_disk_templates:
|
86 |
return opts.enabled_disk_templates.split(",") |
87 |
else:
|
88 |
return constants.DEFAULT_ENABLED_DISK_TEMPLATES
|
89 |
|
90 |
|
91 |
def _InitVgName(opts, enabled_disk_templates): |
92 |
"""Initialize the volume group name.
|
93 |
|
94 |
@type enabled_disk_templates: list of strings
|
95 |
@param enabled_disk_templates: cluster-wide enabled disk templates
|
96 |
|
97 |
"""
|
98 |
vg_name = None
|
99 |
if opts.vg_name is not None: |
100 |
vg_name = opts.vg_name |
101 |
if vg_name:
|
102 |
if not utils.IsLvmEnabled(enabled_disk_templates): |
103 |
ToStdout("You specified a volume group with --vg-name, but you did not"
|
104 |
" enable any disk template that uses lvm.")
|
105 |
elif utils.IsLvmEnabled(enabled_disk_templates):
|
106 |
raise errors.OpPrereqError(
|
107 |
"LVM disk templates are enabled, but vg name not set.")
|
108 |
elif utils.IsLvmEnabled(enabled_disk_templates):
|
109 |
vg_name = constants.DEFAULT_VG |
110 |
return vg_name
|
111 |
|
112 |
|
113 |
def _InitDrbdHelper(opts, enabled_disk_templates): |
114 |
"""Initialize the DRBD usermode helper.
|
115 |
|
116 |
"""
|
117 |
drbd_enabled = constants.DT_DRBD8 in enabled_disk_templates
|
118 |
|
119 |
if not drbd_enabled and opts.drbd_helper is not None: |
120 |
ToStdout("Note: You specified a DRBD usermode helper, while DRBD storage"
|
121 |
" is not enabled.")
|
122 |
|
123 |
if drbd_enabled:
|
124 |
if opts.drbd_helper is None: |
125 |
return constants.DEFAULT_DRBD_HELPER
|
126 |
if opts.drbd_helper == '': |
127 |
raise errors.OpPrereqError(
|
128 |
"Unsetting the drbd usermode helper while enabling DRBD is not"
|
129 |
" allowed.")
|
130 |
|
131 |
return opts.drbd_helper
|
132 |
|
133 |
|
134 |
@UsesRPC
|
135 |
def InitCluster(opts, args): |
136 |
"""Initialize the cluster.
|
137 |
|
138 |
@param opts: the command line options selected by the user
|
139 |
@type args: list
|
140 |
@param args: should contain only one element, the desired
|
141 |
cluster name
|
142 |
@rtype: int
|
143 |
@return: the desired exit code
|
144 |
|
145 |
"""
|
146 |
enabled_disk_templates = _InitEnabledDiskTemplates(opts) |
147 |
|
148 |
try:
|
149 |
vg_name = _InitVgName(opts, enabled_disk_templates) |
150 |
drbd_helper = _InitDrbdHelper(opts, enabled_disk_templates) |
151 |
except errors.OpPrereqError, e:
|
152 |
ToStderr(str(e))
|
153 |
return 1 |
154 |
|
155 |
master_netdev = opts.master_netdev |
156 |
if master_netdev is None: |
157 |
nic_mode = opts.nicparams.get(constants.NIC_MODE, None)
|
158 |
if not nic_mode: |
159 |
# default case, use bridging
|
160 |
master_netdev = constants.DEFAULT_BRIDGE |
161 |
elif nic_mode == constants.NIC_MODE_OVS:
|
162 |
# default ovs is different from default bridge
|
163 |
master_netdev = constants.DEFAULT_OVS |
164 |
opts.nicparams[constants.NIC_LINK] = constants.DEFAULT_OVS |
165 |
|
166 |
hvlist = opts.enabled_hypervisors |
167 |
if hvlist is None: |
168 |
hvlist = constants.DEFAULT_ENABLED_HYPERVISOR |
169 |
hvlist = hvlist.split(",")
|
170 |
|
171 |
hvparams = dict(opts.hvparams)
|
172 |
beparams = opts.beparams |
173 |
nicparams = opts.nicparams |
174 |
|
175 |
diskparams = dict(opts.diskparams)
|
176 |
|
177 |
# check the disk template types here, as we cannot rely on the type check done
|
178 |
# by the opcode parameter types
|
179 |
diskparams_keys = set(diskparams.keys())
|
180 |
if not (diskparams_keys <= constants.DISK_TEMPLATES): |
181 |
unknown = utils.NiceSort(diskparams_keys - constants.DISK_TEMPLATES) |
182 |
ToStderr("Disk templates unknown: %s" % utils.CommaJoin(unknown))
|
183 |
return 1 |
184 |
|
185 |
# prepare beparams dict
|
186 |
beparams = objects.FillDict(constants.BEC_DEFAULTS, beparams) |
187 |
utils.ForceDictType(beparams, constants.BES_PARAMETER_COMPAT) |
188 |
|
189 |
# prepare nicparams dict
|
190 |
nicparams = objects.FillDict(constants.NICC_DEFAULTS, nicparams) |
191 |
utils.ForceDictType(nicparams, constants.NICS_PARAMETER_TYPES) |
192 |
|
193 |
# prepare ndparams dict
|
194 |
if opts.ndparams is None: |
195 |
ndparams = dict(constants.NDC_DEFAULTS)
|
196 |
else:
|
197 |
ndparams = objects.FillDict(constants.NDC_DEFAULTS, opts.ndparams) |
198 |
utils.ForceDictType(ndparams, constants.NDS_PARAMETER_TYPES) |
199 |
|
200 |
# prepare hvparams dict
|
201 |
for hv in constants.HYPER_TYPES: |
202 |
if hv not in hvparams: |
203 |
hvparams[hv] = {} |
204 |
hvparams[hv] = objects.FillDict(constants.HVC_DEFAULTS[hv], hvparams[hv]) |
205 |
utils.ForceDictType(hvparams[hv], constants.HVS_PARAMETER_TYPES) |
206 |
|
207 |
# prepare diskparams dict
|
208 |
for templ in constants.DISK_TEMPLATES: |
209 |
if templ not in diskparams: |
210 |
diskparams[templ] = {} |
211 |
diskparams[templ] = objects.FillDict(constants.DISK_DT_DEFAULTS[templ], |
212 |
diskparams[templ]) |
213 |
utils.ForceDictType(diskparams[templ], constants.DISK_DT_TYPES) |
214 |
|
215 |
# prepare ipolicy dict
|
216 |
ipolicy = CreateIPolicyFromOpts( |
217 |
ispecs_mem_size=opts.ispecs_mem_size, |
218 |
ispecs_cpu_count=opts.ispecs_cpu_count, |
219 |
ispecs_disk_count=opts.ispecs_disk_count, |
220 |
ispecs_disk_size=opts.ispecs_disk_size, |
221 |
ispecs_nic_count=opts.ispecs_nic_count, |
222 |
minmax_ispecs=opts.ipolicy_bounds_specs, |
223 |
std_ispecs=opts.ipolicy_std_specs, |
224 |
ipolicy_disk_templates=opts.ipolicy_disk_templates, |
225 |
ipolicy_vcpu_ratio=opts.ipolicy_vcpu_ratio, |
226 |
ipolicy_spindle_ratio=opts.ipolicy_spindle_ratio, |
227 |
fill_all=True)
|
228 |
|
229 |
if opts.candidate_pool_size is None: |
230 |
opts.candidate_pool_size = constants.MASTER_POOL_SIZE_DEFAULT |
231 |
|
232 |
if opts.mac_prefix is None: |
233 |
opts.mac_prefix = constants.DEFAULT_MAC_PREFIX |
234 |
|
235 |
uid_pool = opts.uid_pool |
236 |
if uid_pool is not None: |
237 |
uid_pool = uidpool.ParseUidPool(uid_pool) |
238 |
|
239 |
if opts.prealloc_wipe_disks is None: |
240 |
opts.prealloc_wipe_disks = False
|
241 |
|
242 |
external_ip_setup_script = opts.use_external_mip_script |
243 |
if external_ip_setup_script is None: |
244 |
external_ip_setup_script = False
|
245 |
|
246 |
try:
|
247 |
primary_ip_version = int(opts.primary_ip_version)
|
248 |
except (ValueError, TypeError), err: |
249 |
ToStderr("Invalid primary ip version value: %s" % str(err)) |
250 |
return 1 |
251 |
|
252 |
master_netmask = opts.master_netmask |
253 |
try:
|
254 |
if master_netmask is not None: |
255 |
master_netmask = int(master_netmask)
|
256 |
except (ValueError, TypeError), err: |
257 |
ToStderr("Invalid master netmask value: %s" % str(err)) |
258 |
return 1 |
259 |
|
260 |
if opts.disk_state:
|
261 |
disk_state = utils.FlatToDict(opts.disk_state) |
262 |
else:
|
263 |
disk_state = {} |
264 |
|
265 |
hv_state = dict(opts.hv_state)
|
266 |
|
267 |
default_ialloc_params = opts.default_iallocator_params |
268 |
bootstrap.InitCluster(cluster_name=args[0],
|
269 |
secondary_ip=opts.secondary_ip, |
270 |
vg_name=vg_name, |
271 |
mac_prefix=opts.mac_prefix, |
272 |
master_netmask=master_netmask, |
273 |
master_netdev=master_netdev, |
274 |
file_storage_dir=opts.file_storage_dir, |
275 |
shared_file_storage_dir=opts.shared_file_storage_dir, |
276 |
gluster_storage_dir=opts.gluster_storage_dir, |
277 |
enabled_hypervisors=hvlist, |
278 |
hvparams=hvparams, |
279 |
beparams=beparams, |
280 |
nicparams=nicparams, |
281 |
ndparams=ndparams, |
282 |
diskparams=diskparams, |
283 |
ipolicy=ipolicy, |
284 |
candidate_pool_size=opts.candidate_pool_size, |
285 |
modify_etc_hosts=opts.modify_etc_hosts, |
286 |
modify_ssh_setup=opts.modify_ssh_setup, |
287 |
maintain_node_health=opts.maintain_node_health, |
288 |
drbd_helper=drbd_helper, |
289 |
uid_pool=uid_pool, |
290 |
default_iallocator=opts.default_iallocator, |
291 |
default_iallocator_params=default_ialloc_params, |
292 |
primary_ip_version=primary_ip_version, |
293 |
prealloc_wipe_disks=opts.prealloc_wipe_disks, |
294 |
use_external_mip_script=external_ip_setup_script, |
295 |
hv_state=hv_state, |
296 |
disk_state=disk_state, |
297 |
enabled_disk_templates=enabled_disk_templates, |
298 |
) |
299 |
op = opcodes.OpClusterPostInit() |
300 |
SubmitOpCode(op, opts=opts) |
301 |
return 0 |
302 |
|
303 |
|
304 |
@UsesRPC
|
305 |
def DestroyCluster(opts, args): |
306 |
"""Destroy the cluster.
|
307 |
|
308 |
@param opts: the command line options selected by the user
|
309 |
@type args: list
|
310 |
@param args: should be an empty list
|
311 |
@rtype: int
|
312 |
@return: the desired exit code
|
313 |
|
314 |
"""
|
315 |
if not opts.yes_do_it: |
316 |
ToStderr("Destroying a cluster is irreversible. If you really want"
|
317 |
" destroy this cluster, supply the --yes-do-it option.")
|
318 |
return 1 |
319 |
|
320 |
op = opcodes.OpClusterDestroy() |
321 |
master_uuid = SubmitOpCode(op, opts=opts) |
322 |
# if we reached this, the opcode didn't fail; we can proceed to
|
323 |
# shutdown all the daemons
|
324 |
bootstrap.FinalizeClusterDestroy(master_uuid) |
325 |
return 0 |
326 |
|
327 |
|
328 |
def RenameCluster(opts, args): |
329 |
"""Rename the cluster.
|
330 |
|
331 |
@param opts: the command line options selected by the user
|
332 |
@type args: list
|
333 |
@param args: should contain only one element, the new cluster name
|
334 |
@rtype: int
|
335 |
@return: the desired exit code
|
336 |
|
337 |
"""
|
338 |
cl = GetClient() |
339 |
|
340 |
(cluster_name, ) = cl.QueryConfigValues(["cluster_name"])
|
341 |
|
342 |
new_name = args[0]
|
343 |
if not opts.force: |
344 |
usertext = ("This will rename the cluster from '%s' to '%s'. If you are"
|
345 |
" connected over the network to the cluster name, the"
|
346 |
" operation is very dangerous as the IP address will be"
|
347 |
" removed from the node and the change may not go through."
|
348 |
" Continue?") % (cluster_name, new_name)
|
349 |
if not AskUser(usertext): |
350 |
return 1 |
351 |
|
352 |
op = opcodes.OpClusterRename(name=new_name) |
353 |
result = SubmitOpCode(op, opts=opts, cl=cl) |
354 |
|
355 |
if result:
|
356 |
ToStdout("Cluster renamed from '%s' to '%s'", cluster_name, result)
|
357 |
|
358 |
return 0 |
359 |
|
360 |
|
361 |
def ActivateMasterIp(opts, args): |
362 |
"""Activates the master IP.
|
363 |
|
364 |
"""
|
365 |
op = opcodes.OpClusterActivateMasterIp() |
366 |
SubmitOpCode(op) |
367 |
return 0 |
368 |
|
369 |
|
370 |
def DeactivateMasterIp(opts, args): |
371 |
"""Deactivates the master IP.
|
372 |
|
373 |
"""
|
374 |
if not opts.confirm: |
375 |
usertext = ("This will disable the master IP. All the open connections to"
|
376 |
" the master IP will be closed. To reach the master you will"
|
377 |
" need to use its node IP."
|
378 |
" Continue?")
|
379 |
if not AskUser(usertext): |
380 |
return 1 |
381 |
|
382 |
op = opcodes.OpClusterDeactivateMasterIp() |
383 |
SubmitOpCode(op) |
384 |
return 0 |
385 |
|
386 |
|
387 |
def RedistributeConfig(opts, args): |
388 |
"""Forces push of the cluster configuration.
|
389 |
|
390 |
@param opts: the command line options selected by the user
|
391 |
@type args: list
|
392 |
@param args: empty list
|
393 |
@rtype: int
|
394 |
@return: the desired exit code
|
395 |
|
396 |
"""
|
397 |
op = opcodes.OpClusterRedistConf() |
398 |
if opts.yes_do_it:
|
399 |
SubmitOpCodeToDrainedQueue(op) |
400 |
else:
|
401 |
SubmitOrSend(op, opts) |
402 |
return 0 |
403 |
|
404 |
|
405 |
def ShowClusterVersion(opts, args): |
406 |
"""Write version of ganeti software to the standard output.
|
407 |
|
408 |
@param opts: the command line options selected by the user
|
409 |
@type args: list
|
410 |
@param args: should be an empty list
|
411 |
@rtype: int
|
412 |
@return: the desired exit code
|
413 |
|
414 |
"""
|
415 |
cl = GetClient(query=True)
|
416 |
result = cl.QueryClusterInfo() |
417 |
ToStdout("Software version: %s", result["software_version"]) |
418 |
ToStdout("Internode protocol: %s", result["protocol_version"]) |
419 |
ToStdout("Configuration format: %s", result["config_version"]) |
420 |
ToStdout("OS api version: %s", result["os_api_version"]) |
421 |
ToStdout("Export interface: %s", result["export_version"]) |
422 |
ToStdout("VCS version: %s", result["vcs_version"]) |
423 |
return 0 |
424 |
|
425 |
|
426 |
def ShowClusterMaster(opts, args): |
427 |
"""Write name of master node to the standard output.
|
428 |
|
429 |
@param opts: the command line options selected by the user
|
430 |
@type args: list
|
431 |
@param args: should be an empty list
|
432 |
@rtype: int
|
433 |
@return: the desired exit code
|
434 |
|
435 |
"""
|
436 |
master = bootstrap.GetMaster() |
437 |
ToStdout(master) |
438 |
return 0 |
439 |
|
440 |
|
441 |
def _FormatGroupedParams(paramsdict, roman=False): |
442 |
"""Format Grouped parameters (be, nic, disk) by group.
|
443 |
|
444 |
@type paramsdict: dict of dicts
|
445 |
@param paramsdict: {group: {param: value, ...}, ...}
|
446 |
@rtype: dict of dicts
|
447 |
@return: copy of the input dictionaries with strings as values
|
448 |
|
449 |
"""
|
450 |
ret = {} |
451 |
for (item, val) in paramsdict.items(): |
452 |
if isinstance(val, dict): |
453 |
ret[item] = _FormatGroupedParams(val, roman=roman) |
454 |
elif roman and isinstance(val, int): |
455 |
ret[item] = compat.TryToRoman(val) |
456 |
else:
|
457 |
ret[item] = str(val)
|
458 |
return ret
|
459 |
|
460 |
|
461 |
def ShowClusterConfig(opts, args): |
462 |
"""Shows cluster information.
|
463 |
|
464 |
@param opts: the command line options selected by the user
|
465 |
@type args: list
|
466 |
@param args: should be an empty list
|
467 |
@rtype: int
|
468 |
@return: the desired exit code
|
469 |
|
470 |
"""
|
471 |
cl = GetClient(query=True)
|
472 |
result = cl.QueryClusterInfo() |
473 |
|
474 |
if result["tags"]: |
475 |
tags = utils.CommaJoin(utils.NiceSort(result["tags"]))
|
476 |
else:
|
477 |
tags = "(none)"
|
478 |
if result["reserved_lvs"]: |
479 |
reserved_lvs = utils.CommaJoin(result["reserved_lvs"])
|
480 |
else:
|
481 |
reserved_lvs = "(none)"
|
482 |
|
483 |
enabled_hv = result["enabled_hypervisors"]
|
484 |
hvparams = dict((k, v) for k, v in result["hvparams"].iteritems() |
485 |
if k in enabled_hv) |
486 |
|
487 |
info = [ |
488 |
("Cluster name", result["name"]), |
489 |
("Cluster UUID", result["uuid"]), |
490 |
|
491 |
("Creation time", utils.FormatTime(result["ctime"])), |
492 |
("Modification time", utils.FormatTime(result["mtime"])), |
493 |
|
494 |
("Master node", result["master"]), |
495 |
|
496 |
("Architecture (this node)",
|
497 |
"%s (%s)" % (result["architecture"][0], result["architecture"][1])), |
498 |
|
499 |
("Tags", tags),
|
500 |
|
501 |
("Default hypervisor", result["default_hypervisor"]), |
502 |
("Enabled hypervisors", utils.CommaJoin(enabled_hv)),
|
503 |
|
504 |
("Hypervisor parameters", _FormatGroupedParams(hvparams)),
|
505 |
|
506 |
("OS-specific hypervisor parameters",
|
507 |
_FormatGroupedParams(result["os_hvp"])),
|
508 |
|
509 |
("OS parameters", _FormatGroupedParams(result["osparams"])), |
510 |
|
511 |
("Hidden OSes", utils.CommaJoin(result["hidden_os"])), |
512 |
("Blacklisted OSes", utils.CommaJoin(result["blacklisted_os"])), |
513 |
|
514 |
("Cluster parameters", [
|
515 |
("candidate pool size",
|
516 |
compat.TryToRoman(result["candidate_pool_size"],
|
517 |
convert=opts.roman_integers)), |
518 |
("master netdev", result["master_netdev"]), |
519 |
("master netmask", result["master_netmask"]), |
520 |
("use external master IP address setup script",
|
521 |
result["use_external_mip_script"]),
|
522 |
("lvm volume group", result["volume_group_name"]), |
523 |
("lvm reserved volumes", reserved_lvs),
|
524 |
("drbd usermode helper", result["drbd_usermode_helper"]), |
525 |
("file storage path", result["file_storage_dir"]), |
526 |
("shared file storage path", result["shared_file_storage_dir"]), |
527 |
("gluster storage path", result["gluster_storage_dir"]), |
528 |
("maintenance of node health", result["maintain_node_health"]), |
529 |
("uid pool", uidpool.FormatUidPool(result["uid_pool"])), |
530 |
("default instance allocator", result["default_iallocator"]), |
531 |
("default instance allocator parameters",
|
532 |
result["default_iallocator_params"]),
|
533 |
("primary ip version", result["primary_ip_version"]), |
534 |
("preallocation wipe disks", result["prealloc_wipe_disks"]), |
535 |
("OS search path", utils.CommaJoin(pathutils.OS_SEARCH_PATH)),
|
536 |
("ExtStorage Providers search path",
|
537 |
utils.CommaJoin(pathutils.ES_SEARCH_PATH)), |
538 |
("enabled disk templates",
|
539 |
utils.CommaJoin(result["enabled_disk_templates"])),
|
540 |
]), |
541 |
|
542 |
("Default node parameters",
|
543 |
_FormatGroupedParams(result["ndparams"], roman=opts.roman_integers)),
|
544 |
|
545 |
("Default instance parameters",
|
546 |
_FormatGroupedParams(result["beparams"], roman=opts.roman_integers)),
|
547 |
|
548 |
("Default nic parameters",
|
549 |
_FormatGroupedParams(result["nicparams"], roman=opts.roman_integers)),
|
550 |
|
551 |
("Default disk parameters",
|
552 |
_FormatGroupedParams(result["diskparams"], roman=opts.roman_integers)),
|
553 |
|
554 |
("Instance policy - limits for instances",
|
555 |
FormatPolicyInfo(result["ipolicy"], None, True)), |
556 |
] |
557 |
|
558 |
PrintGenericInfo(info) |
559 |
return 0 |
560 |
|
561 |
|
562 |
def ClusterCopyFile(opts, args): |
563 |
"""Copy a file from master to some nodes.
|
564 |
|
565 |
@param opts: the command line options selected by the user
|
566 |
@type args: list
|
567 |
@param args: should contain only one element, the path of
|
568 |
the file to be copied
|
569 |
@rtype: int
|
570 |
@return: the desired exit code
|
571 |
|
572 |
"""
|
573 |
filename = args[0]
|
574 |
if not os.path.exists(filename): |
575 |
raise errors.OpPrereqError("No such filename '%s'" % filename, |
576 |
errors.ECODE_INVAL) |
577 |
|
578 |
cl = GetClient() |
579 |
qcl = GetClient(query=True)
|
580 |
try:
|
581 |
cluster_name = cl.QueryConfigValues(["cluster_name"])[0] |
582 |
|
583 |
results = GetOnlineNodes(nodes=opts.nodes, cl=qcl, filter_master=True,
|
584 |
secondary_ips=opts.use_replication_network, |
585 |
nodegroup=opts.nodegroup) |
586 |
ports = GetNodesSshPorts(opts.nodes, qcl) |
587 |
finally:
|
588 |
cl.Close() |
589 |
qcl.Close() |
590 |
|
591 |
srun = ssh.SshRunner(cluster_name) |
592 |
for (node, port) in zip(results, ports): |
593 |
if not srun.CopyFileToNode(node, port, filename): |
594 |
ToStderr("Copy of file %s to node %s:%d failed", filename, node, port)
|
595 |
|
596 |
return 0 |
597 |
|
598 |
|
599 |
def RunClusterCommand(opts, args): |
600 |
"""Run a command on some nodes.
|
601 |
|
602 |
@param opts: the command line options selected by the user
|
603 |
@type args: list
|
604 |
@param args: should contain the command to be run and its arguments
|
605 |
@rtype: int
|
606 |
@return: the desired exit code
|
607 |
|
608 |
"""
|
609 |
cl = GetClient() |
610 |
qcl = GetClient(query=True)
|
611 |
|
612 |
command = " ".join(args)
|
613 |
|
614 |
nodes = GetOnlineNodes(nodes=opts.nodes, cl=qcl, nodegroup=opts.nodegroup) |
615 |
ports = GetNodesSshPorts(nodes, qcl) |
616 |
|
617 |
cluster_name, master_node = cl.QueryConfigValues(["cluster_name",
|
618 |
"master_node"])
|
619 |
|
620 |
srun = ssh.SshRunner(cluster_name=cluster_name) |
621 |
|
622 |
# Make sure master node is at list end
|
623 |
if master_node in nodes: |
624 |
nodes.remove(master_node) |
625 |
nodes.append(master_node) |
626 |
|
627 |
for (name, port) in zip(nodes, ports): |
628 |
result = srun.Run(name, constants.SSH_LOGIN_USER, command, port=port) |
629 |
|
630 |
if opts.failure_only and result.exit_code == constants.EXIT_SUCCESS: |
631 |
# Do not output anything for successful commands
|
632 |
continue
|
633 |
|
634 |
ToStdout("------------------------------------------------")
|
635 |
if opts.show_machine_names:
|
636 |
for line in result.output.splitlines(): |
637 |
ToStdout("%s: %s", name, line)
|
638 |
else:
|
639 |
ToStdout("node: %s", name)
|
640 |
ToStdout("%s", result.output)
|
641 |
ToStdout("return code = %s", result.exit_code)
|
642 |
|
643 |
return 0 |
644 |
|
645 |
|
646 |
def VerifyCluster(opts, args): |
647 |
"""Verify integrity of cluster, performing various test on nodes.
|
648 |
|
649 |
@param opts: the command line options selected by the user
|
650 |
@type args: list
|
651 |
@param args: should be an empty list
|
652 |
@rtype: int
|
653 |
@return: the desired exit code
|
654 |
|
655 |
"""
|
656 |
skip_checks = [] |
657 |
|
658 |
if opts.skip_nplusone_mem:
|
659 |
skip_checks.append(constants.VERIFY_NPLUSONE_MEM) |
660 |
|
661 |
cl = GetClient() |
662 |
|
663 |
op = opcodes.OpClusterVerify(verbose=opts.verbose, |
664 |
error_codes=opts.error_codes, |
665 |
debug_simulate_errors=opts.simulate_errors, |
666 |
skip_checks=skip_checks, |
667 |
ignore_errors=opts.ignore_errors, |
668 |
group_name=opts.nodegroup) |
669 |
result = SubmitOpCode(op, cl=cl, opts=opts) |
670 |
|
671 |
# Keep track of submitted jobs
|
672 |
jex = JobExecutor(cl=cl, opts=opts) |
673 |
|
674 |
for (status, job_id) in result[constants.JOB_IDS_KEY]: |
675 |
jex.AddJobId(None, status, job_id)
|
676 |
|
677 |
results = jex.GetResults() |
678 |
|
679 |
(bad_jobs, bad_results) = \ |
680 |
map(len, |
681 |
# Convert iterators to lists
|
682 |
map(list, |
683 |
# Count errors
|
684 |
map(compat.partial(itertools.ifilterfalse, bool), |
685 |
# Convert result to booleans in a tuple
|
686 |
zip(*((job_success, len(op_results) == 1 and op_results[0]) |
687 |
for (job_success, op_results) in results))))) |
688 |
|
689 |
if bad_jobs == 0 and bad_results == 0: |
690 |
rcode = constants.EXIT_SUCCESS |
691 |
else:
|
692 |
rcode = constants.EXIT_FAILURE |
693 |
if bad_jobs > 0: |
694 |
ToStdout("%s job(s) failed while verifying the cluster.", bad_jobs)
|
695 |
|
696 |
return rcode
|
697 |
|
698 |
|
699 |
def VerifyDisks(opts, args): |
700 |
"""Verify integrity of cluster disks.
|
701 |
|
702 |
@param opts: the command line options selected by the user
|
703 |
@type args: list
|
704 |
@param args: should be an empty list
|
705 |
@rtype: int
|
706 |
@return: the desired exit code
|
707 |
|
708 |
"""
|
709 |
cl = GetClient() |
710 |
|
711 |
op = opcodes.OpClusterVerifyDisks() |
712 |
|
713 |
result = SubmitOpCode(op, cl=cl, opts=opts) |
714 |
|
715 |
# Keep track of submitted jobs
|
716 |
jex = JobExecutor(cl=cl, opts=opts) |
717 |
|
718 |
for (status, job_id) in result[constants.JOB_IDS_KEY]: |
719 |
jex.AddJobId(None, status, job_id)
|
720 |
|
721 |
retcode = constants.EXIT_SUCCESS |
722 |
|
723 |
for (status, result) in jex.GetResults(): |
724 |
if not status: |
725 |
ToStdout("Job failed: %s", result)
|
726 |
continue
|
727 |
|
728 |
((bad_nodes, instances, missing), ) = result |
729 |
|
730 |
for node, text in bad_nodes.items(): |
731 |
ToStdout("Error gathering data on node %s: %s",
|
732 |
node, utils.SafeEncode(text[-400:]))
|
733 |
retcode = constants.EXIT_FAILURE |
734 |
ToStdout("You need to fix these nodes first before fixing instances")
|
735 |
|
736 |
for iname in instances: |
737 |
if iname in missing: |
738 |
continue
|
739 |
op = opcodes.OpInstanceActivateDisks(instance_name=iname) |
740 |
try:
|
741 |
ToStdout("Activating disks for instance '%s'", iname)
|
742 |
SubmitOpCode(op, opts=opts, cl=cl) |
743 |
except errors.GenericError, err:
|
744 |
nret, msg = FormatError(err) |
745 |
retcode |= nret |
746 |
ToStderr("Error activating disks for instance %s: %s", iname, msg)
|
747 |
|
748 |
if missing:
|
749 |
for iname, ival in missing.iteritems(): |
750 |
all_missing = compat.all(x[0] in bad_nodes for x in ival) |
751 |
if all_missing:
|
752 |
ToStdout("Instance %s cannot be verified as it lives on"
|
753 |
" broken nodes", iname)
|
754 |
else:
|
755 |
ToStdout("Instance %s has missing logical volumes:", iname)
|
756 |
ival.sort() |
757 |
for node, vol in ival: |
758 |
if node in bad_nodes: |
759 |
ToStdout("\tbroken node %s /dev/%s", node, vol)
|
760 |
else:
|
761 |
ToStdout("\t%s /dev/%s", node, vol)
|
762 |
|
763 |
ToStdout("You need to replace or recreate disks for all the above"
|
764 |
" instances if this message persists after fixing broken nodes.")
|
765 |
retcode = constants.EXIT_FAILURE |
766 |
elif not instances: |
767 |
ToStdout("No disks need to be activated.")
|
768 |
|
769 |
return retcode
|
770 |
|
771 |
|
772 |
def RepairDiskSizes(opts, args): |
773 |
"""Verify sizes of cluster disks.
|
774 |
|
775 |
@param opts: the command line options selected by the user
|
776 |
@type args: list
|
777 |
@param args: optional list of instances to restrict check to
|
778 |
@rtype: int
|
779 |
@return: the desired exit code
|
780 |
|
781 |
"""
|
782 |
op = opcodes.OpClusterRepairDiskSizes(instances=args) |
783 |
SubmitOpCode(op, opts=opts) |
784 |
|
785 |
|
786 |
@UsesRPC
|
787 |
def MasterFailover(opts, args): |
788 |
"""Failover the master node.
|
789 |
|
790 |
This command, when run on a non-master node, will cause the current
|
791 |
master to cease being master, and the non-master to become new
|
792 |
master.
|
793 |
|
794 |
@param opts: the command line options selected by the user
|
795 |
@type args: list
|
796 |
@param args: should be an empty list
|
797 |
@rtype: int
|
798 |
@return: the desired exit code
|
799 |
|
800 |
"""
|
801 |
if opts.no_voting and not opts.yes_do_it: |
802 |
usertext = ("This will perform the failover even if most other nodes"
|
803 |
" are down, or if this node is outdated. This is dangerous"
|
804 |
" as it can lead to a non-consistent cluster. Check the"
|
805 |
" gnt-cluster(8) man page before proceeding. Continue?")
|
806 |
if not AskUser(usertext): |
807 |
return 1 |
808 |
|
809 |
return bootstrap.MasterFailover(no_voting=opts.no_voting)
|
810 |
|
811 |
|
812 |
def MasterPing(opts, args): |
813 |
"""Checks if the master is alive.
|
814 |
|
815 |
@param opts: the command line options selected by the user
|
816 |
@type args: list
|
817 |
@param args: should be an empty list
|
818 |
@rtype: int
|
819 |
@return: the desired exit code
|
820 |
|
821 |
"""
|
822 |
try:
|
823 |
cl = GetClient() |
824 |
cl.QueryClusterInfo() |
825 |
return 0 |
826 |
except Exception: # pylint: disable=W0703 |
827 |
return 1 |
828 |
|
829 |
|
830 |
def SearchTags(opts, args): |
831 |
"""Searches the tags on all the cluster.
|
832 |
|
833 |
@param opts: the command line options selected by the user
|
834 |
@type args: list
|
835 |
@param args: should contain only one element, the tag pattern
|
836 |
@rtype: int
|
837 |
@return: the desired exit code
|
838 |
|
839 |
"""
|
840 |
op = opcodes.OpTagsSearch(pattern=args[0])
|
841 |
result = SubmitOpCode(op, opts=opts) |
842 |
if not result: |
843 |
return 1 |
844 |
result = list(result)
|
845 |
result.sort() |
846 |
for path, tag in result: |
847 |
ToStdout("%s %s", path, tag)
|
848 |
|
849 |
|
850 |
def _ReadAndVerifyCert(cert_filename, verify_private_key=False): |
851 |
"""Reads and verifies an X509 certificate.
|
852 |
|
853 |
@type cert_filename: string
|
854 |
@param cert_filename: the path of the file containing the certificate to
|
855 |
verify encoded in PEM format
|
856 |
@type verify_private_key: bool
|
857 |
@param verify_private_key: whether to verify the private key in addition to
|
858 |
the public certificate
|
859 |
@rtype: string
|
860 |
@return: a string containing the PEM-encoded certificate.
|
861 |
|
862 |
"""
|
863 |
try:
|
864 |
pem = utils.ReadFile(cert_filename) |
865 |
except IOError, err: |
866 |
raise errors.X509CertError(cert_filename,
|
867 |
"Unable to read certificate: %s" % str(err)) |
868 |
|
869 |
try:
|
870 |
OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, pem) |
871 |
except Exception, err: |
872 |
raise errors.X509CertError(cert_filename,
|
873 |
"Unable to load certificate: %s" % str(err)) |
874 |
|
875 |
if verify_private_key:
|
876 |
try:
|
877 |
OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, pem) |
878 |
except Exception, err: |
879 |
raise errors.X509CertError(cert_filename,
|
880 |
"Unable to load private key: %s" % str(err)) |
881 |
|
882 |
return pem
|
883 |
|
884 |
|
885 |
def _RenewCrypto(new_cluster_cert, new_rapi_cert, # pylint: disable=R0911 |
886 |
rapi_cert_filename, new_spice_cert, spice_cert_filename, |
887 |
spice_cacert_filename, new_confd_hmac_key, new_cds, |
888 |
cds_filename, force): |
889 |
"""Renews cluster certificates, keys and secrets.
|
890 |
|
891 |
@type new_cluster_cert: bool
|
892 |
@param new_cluster_cert: Whether to generate a new cluster certificate
|
893 |
@type new_rapi_cert: bool
|
894 |
@param new_rapi_cert: Whether to generate a new RAPI certificate
|
895 |
@type rapi_cert_filename: string
|
896 |
@param rapi_cert_filename: Path to file containing new RAPI certificate
|
897 |
@type new_spice_cert: bool
|
898 |
@param new_spice_cert: Whether to generate a new SPICE certificate
|
899 |
@type spice_cert_filename: string
|
900 |
@param spice_cert_filename: Path to file containing new SPICE certificate
|
901 |
@type spice_cacert_filename: string
|
902 |
@param spice_cacert_filename: Path to file containing the certificate of the
|
903 |
CA that signed the SPICE certificate
|
904 |
@type new_confd_hmac_key: bool
|
905 |
@param new_confd_hmac_key: Whether to generate a new HMAC key
|
906 |
@type new_cds: bool
|
907 |
@param new_cds: Whether to generate a new cluster domain secret
|
908 |
@type cds_filename: string
|
909 |
@param cds_filename: Path to file containing new cluster domain secret
|
910 |
@type force: bool
|
911 |
@param force: Whether to ask user for confirmation
|
912 |
|
913 |
"""
|
914 |
if new_rapi_cert and rapi_cert_filename: |
915 |
ToStderr("Only one of the --new-rapi-certificate and --rapi-certificate"
|
916 |
" options can be specified at the same time.")
|
917 |
return 1 |
918 |
|
919 |
if new_cds and cds_filename: |
920 |
ToStderr("Only one of the --new-cluster-domain-secret and"
|
921 |
" --cluster-domain-secret options can be specified at"
|
922 |
" the same time.")
|
923 |
return 1 |
924 |
|
925 |
if new_spice_cert and (spice_cert_filename or spice_cacert_filename): |
926 |
ToStderr("When using --new-spice-certificate, the --spice-certificate"
|
927 |
" and --spice-ca-certificate must not be used.")
|
928 |
return 1 |
929 |
|
930 |
if bool(spice_cacert_filename) ^ bool(spice_cert_filename): |
931 |
ToStderr("Both --spice-certificate and --spice-ca-certificate must be"
|
932 |
" specified.")
|
933 |
return 1 |
934 |
|
935 |
rapi_cert_pem, spice_cert_pem, spice_cacert_pem = (None, None, None) |
936 |
try:
|
937 |
if rapi_cert_filename:
|
938 |
rapi_cert_pem = _ReadAndVerifyCert(rapi_cert_filename, True)
|
939 |
if spice_cert_filename:
|
940 |
spice_cert_pem = _ReadAndVerifyCert(spice_cert_filename, True)
|
941 |
spice_cacert_pem = _ReadAndVerifyCert(spice_cacert_filename) |
942 |
except errors.X509CertError, err:
|
943 |
ToStderr("Unable to load X509 certificate from %s: %s", err[0], err[1]) |
944 |
return 1 |
945 |
|
946 |
if cds_filename:
|
947 |
try:
|
948 |
cds = utils.ReadFile(cds_filename) |
949 |
except Exception, err: # pylint: disable=W0703 |
950 |
ToStderr("Can't load new cluster domain secret from %s: %s" %
|
951 |
(cds_filename, str(err)))
|
952 |
return 1 |
953 |
else:
|
954 |
cds = None
|
955 |
|
956 |
if not force: |
957 |
usertext = ("This requires all daemons on all nodes to be restarted and"
|
958 |
" may take some time. Continue?")
|
959 |
if not AskUser(usertext): |
960 |
return 1 |
961 |
|
962 |
def _RenewCryptoInner(ctx): |
963 |
ctx.feedback_fn("Updating certificates and keys")
|
964 |
# FIXME: add separate option for client certs
|
965 |
bootstrap.GenerateClusterCrypto(new_cluster_cert, |
966 |
new_rapi_cert, |
967 |
new_spice_cert, |
968 |
new_confd_hmac_key, |
969 |
new_cds, |
970 |
new_cluster_cert, |
971 |
rapi_cert_pem=rapi_cert_pem, |
972 |
spice_cert_pem=spice_cert_pem, |
973 |
spice_cacert_pem=spice_cacert_pem, |
974 |
cds=cds) |
975 |
|
976 |
files_to_copy = [] |
977 |
|
978 |
if new_cluster_cert:
|
979 |
files_to_copy.append(pathutils.NODED_CERT_FILE) |
980 |
|
981 |
if new_rapi_cert or rapi_cert_pem: |
982 |
files_to_copy.append(pathutils.RAPI_CERT_FILE) |
983 |
|
984 |
if new_spice_cert or spice_cert_pem: |
985 |
files_to_copy.append(pathutils.SPICE_CERT_FILE) |
986 |
files_to_copy.append(pathutils.SPICE_CACERT_FILE) |
987 |
|
988 |
if new_confd_hmac_key:
|
989 |
files_to_copy.append(pathutils.CONFD_HMAC_KEY) |
990 |
|
991 |
if new_cds or cds: |
992 |
files_to_copy.append(pathutils.CLUSTER_DOMAIN_SECRET_FILE) |
993 |
|
994 |
if files_to_copy:
|
995 |
for node_name in ctx.nonmaster_nodes: |
996 |
port = ctx.ssh_ports[node_name] |
997 |
ctx.feedback_fn("Copying %s to %s:%d" %
|
998 |
(", ".join(files_to_copy), node_name, port))
|
999 |
for file_name in files_to_copy: |
1000 |
ctx.ssh.CopyFileToNode(node_name, port, file_name) |
1001 |
|
1002 |
RunWhileClusterStopped(ToStdout, _RenewCryptoInner) |
1003 |
|
1004 |
ToStdout("All requested certificates and keys have been replaced."
|
1005 |
" Running \"gnt-cluster verify\" now is recommended.")
|
1006 |
|
1007 |
return 0 |
1008 |
|
1009 |
|
1010 |
def RenewCrypto(opts, args): |
1011 |
"""Renews cluster certificates, keys and secrets.
|
1012 |
|
1013 |
"""
|
1014 |
return _RenewCrypto(opts.new_cluster_cert,
|
1015 |
opts.new_rapi_cert, |
1016 |
opts.rapi_cert, |
1017 |
opts.new_spice_cert, |
1018 |
opts.spice_cert, |
1019 |
opts.spice_cacert, |
1020 |
opts.new_confd_hmac_key, |
1021 |
opts.new_cluster_domain_secret, |
1022 |
opts.cluster_domain_secret, |
1023 |
opts.force) |
1024 |
|
1025 |
|
1026 |
def _GetEnabledDiskTemplates(opts): |
1027 |
"""Determine the list of enabled disk templates.
|
1028 |
|
1029 |
"""
|
1030 |
if opts.enabled_disk_templates:
|
1031 |
return opts.enabled_disk_templates.split(",") |
1032 |
else:
|
1033 |
return None |
1034 |
|
1035 |
|
1036 |
def _GetVgName(opts, enabled_disk_templates): |
1037 |
"""Determine the volume group name.
|
1038 |
|
1039 |
@type enabled_disk_templates: list of strings
|
1040 |
@param enabled_disk_templates: cluster-wide enabled disk-templates
|
1041 |
|
1042 |
"""
|
1043 |
# consistency between vg name and enabled disk templates
|
1044 |
vg_name = None
|
1045 |
if opts.vg_name is not None: |
1046 |
vg_name = opts.vg_name |
1047 |
if enabled_disk_templates:
|
1048 |
if vg_name and not utils.IsLvmEnabled(enabled_disk_templates): |
1049 |
ToStdout("You specified a volume group with --vg-name, but you did not"
|
1050 |
" enable any of the following lvm-based disk templates: %s" %
|
1051 |
utils.CommaJoin(constants.DTS_LVM)) |
1052 |
return vg_name
|
1053 |
|
1054 |
|
1055 |
def _GetDrbdHelper(opts, enabled_disk_templates): |
1056 |
"""Determine the DRBD usermode helper.
|
1057 |
|
1058 |
"""
|
1059 |
drbd_helper = opts.drbd_helper |
1060 |
if enabled_disk_templates:
|
1061 |
drbd_enabled = constants.DT_DRBD8 in enabled_disk_templates
|
1062 |
if not drbd_enabled and opts.drbd_helper: |
1063 |
ToStdout("You specified a DRBD usermode helper with "
|
1064 |
" --drbd-usermode-helper while DRBD is not enabled.")
|
1065 |
return drbd_helper
|
1066 |
|
1067 |
|
1068 |
def SetClusterParams(opts, args): |
1069 |
"""Modify the cluster.
|
1070 |
|
1071 |
@param opts: the command line options selected by the user
|
1072 |
@type args: list
|
1073 |
@param args: should be an empty list
|
1074 |
@rtype: int
|
1075 |
@return: the desired exit code
|
1076 |
|
1077 |
"""
|
1078 |
if not (opts.vg_name is not None or |
1079 |
opts.drbd_helper is not None or |
1080 |
opts.enabled_hypervisors or opts.hvparams or |
1081 |
opts.beparams or opts.nicparams or |
1082 |
opts.ndparams or opts.diskparams or |
1083 |
opts.candidate_pool_size is not None or |
1084 |
opts.uid_pool is not None or |
1085 |
opts.maintain_node_health is not None or |
1086 |
opts.add_uids is not None or |
1087 |
opts.remove_uids is not None or |
1088 |
opts.default_iallocator is not None or |
1089 |
opts.default_iallocator_params or
|
1090 |
opts.reserved_lvs is not None or |
1091 |
opts.master_netdev is not None or |
1092 |
opts.master_netmask is not None or |
1093 |
opts.use_external_mip_script is not None or |
1094 |
opts.prealloc_wipe_disks is not None or |
1095 |
opts.hv_state or
|
1096 |
opts.enabled_disk_templates or
|
1097 |
opts.disk_state or
|
1098 |
opts.ipolicy_bounds_specs is not None or |
1099 |
opts.ipolicy_std_specs is not None or |
1100 |
opts.ipolicy_disk_templates is not None or |
1101 |
opts.ipolicy_vcpu_ratio is not None or |
1102 |
opts.ipolicy_spindle_ratio is not None or |
1103 |
opts.modify_etc_hosts is not None or |
1104 |
opts.file_storage_dir is not None): |
1105 |
ToStderr("Please give at least one of the parameters.")
|
1106 |
return 1 |
1107 |
|
1108 |
enabled_disk_templates = _GetEnabledDiskTemplates(opts) |
1109 |
vg_name = _GetVgName(opts, enabled_disk_templates) |
1110 |
|
1111 |
try:
|
1112 |
drbd_helper = _GetDrbdHelper(opts, enabled_disk_templates) |
1113 |
except errors.OpPrereqError, e:
|
1114 |
ToStderr(str(e))
|
1115 |
return 1 |
1116 |
|
1117 |
hvlist = opts.enabled_hypervisors |
1118 |
if hvlist is not None: |
1119 |
hvlist = hvlist.split(",")
|
1120 |
|
1121 |
# a list of (name, dict) we can pass directly to dict() (or [])
|
1122 |
hvparams = dict(opts.hvparams)
|
1123 |
for hv_params in hvparams.values(): |
1124 |
utils.ForceDictType(hv_params, constants.HVS_PARAMETER_TYPES) |
1125 |
|
1126 |
diskparams = dict(opts.diskparams)
|
1127 |
|
1128 |
for dt_params in diskparams.values(): |
1129 |
utils.ForceDictType(dt_params, constants.DISK_DT_TYPES) |
1130 |
|
1131 |
beparams = opts.beparams |
1132 |
utils.ForceDictType(beparams, constants.BES_PARAMETER_COMPAT) |
1133 |
|
1134 |
nicparams = opts.nicparams |
1135 |
utils.ForceDictType(nicparams, constants.NICS_PARAMETER_TYPES) |
1136 |
|
1137 |
ndparams = opts.ndparams |
1138 |
if ndparams is not None: |
1139 |
utils.ForceDictType(ndparams, constants.NDS_PARAMETER_TYPES) |
1140 |
|
1141 |
ipolicy = CreateIPolicyFromOpts( |
1142 |
minmax_ispecs=opts.ipolicy_bounds_specs, |
1143 |
std_ispecs=opts.ipolicy_std_specs, |
1144 |
ipolicy_disk_templates=opts.ipolicy_disk_templates, |
1145 |
ipolicy_vcpu_ratio=opts.ipolicy_vcpu_ratio, |
1146 |
ipolicy_spindle_ratio=opts.ipolicy_spindle_ratio, |
1147 |
) |
1148 |
|
1149 |
mnh = opts.maintain_node_health |
1150 |
|
1151 |
uid_pool = opts.uid_pool |
1152 |
if uid_pool is not None: |
1153 |
uid_pool = uidpool.ParseUidPool(uid_pool) |
1154 |
|
1155 |
add_uids = opts.add_uids |
1156 |
if add_uids is not None: |
1157 |
add_uids = uidpool.ParseUidPool(add_uids) |
1158 |
|
1159 |
remove_uids = opts.remove_uids |
1160 |
if remove_uids is not None: |
1161 |
remove_uids = uidpool.ParseUidPool(remove_uids) |
1162 |
|
1163 |
if opts.reserved_lvs is not None: |
1164 |
if opts.reserved_lvs == "": |
1165 |
opts.reserved_lvs = [] |
1166 |
else:
|
1167 |
opts.reserved_lvs = utils.UnescapeAndSplit(opts.reserved_lvs, sep=",")
|
1168 |
|
1169 |
if opts.master_netmask is not None: |
1170 |
try:
|
1171 |
opts.master_netmask = int(opts.master_netmask)
|
1172 |
except ValueError: |
1173 |
ToStderr("The --master-netmask option expects an int parameter.")
|
1174 |
return 1 |
1175 |
|
1176 |
ext_ip_script = opts.use_external_mip_script |
1177 |
|
1178 |
if opts.disk_state:
|
1179 |
disk_state = utils.FlatToDict(opts.disk_state) |
1180 |
else:
|
1181 |
disk_state = {} |
1182 |
|
1183 |
hv_state = dict(opts.hv_state)
|
1184 |
|
1185 |
op = opcodes.OpClusterSetParams( |
1186 |
vg_name=vg_name, |
1187 |
drbd_helper=drbd_helper, |
1188 |
enabled_hypervisors=hvlist, |
1189 |
hvparams=hvparams, |
1190 |
os_hvp=None,
|
1191 |
beparams=beparams, |
1192 |
nicparams=nicparams, |
1193 |
ndparams=ndparams, |
1194 |
diskparams=diskparams, |
1195 |
ipolicy=ipolicy, |
1196 |
candidate_pool_size=opts.candidate_pool_size, |
1197 |
maintain_node_health=mnh, |
1198 |
modify_etc_hosts=opts.modify_etc_hosts, |
1199 |
uid_pool=uid_pool, |
1200 |
add_uids=add_uids, |
1201 |
remove_uids=remove_uids, |
1202 |
default_iallocator=opts.default_iallocator, |
1203 |
default_iallocator_params=opts.default_iallocator_params, |
1204 |
prealloc_wipe_disks=opts.prealloc_wipe_disks, |
1205 |
master_netdev=opts.master_netdev, |
1206 |
master_netmask=opts.master_netmask, |
1207 |
reserved_lvs=opts.reserved_lvs, |
1208 |
use_external_mip_script=ext_ip_script, |
1209 |
hv_state=hv_state, |
1210 |
disk_state=disk_state, |
1211 |
enabled_disk_templates=enabled_disk_templates, |
1212 |
force=opts.force, |
1213 |
file_storage_dir=opts.file_storage_dir, |
1214 |
) |
1215 |
SubmitOrSend(op, opts) |
1216 |
return 0 |
1217 |
|
1218 |
|
1219 |
def QueueOps(opts, args): |
1220 |
"""Queue operations.
|
1221 |
|
1222 |
@param opts: the command line options selected by the user
|
1223 |
@type args: list
|
1224 |
@param args: should contain only one element, the subcommand
|
1225 |
@rtype: int
|
1226 |
@return: the desired exit code
|
1227 |
|
1228 |
"""
|
1229 |
command = args[0]
|
1230 |
client = GetClient() |
1231 |
if command in ("drain", "undrain"): |
1232 |
drain_flag = command == "drain"
|
1233 |
client.SetQueueDrainFlag(drain_flag) |
1234 |
elif command == "info": |
1235 |
result = client.QueryConfigValues(["drain_flag"])
|
1236 |
if result[0]: |
1237 |
val = "set"
|
1238 |
else:
|
1239 |
val = "unset"
|
1240 |
ToStdout("The drain flag is %s" % val)
|
1241 |
else:
|
1242 |
raise errors.OpPrereqError("Command '%s' is not valid." % command, |
1243 |
errors.ECODE_INVAL) |
1244 |
|
1245 |
return 0 |
1246 |
|
1247 |
|
1248 |
def _ShowWatcherPause(until): |
1249 |
if until is None or until < time.time(): |
1250 |
ToStdout("The watcher is not paused.")
|
1251 |
else:
|
1252 |
ToStdout("The watcher is paused until %s.", time.ctime(until))
|
1253 |
|
1254 |
|
1255 |
def WatcherOps(opts, args): |
1256 |
"""Watcher operations.
|
1257 |
|
1258 |
@param opts: the command line options selected by the user
|
1259 |
@type args: list
|
1260 |
@param args: should contain only one element, the subcommand
|
1261 |
@rtype: int
|
1262 |
@return: the desired exit code
|
1263 |
|
1264 |
"""
|
1265 |
command = args[0]
|
1266 |
client = GetClient() |
1267 |
|
1268 |
if command == "continue": |
1269 |
client.SetWatcherPause(None)
|
1270 |
ToStdout("The watcher is no longer paused.")
|
1271 |
|
1272 |
elif command == "pause": |
1273 |
if len(args) < 2: |
1274 |
raise errors.OpPrereqError("Missing pause duration", errors.ECODE_INVAL) |
1275 |
|
1276 |
result = client.SetWatcherPause(time.time() + ParseTimespec(args[1]))
|
1277 |
_ShowWatcherPause(result) |
1278 |
|
1279 |
elif command == "info": |
1280 |
result = client.QueryConfigValues(["watcher_pause"])
|
1281 |
_ShowWatcherPause(result[0])
|
1282 |
|
1283 |
else:
|
1284 |
raise errors.OpPrereqError("Command '%s' is not valid." % command, |
1285 |
errors.ECODE_INVAL) |
1286 |
|
1287 |
return 0 |
1288 |
|
1289 |
|
1290 |
def _OobPower(opts, node_list, power): |
1291 |
"""Puts the node in the list to desired power state.
|
1292 |
|
1293 |
@param opts: The command line options selected by the user
|
1294 |
@param node_list: The list of nodes to operate on
|
1295 |
@param power: True if they should be powered on, False otherwise
|
1296 |
@return: The success of the operation (none failed)
|
1297 |
|
1298 |
"""
|
1299 |
if power:
|
1300 |
command = constants.OOB_POWER_ON |
1301 |
else:
|
1302 |
command = constants.OOB_POWER_OFF |
1303 |
|
1304 |
op = opcodes.OpOobCommand(node_names=node_list, |
1305 |
command=command, |
1306 |
ignore_status=True,
|
1307 |
timeout=opts.oob_timeout, |
1308 |
power_delay=opts.power_delay) |
1309 |
result = SubmitOpCode(op, opts=opts) |
1310 |
errs = 0
|
1311 |
for node_result in result: |
1312 |
(node_tuple, data_tuple) = node_result |
1313 |
(_, node_name) = node_tuple |
1314 |
(data_status, _) = data_tuple |
1315 |
if data_status != constants.RS_NORMAL:
|
1316 |
assert data_status != constants.RS_UNAVAIL
|
1317 |
errs += 1
|
1318 |
ToStderr("There was a problem changing power for %s, please investigate",
|
1319 |
node_name) |
1320 |
|
1321 |
if errs > 0: |
1322 |
return False |
1323 |
|
1324 |
return True |
1325 |
|
1326 |
|
1327 |
def _InstanceStart(opts, inst_list, start, no_remember=False): |
1328 |
"""Puts the instances in the list to desired state.
|
1329 |
|
1330 |
@param opts: The command line options selected by the user
|
1331 |
@param inst_list: The list of instances to operate on
|
1332 |
@param start: True if they should be started, False for shutdown
|
1333 |
@param no_remember: If the instance state should be remembered
|
1334 |
@return: The success of the operation (none failed)
|
1335 |
|
1336 |
"""
|
1337 |
if start:
|
1338 |
opcls = opcodes.OpInstanceStartup |
1339 |
text_submit, text_success, text_failed = ("startup", "started", "starting") |
1340 |
else:
|
1341 |
opcls = compat.partial(opcodes.OpInstanceShutdown, |
1342 |
timeout=opts.shutdown_timeout, |
1343 |
no_remember=no_remember) |
1344 |
text_submit, text_success, text_failed = ("shutdown", "stopped", "stopping") |
1345 |
|
1346 |
jex = JobExecutor(opts=opts) |
1347 |
|
1348 |
for inst in inst_list: |
1349 |
ToStdout("Submit %s of instance %s", text_submit, inst)
|
1350 |
op = opcls(instance_name=inst) |
1351 |
jex.QueueJob(inst, op) |
1352 |
|
1353 |
results = jex.GetResults() |
1354 |
bad_cnt = len([1 for (success, _) in results if not success]) |
1355 |
|
1356 |
if bad_cnt == 0: |
1357 |
ToStdout("All instances have been %s successfully", text_success)
|
1358 |
else:
|
1359 |
ToStderr("There were errors while %s instances:\n"
|
1360 |
"%d error(s) out of %d instance(s)", text_failed, bad_cnt,
|
1361 |
len(results))
|
1362 |
return False |
1363 |
|
1364 |
return True |
1365 |
|
1366 |
|
1367 |
class _RunWhenNodesReachableHelper: |
1368 |
"""Helper class to make shared internal state sharing easier.
|
1369 |
|
1370 |
@ivar success: Indicates if all action_cb calls were successful
|
1371 |
|
1372 |
"""
|
1373 |
def __init__(self, node_list, action_cb, node2ip, port, feedback_fn, |
1374 |
_ping_fn=netutils.TcpPing, _sleep_fn=time.sleep): |
1375 |
"""Init the object.
|
1376 |
|
1377 |
@param node_list: The list of nodes to be reachable
|
1378 |
@param action_cb: Callback called when a new host is reachable
|
1379 |
@type node2ip: dict
|
1380 |
@param node2ip: Node to ip mapping
|
1381 |
@param port: The port to use for the TCP ping
|
1382 |
@param feedback_fn: The function used for feedback
|
1383 |
@param _ping_fn: Function to check reachabilty (for unittest use only)
|
1384 |
@param _sleep_fn: Function to sleep (for unittest use only)
|
1385 |
|
1386 |
"""
|
1387 |
self.down = set(node_list) |
1388 |
self.up = set() |
1389 |
self.node2ip = node2ip
|
1390 |
self.success = True |
1391 |
self.action_cb = action_cb
|
1392 |
self.port = port
|
1393 |
self.feedback_fn = feedback_fn
|
1394 |
self._ping_fn = _ping_fn
|
1395 |
self._sleep_fn = _sleep_fn
|
1396 |
|
1397 |
def __call__(self): |
1398 |
"""When called we run action_cb.
|
1399 |
|
1400 |
@raises utils.RetryAgain: When there are still down nodes
|
1401 |
|
1402 |
"""
|
1403 |
if not self.action_cb(self.up): |
1404 |
self.success = False |
1405 |
|
1406 |
if self.down: |
1407 |
raise utils.RetryAgain()
|
1408 |
else:
|
1409 |
return self.success |
1410 |
|
1411 |
def Wait(self, secs): |
1412 |
"""Checks if a host is up or waits remaining seconds.
|
1413 |
|
1414 |
@param secs: The secs remaining
|
1415 |
|
1416 |
"""
|
1417 |
start = time.time() |
1418 |
for node in self.down: |
1419 |
if self._ping_fn(self.node2ip[node], self.port, timeout=_EPO_PING_TIMEOUT, |
1420 |
live_port_needed=True):
|
1421 |
self.feedback_fn("Node %s became available" % node) |
1422 |
self.up.add(node)
|
1423 |
self.down -= self.up |
1424 |
# If we have a node available there is the possibility to run the
|
1425 |
# action callback successfully, therefore we don't wait and return
|
1426 |
return
|
1427 |
|
1428 |
self._sleep_fn(max(0.0, start + secs - time.time())) |
1429 |
|
1430 |
|
1431 |
def _RunWhenNodesReachable(node_list, action_cb, interval): |
1432 |
"""Run action_cb when nodes become reachable.
|
1433 |
|
1434 |
@param node_list: The list of nodes to be reachable
|
1435 |
@param action_cb: Callback called when a new host is reachable
|
1436 |
@param interval: The earliest time to retry
|
1437 |
|
1438 |
"""
|
1439 |
client = GetClient() |
1440 |
cluster_info = client.QueryClusterInfo() |
1441 |
if cluster_info["primary_ip_version"] == constants.IP4_VERSION: |
1442 |
family = netutils.IPAddress.family |
1443 |
else:
|
1444 |
family = netutils.IP6Address.family |
1445 |
|
1446 |
node2ip = dict((node, netutils.GetHostname(node, family=family).ip)
|
1447 |
for node in node_list) |
1448 |
|
1449 |
port = netutils.GetDaemonPort(constants.NODED) |
1450 |
helper = _RunWhenNodesReachableHelper(node_list, action_cb, node2ip, port, |
1451 |
ToStdout) |
1452 |
|
1453 |
try:
|
1454 |
return utils.Retry(helper, interval, _EPO_REACHABLE_TIMEOUT,
|
1455 |
wait_fn=helper.Wait) |
1456 |
except utils.RetryTimeout:
|
1457 |
ToStderr("Time exceeded while waiting for nodes to become reachable"
|
1458 |
" again:\n - %s", " - ".join(helper.down)) |
1459 |
return False |
1460 |
|
1461 |
|
1462 |
def _MaybeInstanceStartup(opts, inst_map, nodes_online, |
1463 |
_instance_start_fn=_InstanceStart): |
1464 |
"""Start the instances conditional based on node_states.
|
1465 |
|
1466 |
@param opts: The command line options selected by the user
|
1467 |
@param inst_map: A dict of inst -> nodes mapping
|
1468 |
@param nodes_online: A list of nodes online
|
1469 |
@param _instance_start_fn: Callback to start instances (unittest use only)
|
1470 |
@return: Success of the operation on all instances
|
1471 |
|
1472 |
"""
|
1473 |
start_inst_list = [] |
1474 |
for (inst, nodes) in inst_map.items(): |
1475 |
if not (nodes - nodes_online): |
1476 |
# All nodes the instance lives on are back online
|
1477 |
start_inst_list.append(inst) |
1478 |
|
1479 |
for inst in start_inst_list: |
1480 |
del inst_map[inst]
|
1481 |
|
1482 |
if start_inst_list:
|
1483 |
return _instance_start_fn(opts, start_inst_list, True) |
1484 |
|
1485 |
return True |
1486 |
|
1487 |
|
1488 |
def _EpoOn(opts, full_node_list, node_list, inst_map): |
1489 |
"""Does the actual power on.
|
1490 |
|
1491 |
@param opts: The command line options selected by the user
|
1492 |
@param full_node_list: All nodes to operate on (includes nodes not supporting
|
1493 |
OOB)
|
1494 |
@param node_list: The list of nodes to operate on (all need to support OOB)
|
1495 |
@param inst_map: A dict of inst -> nodes mapping
|
1496 |
@return: The desired exit status
|
1497 |
|
1498 |
"""
|
1499 |
if node_list and not _OobPower(opts, node_list, False): |
1500 |
ToStderr("Not all nodes seem to get back up, investigate and start"
|
1501 |
" manually if needed")
|
1502 |
|
1503 |
# Wait for the nodes to be back up
|
1504 |
action_cb = compat.partial(_MaybeInstanceStartup, opts, dict(inst_map))
|
1505 |
|
1506 |
ToStdout("Waiting until all nodes are available again")
|
1507 |
if not _RunWhenNodesReachable(full_node_list, action_cb, _EPO_PING_INTERVAL): |
1508 |
ToStderr("Please investigate and start stopped instances manually")
|
1509 |
return constants.EXIT_FAILURE
|
1510 |
|
1511 |
return constants.EXIT_SUCCESS
|
1512 |
|
1513 |
|
1514 |
def _EpoOff(opts, node_list, inst_map): |
1515 |
"""Does the actual power off.
|
1516 |
|
1517 |
@param opts: The command line options selected by the user
|
1518 |
@param node_list: The list of nodes to operate on (all need to support OOB)
|
1519 |
@param inst_map: A dict of inst -> nodes mapping
|
1520 |
@return: The desired exit status
|
1521 |
|
1522 |
"""
|
1523 |
if not _InstanceStart(opts, inst_map.keys(), False, no_remember=True): |
1524 |
ToStderr("Please investigate and stop instances manually before continuing")
|
1525 |
return constants.EXIT_FAILURE
|
1526 |
|
1527 |
if not node_list: |
1528 |
return constants.EXIT_SUCCESS
|
1529 |
|
1530 |
if _OobPower(opts, node_list, False): |
1531 |
return constants.EXIT_SUCCESS
|
1532 |
else:
|
1533 |
return constants.EXIT_FAILURE
|
1534 |
|
1535 |
|
1536 |
def Epo(opts, args, qcl=None, _on_fn=_EpoOn, _off_fn=_EpoOff, |
1537 |
_confirm_fn=ConfirmOperation, |
1538 |
_stdout_fn=ToStdout, _stderr_fn=ToStderr): |
1539 |
"""EPO operations.
|
1540 |
|
1541 |
@param opts: the command line options selected by the user
|
1542 |
@type args: list
|
1543 |
@param args: should contain only one element, the subcommand
|
1544 |
@rtype: int
|
1545 |
@return: the desired exit code
|
1546 |
|
1547 |
"""
|
1548 |
if opts.groups and opts.show_all: |
1549 |
_stderr_fn("Only one of --groups or --all are allowed")
|
1550 |
return constants.EXIT_FAILURE
|
1551 |
elif args and opts.show_all: |
1552 |
_stderr_fn("Arguments in combination with --all are not allowed")
|
1553 |
return constants.EXIT_FAILURE
|
1554 |
|
1555 |
if qcl is None: |
1556 |
# Query client
|
1557 |
qcl = GetClient(query=True)
|
1558 |
|
1559 |
if opts.groups:
|
1560 |
node_query_list = \ |
1561 |
itertools.chain(*qcl.QueryGroups(args, ["node_list"], False)) |
1562 |
else:
|
1563 |
node_query_list = args |
1564 |
|
1565 |
result = qcl.QueryNodes(node_query_list, ["name", "master", "pinst_list", |
1566 |
"sinst_list", "powered", "offline"], |
1567 |
False)
|
1568 |
|
1569 |
all_nodes = map(compat.fst, result)
|
1570 |
node_list = [] |
1571 |
inst_map = {} |
1572 |
for (node, master, pinsts, sinsts, powered, offline) in result: |
1573 |
if not offline: |
1574 |
for inst in (pinsts + sinsts): |
1575 |
if inst in inst_map: |
1576 |
if not master: |
1577 |
inst_map[inst].add(node) |
1578 |
elif master:
|
1579 |
inst_map[inst] = set()
|
1580 |
else:
|
1581 |
inst_map[inst] = set([node])
|
1582 |
|
1583 |
if master and opts.on: |
1584 |
# We ignore the master for turning on the machines, in fact we are
|
1585 |
# already operating on the master at this point :)
|
1586 |
continue
|
1587 |
elif master and not opts.show_all: |
1588 |
_stderr_fn("%s is the master node, please do a master-failover to another"
|
1589 |
" node not affected by the EPO or use --all if you intend to"
|
1590 |
" shutdown the whole cluster", node)
|
1591 |
return constants.EXIT_FAILURE
|
1592 |
elif powered is None: |
1593 |
_stdout_fn("Node %s does not support out-of-band handling, it can not be"
|
1594 |
" handled in a fully automated manner", node)
|
1595 |
elif powered == opts.on:
|
1596 |
_stdout_fn("Node %s is already in desired power state, skipping", node)
|
1597 |
elif not offline or (offline and powered): |
1598 |
node_list.append(node) |
1599 |
|
1600 |
if not (opts.force or _confirm_fn(all_nodes, "nodes", "epo")): |
1601 |
return constants.EXIT_FAILURE
|
1602 |
|
1603 |
if opts.on:
|
1604 |
return _on_fn(opts, all_nodes, node_list, inst_map)
|
1605 |
else:
|
1606 |
return _off_fn(opts, node_list, inst_map)
|
1607 |
|
1608 |
|
1609 |
def _GetCreateCommand(info): |
1610 |
buf = StringIO() |
1611 |
buf.write("gnt-cluster init")
|
1612 |
PrintIPolicyCommand(buf, info["ipolicy"], False) |
1613 |
buf.write(" ")
|
1614 |
buf.write(info["name"])
|
1615 |
return buf.getvalue()
|
1616 |
|
1617 |
|
1618 |
def ShowCreateCommand(opts, args): |
1619 |
"""Shows the command that can be used to re-create the cluster.
|
1620 |
|
1621 |
Currently it works only for ipolicy specs.
|
1622 |
|
1623 |
"""
|
1624 |
cl = GetClient(query=True)
|
1625 |
result = cl.QueryClusterInfo() |
1626 |
ToStdout(_GetCreateCommand(result)) |
1627 |
|
1628 |
|
1629 |
def _RunCommandAndReport(cmd): |
1630 |
"""Run a command and report its output, iff it failed.
|
1631 |
|
1632 |
@param cmd: the command to execute
|
1633 |
@type cmd: list
|
1634 |
@rtype: bool
|
1635 |
@return: False, if the execution failed.
|
1636 |
|
1637 |
"""
|
1638 |
result = utils.RunCmd(cmd) |
1639 |
if result.failed:
|
1640 |
ToStderr("Command %s failed: %s; Output %s" %
|
1641 |
(cmd, result.fail_reason, result.output)) |
1642 |
return False |
1643 |
return True |
1644 |
|
1645 |
|
1646 |
def _VerifyCommand(cmd): |
1647 |
"""Verify that a given command succeeds on all online nodes.
|
1648 |
|
1649 |
As this function is intended to run during upgrades, it
|
1650 |
is implemented in such a way that it still works, if all Ganeti
|
1651 |
daemons are down.
|
1652 |
|
1653 |
@param cmd: the command to execute
|
1654 |
@type cmd: list
|
1655 |
@rtype: list
|
1656 |
@return: the list of node names that are online where
|
1657 |
the command failed.
|
1658 |
|
1659 |
"""
|
1660 |
command = utils.text.ShellQuoteArgs([str(val) for val in cmd]) |
1661 |
|
1662 |
nodes = ssconf.SimpleStore().GetOnlineNodeList() |
1663 |
master_node = ssconf.SimpleStore().GetMasterNode() |
1664 |
cluster_name = ssconf.SimpleStore().GetClusterName() |
1665 |
|
1666 |
# If master node is in 'nodes', make sure master node is at list end
|
1667 |
if master_node in nodes: |
1668 |
nodes.remove(master_node) |
1669 |
nodes.append(master_node) |
1670 |
|
1671 |
failed = [] |
1672 |
|
1673 |
srun = ssh.SshRunner(cluster_name=cluster_name) |
1674 |
for name in nodes: |
1675 |
result = srun.Run(name, constants.SSH_LOGIN_USER, command) |
1676 |
if result.exit_code != 0: |
1677 |
failed.append(name) |
1678 |
|
1679 |
return failed
|
1680 |
|
1681 |
|
1682 |
def _VerifyVersionInstalled(versionstring): |
1683 |
"""Verify that the given version of ganeti is installed on all online nodes.
|
1684 |
|
1685 |
Do nothing, if this is the case, otherwise print an appropriate
|
1686 |
message to stderr.
|
1687 |
|
1688 |
@param versionstring: the version to check for
|
1689 |
@type versionstring: string
|
1690 |
@rtype: bool
|
1691 |
@return: True, if the version is installed on all online nodes
|
1692 |
|
1693 |
"""
|
1694 |
badnodes = _VerifyCommand(["test", "-d", |
1695 |
os.path.join(pathutils.PKGLIBDIR, versionstring)]) |
1696 |
if badnodes:
|
1697 |
ToStderr("Ganeti version %s not installed on nodes %s"
|
1698 |
% (versionstring, ", ".join(badnodes)))
|
1699 |
return False |
1700 |
|
1701 |
return True |
1702 |
|
1703 |
|
1704 |
def _GetRunning(): |
1705 |
"""Determine the list of running jobs.
|
1706 |
|
1707 |
@rtype: list
|
1708 |
@return: the number of jobs still running
|
1709 |
|
1710 |
"""
|
1711 |
cl = GetClient() |
1712 |
qfilter = qlang.MakeSimpleFilter("status",
|
1713 |
frozenset([constants.JOB_STATUS_RUNNING]))
|
1714 |
return len(cl.Query(constants.QR_JOB, [], qfilter).data) |
1715 |
|
1716 |
|
1717 |
def _SetGanetiVersion(versionstring): |
1718 |
"""Set the active version of ganeti to the given versionstring
|
1719 |
|
1720 |
@type versionstring: string
|
1721 |
@rtype: list
|
1722 |
@return: the list of nodes where the version change failed
|
1723 |
|
1724 |
"""
|
1725 |
failed = [] |
1726 |
if constants.HAS_GNU_LN:
|
1727 |
failed.extend(_VerifyCommand( |
1728 |
["ln", "-s", "-f", "-T", |
1729 |
os.path.join(pathutils.PKGLIBDIR, versionstring), |
1730 |
os.path.join(pathutils.SYSCONFDIR, "ganeti/lib")]))
|
1731 |
failed.extend(_VerifyCommand( |
1732 |
["ln", "-s", "-f", "-T", |
1733 |
os.path.join(pathutils.SHAREDIR, versionstring), |
1734 |
os.path.join(pathutils.SYSCONFDIR, "ganeti/share")]))
|
1735 |
else:
|
1736 |
failed.extend(_VerifyCommand( |
1737 |
["rm", "-f", os.path.join(pathutils.SYSCONFDIR, "ganeti/lib")])) |
1738 |
failed.extend(_VerifyCommand( |
1739 |
["ln", "-s", "-f", os.path.join(pathutils.PKGLIBDIR, versionstring), |
1740 |
os.path.join(pathutils.SYSCONFDIR, "ganeti/lib")]))
|
1741 |
failed.extend(_VerifyCommand( |
1742 |
["rm", "-f", os.path.join(pathutils.SYSCONFDIR, "ganeti/share")])) |
1743 |
failed.extend(_VerifyCommand( |
1744 |
["ln", "-s", "-f", os.path.join(pathutils.SHAREDIR, versionstring), |
1745 |
os.path.join(pathutils.SYSCONFDIR, "ganeti/share")]))
|
1746 |
return list(set(failed)) |
1747 |
|
1748 |
|
1749 |
def _ExecuteCommands(fns): |
1750 |
"""Execute a list of functions, in reverse order.
|
1751 |
|
1752 |
@type fns: list of functions.
|
1753 |
@param fns: the functions to be executed.
|
1754 |
|
1755 |
"""
|
1756 |
for fn in reversed(fns): |
1757 |
fn() |
1758 |
|
1759 |
|
1760 |
def _GetConfigVersion(): |
1761 |
"""Determine the version the configuration file currently has.
|
1762 |
|
1763 |
@rtype: tuple or None
|
1764 |
@return: (major, minor, revision) if the version can be determined,
|
1765 |
None otherwise
|
1766 |
|
1767 |
"""
|
1768 |
config_data = serializer.LoadJson(utils.ReadFile(pathutils.CLUSTER_CONF_FILE)) |
1769 |
try:
|
1770 |
config_version = config_data["version"]
|
1771 |
except KeyError: |
1772 |
return None |
1773 |
return utils.SplitVersion(config_version)
|
1774 |
|
1775 |
|
1776 |
def _ReadIntentToUpgrade(): |
1777 |
"""Read the file documenting the intent to upgrade the cluster.
|
1778 |
|
1779 |
@rtype: string or None
|
1780 |
@return: the version to upgrade to, if the file exists, and None
|
1781 |
otherwise.
|
1782 |
|
1783 |
"""
|
1784 |
if not os.path.isfile(pathutils.INTENT_TO_UPGRADE): |
1785 |
return None |
1786 |
|
1787 |
contentstring = utils.ReadFile(pathutils.INTENT_TO_UPGRADE) |
1788 |
contents = utils.UnescapeAndSplit(contentstring) |
1789 |
if len(contents) != 2: |
1790 |
# file syntactically mal-formed
|
1791 |
return None |
1792 |
return contents[0] |
1793 |
|
1794 |
|
1795 |
def _WriteIntentToUpgrade(version): |
1796 |
"""Write file documenting the intent to upgrade the cluster.
|
1797 |
|
1798 |
@type version: string
|
1799 |
@param version: the version we intent to upgrade to
|
1800 |
|
1801 |
"""
|
1802 |
utils.WriteFile(pathutils.INTENT_TO_UPGRADE, |
1803 |
data=utils.EscapeAndJoin([version, "%d" % os.getpid()]))
|
1804 |
|
1805 |
|
1806 |
def _UpgradeBeforeConfigurationChange(versionstring): |
1807 |
"""
|
1808 |
Carry out all the tasks necessary for an upgrade that happen before
|
1809 |
the configuration file, or Ganeti version, changes.
|
1810 |
|
1811 |
@type versionstring: string
|
1812 |
@param versionstring: the version to upgrade to
|
1813 |
@rtype: (bool, list)
|
1814 |
@return: tuple of a bool indicating success and a list of rollback tasks
|
1815 |
|
1816 |
"""
|
1817 |
rollback = [] |
1818 |
|
1819 |
if not _VerifyVersionInstalled(versionstring): |
1820 |
return (False, rollback) |
1821 |
|
1822 |
_WriteIntentToUpgrade(versionstring) |
1823 |
rollback.append( |
1824 |
lambda: utils.RunCmd(["rm", "-f", pathutils.INTENT_TO_UPGRADE])) |
1825 |
|
1826 |
ToStdout("Draining queue")
|
1827 |
client = GetClient() |
1828 |
client.SetQueueDrainFlag(True)
|
1829 |
|
1830 |
rollback.append(lambda: GetClient().SetQueueDrainFlag(False)) |
1831 |
|
1832 |
if utils.SimpleRetry(0, _GetRunning, |
1833 |
constants.UPGRADE_QUEUE_POLL_INTERVAL, |
1834 |
constants.UPGRADE_QUEUE_DRAIN_TIMEOUT): |
1835 |
ToStderr("Failed to completely empty the queue.")
|
1836 |
return (False, rollback) |
1837 |
|
1838 |
ToStdout("Stopping daemons on master node.")
|
1839 |
if not _RunCommandAndReport([pathutils.DAEMON_UTIL, "stop-all"]): |
1840 |
return (False, rollback) |
1841 |
|
1842 |
if not _VerifyVersionInstalled(versionstring): |
1843 |
utils.RunCmd([pathutils.DAEMON_UTIL, "start-all"])
|
1844 |
return (False, rollback) |
1845 |
|
1846 |
ToStdout("Stopping daemons everywhere.")
|
1847 |
rollback.append(lambda: _VerifyCommand([pathutils.DAEMON_UTIL, "start-all"])) |
1848 |
badnodes = _VerifyCommand([pathutils.DAEMON_UTIL, "stop-all"])
|
1849 |
if badnodes:
|
1850 |
ToStderr("Failed to stop daemons on %s." % (", ".join(badnodes),)) |
1851 |
return (False, rollback) |
1852 |
|
1853 |
backuptar = os.path.join(pathutils.LOCALSTATEDIR, |
1854 |
"lib/ganeti%d.tar" % time.time())
|
1855 |
ToStdout("Backing up configuration as %s" % backuptar)
|
1856 |
if not _RunCommandAndReport(["tar", "cf", backuptar, |
1857 |
pathutils.DATA_DIR]): |
1858 |
return (False, rollback) |
1859 |
|
1860 |
return (True, rollback) |
1861 |
|
1862 |
|
1863 |
def _SwitchVersionAndConfig(versionstring, downgrade): |
1864 |
"""
|
1865 |
Switch to the new Ganeti version and change the configuration,
|
1866 |
in correct order.
|
1867 |
|
1868 |
@type versionstring: string
|
1869 |
@param versionstring: the version to change to
|
1870 |
@type downgrade: bool
|
1871 |
@param downgrade: True, if the configuration should be downgraded
|
1872 |
@rtype: (bool, list)
|
1873 |
@return: tupe of a bool indicating success, and a list of
|
1874 |
additional rollback tasks
|
1875 |
|
1876 |
"""
|
1877 |
rollback = [] |
1878 |
if downgrade:
|
1879 |
ToStdout("Downgrading configuration")
|
1880 |
if not _RunCommandAndReport([pathutils.CFGUPGRADE, "--downgrade", "-f"]): |
1881 |
return (False, rollback) |
1882 |
|
1883 |
# Configuration change is the point of no return. From then onwards, it is
|
1884 |
# safer to push through the up/dowgrade than to try to roll it back.
|
1885 |
|
1886 |
ToStdout("Switching to version %s on all nodes" % versionstring)
|
1887 |
rollback.append(lambda: _SetGanetiVersion(constants.DIR_VERSION))
|
1888 |
badnodes = _SetGanetiVersion(versionstring) |
1889 |
if badnodes:
|
1890 |
ToStderr("Failed to switch to Ganeti version %s on nodes %s"
|
1891 |
% (versionstring, ", ".join(badnodes)))
|
1892 |
if not downgrade: |
1893 |
return (False, rollback) |
1894 |
|
1895 |
# Now that we have changed to the new version of Ganeti we should
|
1896 |
# not communicate over luxi any more, as luxi might have changed in
|
1897 |
# incompatible ways. Therefore, manually call the corresponding ganeti
|
1898 |
# commands using their canonical (version independent) path.
|
1899 |
|
1900 |
if not downgrade: |
1901 |
ToStdout("Upgrading configuration")
|
1902 |
if not _RunCommandAndReport([pathutils.CFGUPGRADE, "-f"]): |
1903 |
return (False, rollback) |
1904 |
|
1905 |
return (True, rollback) |
1906 |
|
1907 |
|
1908 |
def _UpgradeAfterConfigurationChange(): |
1909 |
"""
|
1910 |
Carry out the upgrade actions necessary after switching to the new
|
1911 |
Ganeti version and updating the configuration.
|
1912 |
|
1913 |
As this part is run at a time where the new version of Ganeti is already
|
1914 |
running, no communication should happen via luxi, as this is not a stable
|
1915 |
interface. Also, as the configuration change is the point of no return,
|
1916 |
all actions are pushed trough, even if some of them fail.
|
1917 |
|
1918 |
@rtype: int
|
1919 |
@return: the intended return value
|
1920 |
|
1921 |
"""
|
1922 |
returnvalue = 0
|
1923 |
|
1924 |
ToStdout("Starting daemons everywhere.")
|
1925 |
badnodes = _VerifyCommand([pathutils.DAEMON_UTIL, "start-all"])
|
1926 |
if badnodes:
|
1927 |
ToStderr("Warning: failed to start daemons on %s." % (", ".join(badnodes),)) |
1928 |
returnvalue = 1
|
1929 |
|
1930 |
ToStdout("Ensuring directories everywhere.")
|
1931 |
badnodes = _VerifyCommand([pathutils.ENSURE_DIRS]) |
1932 |
if badnodes:
|
1933 |
ToStderr("Warning: failed to ensure directories on %s." %
|
1934 |
(", ".join(badnodes)))
|
1935 |
returnvalue = 1
|
1936 |
|
1937 |
ToStdout("Redistributing the configuration.")
|
1938 |
if not _RunCommandAndReport(["gnt-cluster", "redist-conf", "--yes-do-it"]): |
1939 |
returnvalue = 1
|
1940 |
|
1941 |
ToStdout("Restarting daemons everywhere.")
|
1942 |
badnodes = _VerifyCommand([pathutils.DAEMON_UTIL, "stop-all"])
|
1943 |
badnodes.extend(_VerifyCommand([pathutils.DAEMON_UTIL, "start-all"]))
|
1944 |
if badnodes:
|
1945 |
ToStderr("Warning: failed to start daemons on %s." %
|
1946 |
(", ".join(list(set(badnodes))),)) |
1947 |
returnvalue = 1
|
1948 |
|
1949 |
ToStdout("Undraining the queue.")
|
1950 |
if not _RunCommandAndReport(["gnt-cluster", "queue", "undrain"]): |
1951 |
returnvalue = 1
|
1952 |
|
1953 |
_RunCommandAndReport(["rm", "-f", pathutils.INTENT_TO_UPGRADE]) |
1954 |
|
1955 |
ToStdout("Verifying cluster.")
|
1956 |
if not _RunCommandAndReport(["gnt-cluster", "verify"]): |
1957 |
returnvalue = 1
|
1958 |
|
1959 |
return returnvalue
|
1960 |
|
1961 |
|
1962 |
def UpgradeGanetiCommand(opts, args): |
1963 |
"""Upgrade a cluster to a new ganeti version.
|
1964 |
|
1965 |
@param opts: the command line options selected by the user
|
1966 |
@type args: list
|
1967 |
@param args: should be an empty list
|
1968 |
@rtype: int
|
1969 |
@return: the desired exit code
|
1970 |
|
1971 |
"""
|
1972 |
if ((not opts.resume and opts.to is None) |
1973 |
or (opts.resume and opts.to is not None)): |
1974 |
ToStderr("Precisely one of the options --to and --resume"
|
1975 |
" has to be given")
|
1976 |
return 1 |
1977 |
|
1978 |
if opts.resume:
|
1979 |
ssconf.CheckMaster(False)
|
1980 |
versionstring = _ReadIntentToUpgrade() |
1981 |
if versionstring is None: |
1982 |
return 0 |
1983 |
version = utils.version.ParseVersion(versionstring) |
1984 |
if version is None: |
1985 |
return 1 |
1986 |
configversion = _GetConfigVersion() |
1987 |
if configversion is None: |
1988 |
return 1 |
1989 |
# If the upgrade we resume was an upgrade between compatible
|
1990 |
# versions (like 2.10.0 to 2.10.1), the correct configversion
|
1991 |
# does not guarantee that the config has been updated.
|
1992 |
# However, in the case of a compatible update with the configuration
|
1993 |
# not touched, we are running a different dirversion with the same
|
1994 |
# config version.
|
1995 |
config_already_modified = \ |
1996 |
(utils.IsCorrectConfigVersion(version, configversion) and
|
1997 |
not (versionstring != constants.DIR_VERSION and |
1998 |
configversion == (constants.CONFIG_MAJOR, constants.CONFIG_MINOR, |
1999 |
constants.CONFIG_REVISION))) |
2000 |
if not config_already_modified: |
2001 |
# We have to start from the beginning; however, some daemons might have
|
2002 |
# already been stopped, so the only way to get into a well-defined state
|
2003 |
# is by starting all daemons again.
|
2004 |
_VerifyCommand([pathutils.DAEMON_UTIL, "start-all"])
|
2005 |
else:
|
2006 |
versionstring = opts.to |
2007 |
config_already_modified = False
|
2008 |
version = utils.version.ParseVersion(versionstring) |
2009 |
if version is None: |
2010 |
ToStderr("Could not parse version string %s" % versionstring)
|
2011 |
return 1 |
2012 |
|
2013 |
msg = utils.version.UpgradeRange(version) |
2014 |
if msg is not None: |
2015 |
ToStderr("Cannot upgrade to %s: %s" % (versionstring, msg))
|
2016 |
return 1 |
2017 |
|
2018 |
if not config_already_modified: |
2019 |
success, rollback = _UpgradeBeforeConfigurationChange(versionstring) |
2020 |
if not success: |
2021 |
_ExecuteCommands(rollback) |
2022 |
return 1 |
2023 |
else:
|
2024 |
rollback = [] |
2025 |
|
2026 |
downgrade = utils.version.ShouldCfgdowngrade(version) |
2027 |
|
2028 |
success, additionalrollback = \ |
2029 |
_SwitchVersionAndConfig(versionstring, downgrade) |
2030 |
if not success: |
2031 |
rollback.extend(additionalrollback) |
2032 |
_ExecuteCommands(rollback) |
2033 |
return 1 |
2034 |
|
2035 |
return _UpgradeAfterConfigurationChange()
|
2036 |
|
2037 |
|
2038 |
commands = { |
2039 |
"init": (
|
2040 |
InitCluster, [ArgHost(min=1, max=1)], |
2041 |
[BACKEND_OPT, CP_SIZE_OPT, ENABLED_HV_OPT, GLOBAL_FILEDIR_OPT, |
2042 |
HVLIST_OPT, MAC_PREFIX_OPT, MASTER_NETDEV_OPT, MASTER_NETMASK_OPT, |
2043 |
NIC_PARAMS_OPT, NOMODIFY_ETCHOSTS_OPT, NOMODIFY_SSH_SETUP_OPT, |
2044 |
SECONDARY_IP_OPT, VG_NAME_OPT, MAINTAIN_NODE_HEALTH_OPT, UIDPOOL_OPT, |
2045 |
DRBD_HELPER_OPT, DEFAULT_IALLOCATOR_OPT, DEFAULT_IALLOCATOR_PARAMS_OPT, |
2046 |
PRIMARY_IP_VERSION_OPT, PREALLOC_WIPE_DISKS_OPT, NODE_PARAMS_OPT, |
2047 |
GLOBAL_SHARED_FILEDIR_OPT, USE_EXTERNAL_MIP_SCRIPT, DISK_PARAMS_OPT, |
2048 |
HV_STATE_OPT, DISK_STATE_OPT, ENABLED_DISK_TEMPLATES_OPT, |
2049 |
IPOLICY_STD_SPECS_OPT, GLOBAL_GLUSTER_FILEDIR_OPT] |
2050 |
+ INSTANCE_POLICY_OPTS + SPLIT_ISPECS_OPTS, |
2051 |
"[opts...] <cluster_name>", "Initialises a new cluster configuration"), |
2052 |
"destroy": (
|
2053 |
DestroyCluster, ARGS_NONE, [YES_DOIT_OPT], |
2054 |
"", "Destroy cluster"), |
2055 |
"rename": (
|
2056 |
RenameCluster, [ArgHost(min=1, max=1)], |
2057 |
[FORCE_OPT, DRY_RUN_OPT], |
2058 |
"<new_name>",
|
2059 |
"Renames the cluster"),
|
2060 |
"redist-conf": (
|
2061 |
RedistributeConfig, ARGS_NONE, SUBMIT_OPTS + |
2062 |
[DRY_RUN_OPT, PRIORITY_OPT, FORCE_DISTRIBUTION], |
2063 |
"", "Forces a push of the configuration file and ssconf files" |
2064 |
" to the nodes in the cluster"),
|
2065 |
"verify": (
|
2066 |
VerifyCluster, ARGS_NONE, |
2067 |
[VERBOSE_OPT, DEBUG_SIMERR_OPT, ERROR_CODES_OPT, NONPLUS1_OPT, |
2068 |
DRY_RUN_OPT, PRIORITY_OPT, NODEGROUP_OPT, IGNORE_ERRORS_OPT], |
2069 |
"", "Does a check on the cluster configuration"), |
2070 |
"verify-disks": (
|
2071 |
VerifyDisks, ARGS_NONE, [PRIORITY_OPT], |
2072 |
"", "Does a check on the cluster disk status"), |
2073 |
"repair-disk-sizes": (
|
2074 |
RepairDiskSizes, ARGS_MANY_INSTANCES, [DRY_RUN_OPT, PRIORITY_OPT], |
2075 |
"[instance...]", "Updates mismatches in recorded disk sizes"), |
2076 |
"master-failover": (
|
2077 |
MasterFailover, ARGS_NONE, [NOVOTING_OPT, FORCE_FAILOVER], |
2078 |
"", "Makes the current node the master"), |
2079 |
"master-ping": (
|
2080 |
MasterPing, ARGS_NONE, [], |
2081 |
"", "Checks if the master is alive"), |
2082 |
"version": (
|
2083 |
ShowClusterVersion, ARGS_NONE, [], |
2084 |
"", "Shows the cluster version"), |
2085 |
"getmaster": (
|
2086 |
ShowClusterMaster, ARGS_NONE, [], |
2087 |
"", "Shows the cluster master"), |
2088 |
"copyfile": (
|
2089 |
ClusterCopyFile, [ArgFile(min=1, max=1)], |
2090 |
[NODE_LIST_OPT, USE_REPL_NET_OPT, NODEGROUP_OPT], |
2091 |
"[-n node...] <filename>", "Copies a file to all (or only some) nodes"), |
2092 |
"command": (
|
2093 |
RunClusterCommand, [ArgCommand(min=1)],
|
2094 |
[NODE_LIST_OPT, NODEGROUP_OPT, SHOW_MACHINE_OPT, FAILURE_ONLY_OPT], |
2095 |
"[-n node...] <command>", "Runs a command on all (or only some) nodes"), |
2096 |
"info": (
|
2097 |
ShowClusterConfig, ARGS_NONE, [ROMAN_OPT], |
2098 |
"[--roman]", "Show cluster configuration"), |
2099 |
"list-tags": (
|
2100 |
ListTags, ARGS_NONE, [], "", "List the tags of the cluster"), |
2101 |
"add-tags": (
|
2102 |
AddTags, [ArgUnknown()], [TAG_SRC_OPT, PRIORITY_OPT] + SUBMIT_OPTS, |
2103 |
"tag...", "Add tags to the cluster"), |
2104 |
"remove-tags": (
|
2105 |
RemoveTags, [ArgUnknown()], [TAG_SRC_OPT, PRIORITY_OPT] + SUBMIT_OPTS, |
2106 |
"tag...", "Remove tags from the cluster"), |
2107 |
"search-tags": (
|
2108 |
SearchTags, [ArgUnknown(min=1, max=1)], [PRIORITY_OPT], "", |
2109 |
"Searches the tags on all objects on"
|
2110 |
" the cluster for a given pattern (regex)"),
|
2111 |
"queue": (
|
2112 |
QueueOps, |
2113 |
[ArgChoice(min=1, max=1, choices=["drain", "undrain", "info"])], |
2114 |
[], "drain|undrain|info", "Change queue properties"), |
2115 |
"watcher": (
|
2116 |
WatcherOps, |
2117 |
[ArgChoice(min=1, max=1, choices=["pause", "continue", "info"]), |
2118 |
ArgSuggest(min=0, max=1, choices=["30m", "1h", "4h"])], |
2119 |
[], |
2120 |
"{pause <timespec>|continue|info}", "Change watcher properties"), |
2121 |
"modify": (
|
2122 |
SetClusterParams, ARGS_NONE, |
2123 |
[FORCE_OPT, |
2124 |
BACKEND_OPT, CP_SIZE_OPT, ENABLED_HV_OPT, HVLIST_OPT, MASTER_NETDEV_OPT, |
2125 |
MASTER_NETMASK_OPT, NIC_PARAMS_OPT, VG_NAME_OPT, MAINTAIN_NODE_HEALTH_OPT, |
2126 |
UIDPOOL_OPT, ADD_UIDS_OPT, REMOVE_UIDS_OPT, DRBD_HELPER_OPT, |
2127 |
DEFAULT_IALLOCATOR_OPT, DEFAULT_IALLOCATOR_PARAMS_OPT, RESERVED_LVS_OPT, |
2128 |
DRY_RUN_OPT, PRIORITY_OPT, PREALLOC_WIPE_DISKS_OPT, NODE_PARAMS_OPT, |
2129 |
USE_EXTERNAL_MIP_SCRIPT, DISK_PARAMS_OPT, HV_STATE_OPT, DISK_STATE_OPT] + |
2130 |
SUBMIT_OPTS + |
2131 |
[ENABLED_DISK_TEMPLATES_OPT, IPOLICY_STD_SPECS_OPT, MODIFY_ETCHOSTS_OPT] + |
2132 |
INSTANCE_POLICY_OPTS + [GLOBAL_FILEDIR_OPT], |
2133 |
"[opts...]",
|
2134 |
"Alters the parameters of the cluster"),
|
2135 |
"renew-crypto": (
|
2136 |
RenewCrypto, ARGS_NONE, |
2137 |
[NEW_CLUSTER_CERT_OPT, NEW_RAPI_CERT_OPT, RAPI_CERT_OPT, |
2138 |
NEW_CONFD_HMAC_KEY_OPT, FORCE_OPT, |
2139 |
NEW_CLUSTER_DOMAIN_SECRET_OPT, CLUSTER_DOMAIN_SECRET_OPT, |
2140 |
NEW_SPICE_CERT_OPT, SPICE_CERT_OPT, SPICE_CACERT_OPT], |
2141 |
"[opts...]",
|
2142 |
"Renews cluster certificates, keys and secrets"),
|
2143 |
"epo": (
|
2144 |
Epo, [ArgUnknown()], |
2145 |
[FORCE_OPT, ON_OPT, GROUPS_OPT, ALL_OPT, OOB_TIMEOUT_OPT, |
2146 |
SHUTDOWN_TIMEOUT_OPT, POWER_DELAY_OPT], |
2147 |
"[opts...] [args]",
|
2148 |
"Performs an emergency power-off on given args"),
|
2149 |
"activate-master-ip": (
|
2150 |
ActivateMasterIp, ARGS_NONE, [], "", "Activates the master IP"), |
2151 |
"deactivate-master-ip": (
|
2152 |
DeactivateMasterIp, ARGS_NONE, [CONFIRM_OPT], "",
|
2153 |
"Deactivates the master IP"),
|
2154 |
"show-ispecs-cmd": (
|
2155 |
ShowCreateCommand, ARGS_NONE, [], "",
|
2156 |
"Show the command line to re-create the cluster"),
|
2157 |
"upgrade": (
|
2158 |
UpgradeGanetiCommand, ARGS_NONE, [TO_OPT, RESUME_OPT], "",
|
2159 |
"Upgrade (or downgrade) to a new Ganeti version"),
|
2160 |
} |
2161 |
|
2162 |
|
2163 |
#: dictionary with aliases for commands
|
2164 |
aliases = { |
2165 |
"masterfailover": "master-failover", |
2166 |
"show": "info", |
2167 |
} |
2168 |
|
2169 |
|
2170 |
def Main(): |
2171 |
return GenericMain(commands, override={"tag_type": constants.TAG_CLUSTER}, |
2172 |
aliases=aliases) |