Revision acd9ff9e
b/daemons/ganeti-noded | ||
---|---|---|
712 | 712 |
os_obj = backend.OSFromDisk(name) |
713 | 713 |
return os_obj.ToDict() |
714 | 714 |
|
715 |
@staticmethod |
|
716 |
def perspective_os_validate(params): |
|
717 |
"""Run a given OS' validation routine. |
|
718 |
|
|
719 |
""" |
|
720 |
required, name, checks, params = params |
|
721 |
return backend.ValidateOS(required, name, checks, params) |
|
722 |
|
|
715 | 723 |
# hooks ----------------------- |
716 | 724 |
|
717 | 725 |
@staticmethod |
b/lib/backend.py | ||
---|---|---|
2457 | 2457 |
_Fail(str(err), log=False) |
2458 | 2458 |
|
2459 | 2459 |
|
2460 |
def _CheckOSPList(os_obj, parameters): |
|
2461 |
"""Check whether a list of parameters is supported by the OS. |
|
2462 |
|
|
2463 |
@type os_obj: L{objects.OS} |
|
2464 |
@param os_obj: OS object to check |
|
2465 |
@type parameters: list |
|
2466 |
@param parameters: the list of parameters to check |
|
2467 |
|
|
2468 |
""" |
|
2469 |
supported = [v[0] for v in os_obj.supported_parameters] |
|
2470 |
delta = frozenset(parameters).difference(supported) |
|
2471 |
if delta: |
|
2472 |
_Fail("The following parameters are not supported" |
|
2473 |
" by the OS %s: %s" % (os_obj.name, utils.CommaJoin(delta))) |
|
2474 |
|
|
2475 |
|
|
2476 |
def ValidateOS(required, osname, checks, osparams): |
|
2477 |
"""Validate the given OS' parameters. |
|
2478 |
|
|
2479 |
@type required: boolean |
|
2480 |
@param required: whether absence of the OS should translate into |
|
2481 |
failure or not |
|
2482 |
@type osname: string |
|
2483 |
@param osname: the OS to be validated |
|
2484 |
@type checks: list |
|
2485 |
@param checks: list of the checks to run (currently only 'parameters') |
|
2486 |
@type osparams: dict |
|
2487 |
@param osparams: dictionary with OS parameters |
|
2488 |
@rtype: boolean |
|
2489 |
@return: True if the validation passed, or False if the OS was not |
|
2490 |
found and L{required} was false |
|
2491 |
|
|
2492 |
""" |
|
2493 |
if not constants.OS_VALIDATE_CALLS.issuperset(checks): |
|
2494 |
_Fail("Unknown checks required for OS %s: %s", osname, |
|
2495 |
set(checks).difference(constants.OS_VALIDATE_CALLS)) |
|
2496 |
|
|
2497 |
name_only = osname.split("+", 1)[0] |
|
2498 |
status, tbv = _TryOSFromDisk(name_only, None) |
|
2499 |
|
|
2500 |
if not status: |
|
2501 |
if required: |
|
2502 |
_Fail(tbv) |
|
2503 |
else: |
|
2504 |
return False |
|
2505 |
|
|
2506 |
if constants.OS_VALIDATE_PARAMETERS in checks: |
|
2507 |
_CheckOSPList(tbv, osparams.keys()) |
|
2508 |
|
|
2509 |
validate_env = OSCoreEnv(tbv, osparams) |
|
2510 |
result = utils.RunCmd([tbv.verify_script] + checks, env=validate_env, |
|
2511 |
cwd=tbv.path) |
|
2512 |
if result.failed: |
|
2513 |
logging.error("os validate command '%s' returned error: %s output: %s", |
|
2514 |
result.cmd, result.fail_reason, result.output) |
|
2515 |
_Fail("OS validation script failed (%s), output: %s", |
|
2516 |
result.fail_reason, result.output, log=False) |
|
2517 |
|
|
2518 |
return True |
|
2519 |
|
|
2520 |
|
|
2460 | 2521 |
def DemoteFromMC(): |
2461 | 2522 |
"""Demotes the current node from master candidate role. |
2462 | 2523 |
|
b/lib/cmdlib.py | ||
---|---|---|
6091 | 6091 |
info.Raise("Hypervisor parameter validation failed on node %s" % node) |
6092 | 6092 |
|
6093 | 6093 |
|
6094 |
def _CheckOSParams(lu, required, nodenames, osname, osparams): |
|
6095 |
"""OS parameters validation. |
|
6096 |
|
|
6097 |
@type lu: L{LogicalUnit} |
|
6098 |
@param lu: the logical unit for which we check |
|
6099 |
@type required: boolean |
|
6100 |
@param required: whether the validation should fail if the OS is not |
|
6101 |
found |
|
6102 |
@type nodenames: list |
|
6103 |
@param nodenames: the list of nodes on which we should check |
|
6104 |
@type osname: string |
|
6105 |
@param osname: the name of the hypervisor we should use |
|
6106 |
@type osparams: dict |
|
6107 |
@param osparams: the parameters which we need to check |
|
6108 |
@raise errors.OpPrereqError: if the parameters are not valid |
|
6109 |
|
|
6110 |
""" |
|
6111 |
result = lu.rpc.call_os_validate(required, nodenames, osname, |
|
6112 |
[constants.OS_VALIDATE_PARAMETERS], |
|
6113 |
osparams) |
|
6114 |
for node, nres in result.items(): |
|
6115 |
# we don't check for offline cases since this should be run only |
|
6116 |
# against the master node and/or an instance's nodes |
|
6117 |
nres.Raise("OS Parameters validation failed on node %s" % node) |
|
6118 |
if not nres.payload: |
|
6119 |
lu.LogInfo("OS %s not found on node %s, validation skipped", |
|
6120 |
osname, node) |
|
6121 |
|
|
6122 |
|
|
6094 | 6123 |
class LUCreateInstance(LogicalUnit): |
6095 | 6124 |
"""Create an instance. |
6096 | 6125 |
|
b/lib/constants.py | ||
---|---|---|
459 | 459 |
OS_PARAMETERS_FILE = 'parameters.list' |
460 | 460 |
|
461 | 461 |
OS_VALIDATE_PARAMETERS = 'parameters' |
462 |
OS_VALIDATE_CALLS = frozenset([OS_VALIDATE_PARAMETERS]) |
|
462 | 463 |
|
463 | 464 |
# ssh constants |
464 | 465 |
SSH_CONFIG_DIR = _autoconf.SSH_CONFIG_DIR |
b/lib/rpc.py | ||
---|---|---|
1046 | 1046 |
result.payload = objects.OS.FromDict(result.payload) |
1047 | 1047 |
return result |
1048 | 1048 |
|
1049 |
@_RpcTimeout(_TMO_FAST) |
|
1050 |
def call_os_validate(self, required, nodes, name, checks, params): |
|
1051 |
"""Run a validation routine for a given OS. |
|
1052 |
|
|
1053 |
This is a multi-node call. |
|
1054 |
|
|
1055 |
""" |
|
1056 |
return self._MultiNodeCall(nodes, "os_validate", |
|
1057 |
[required, name, checks, params]) |
|
1058 |
|
|
1049 | 1059 |
@_RpcTimeout(_TMO_NORMAL) |
1050 | 1060 |
def call_hooks_runner(self, node_list, hpath, phase, env): |
1051 | 1061 |
"""Call the hooks runner. |
Also available in: Unified diff