X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/ae5b15305e215ef5f52126784af4b9a0d7d86d5c..b44bd844c54573e7801fc1ef6b4f8007f193555d:/scripts/gnt-os diff --git a/scripts/gnt-os b/scripts/gnt-os index d0df8d2..f74213a 100755 --- a/scripts/gnt-os +++ b/scripts/gnt-os @@ -1,7 +1,7 @@ #!/usr/bin/python # -# Copyright (C) 2006, 2007 Google Inc. +# Copyright (C) 2006, 2007, 2010 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ import sys from ganeti.cli import * +from ganeti import constants from ganeti import opcodes from ganeti import utils @@ -43,8 +44,7 @@ def ListOS(opts, args): @return: the desired exit code """ - op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants"], - names=[]) + op = opcodes.OpDiagnoseOS(output_fields=["name", "variants"], names=[]) result = SubmitOpCode(op, opts=opts) if not result: @@ -57,9 +57,8 @@ def ListOS(opts, args): headers = None os_names = [] - for (name, valid, variants) in result: - if valid: - os_names.extend([[n] for n in CalculateOSNames(name, variants)]) + for (name, variants) in result: + os_names.extend([[n] for n in CalculateOSNames(name, variants)]) data = GenerateTable(separator=None, headers=headers, fields=["name"], data=os_names, units=None) @@ -81,7 +80,8 @@ def ShowOSInfo(opts, args): """ op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants", - "parameters", "api_versions"], + "parameters", "api_versions", + "blacklisted", "hidden"], names=[]) result = SubmitOpCode(op, opts=opts) @@ -91,7 +91,7 @@ def ShowOSInfo(opts, args): do_filter = bool(args) - for (name, valid, variants, parameters, api_versions) in result: + for (name, valid, variants, parameters, api_versions, blk, hid) in result: if do_filter: if name not in args: continue @@ -99,6 +99,8 @@ def ShowOSInfo(opts, args): args.remove(name) ToStdout("%s:", name) ToStdout(" - valid: %s", valid) + ToStdout(" - hidden: %s", hid) + ToStdout(" - blacklisted: %s", blk) if valid: ToStdout(" - API versions:") for version in sorted(api_versions): @@ -135,6 +137,7 @@ def _OsStatus(status, diagnose): else: return "invalid - %s" % diagnose + def DiagnoseOS(opts, args): """Analyse all OSes on this cluster. @@ -146,7 +149,8 @@ def DiagnoseOS(opts, args): """ op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants", - "node_status"], names=[]) + "node_status", "hidden", + "blacklisted"], names=[]) result = SubmitOpCode(op, opts=opts) if not result: @@ -155,25 +159,38 @@ def DiagnoseOS(opts, args): has_bad = False - for os_name, _, os_variants, node_data in result: + for os_name, _, os_variants, node_data, hid, blk in result: nodes_valid = {} nodes_bad = {} nodes_hidden = {} for node_name, node_info in node_data.iteritems(): nodes_hidden[node_name] = [] if node_info: # at least one entry in the per-node list - (first_os_path, first_os_status, first_os_msg, - first_os_variants, _, first_os_api) = node_info.pop(0) - if not first_os_variants: - first_os_variants = [] - first_os_msg = ("%s (path: %s) [variants: %s] [api: %s]" % - (_OsStatus(first_os_status, first_os_msg), - first_os_path, utils.CommaJoin(first_os_variants), - utils.CommaJoin(first_os_api))) - if first_os_status: - nodes_valid[node_name] = first_os_msg + (fo_path, fo_status, fo_msg, fo_variants, + fo_params, fo_api) = node_info.pop(0) + fo_msg = "%s (path: %s)" % (_OsStatus(fo_status, fo_msg), fo_path) + if fo_api: + max_os_api = max(fo_api) + fo_msg += " [API versions: %s]" % utils.CommaJoin(fo_api) else: - nodes_bad[node_name] = first_os_msg + max_os_api = 0 + fo_msg += " [no API versions declared]" + + if max_os_api >= constants.OS_API_V15: + if fo_variants: + fo_msg += " [variants: %s]" % utils.CommaJoin(fo_variants) + else: + fo_msg += " [no variants]" + if max_os_api >= constants.OS_API_V20: + if fo_params: + fo_msg += (" [parameters: %s]" % + utils.CommaJoin([v[0] for v in fo_params])) + else: + fo_msg += " [no parameters]" + if fo_status: + nodes_valid[node_name] = fo_msg + else: + nodes_bad[node_name] = fo_msg for hpath, hstatus, hmsg, _, _, _ in node_info: nodes_hidden[node_name].append(" [hidden] path: %s, status: %s" % (hpath, _OsStatus(hstatus, hmsg))) @@ -196,7 +213,12 @@ def DiagnoseOS(opts, args): for msg in nodes_hidden[node_name]: ToStdout(msg) - ToStdout("OS: %s [global status: %s]", os_name, status) + st_msg = "OS: %s [global status: %s]" % (os_name, status) + if hid: + st_msg += " [hidden]" + if blk: + st_msg += " [blacklisted]" + ToStdout(st_msg) if os_variants: ToStdout(" Variants: [%s]" % utils.CommaJoin(os_variants)) _OutputPerNodeOSStatus(nodes_valid) @@ -228,36 +250,52 @@ def ModifyOS(opts, args): else: osp = None - if not (os_hvp or osp): + if opts.hidden is not None: + if opts.hidden: + ohid = [(constants.DDM_ADD, os)] + else: + ohid = [(constants.DDM_REMOVE, os)] + else: + ohid = None + + if opts.blacklisted is not None: + if opts.blacklisted: + oblk = [(constants.DDM_ADD, os)] + else: + oblk = [(constants.DDM_REMOVE, os)] + else: + oblk = None + + if not (os_hvp or osp or ohid or oblk): ToStderr("At least one of OS parameters or hypervisor parameters" " must be passed") return 1 - op = opcodes.OpSetClusterParams(vg_name=None, - enabled_hypervisors=None, - hvparams=None, - beparams=None, - nicparams=None, - candidate_pool_size=None, - os_hvp=os_hvp, - osparams=osp) - SubmitOpCode(op) + op = opcodes.OpSetClusterParams(os_hvp=os_hvp, + osparams=osp, + hidden_os=ohid, + blacklisted_os=oblk) + SubmitOpCode(op, opts=opts) return 0 commands = { 'list': ( - ListOS, ARGS_NONE, [NOHDR_OPT], "", "Lists all valid operating systems" - " on the cluster"), + ListOS, ARGS_NONE, [NOHDR_OPT, PRIORITY_OPT], + "", "Lists all valid operating systems on the cluster"), 'diagnose': ( - DiagnoseOS, ARGS_NONE, [], "", "Diagnose all operating systems"), + DiagnoseOS, ARGS_NONE, [PRIORITY_OPT], + "", "Diagnose all operating systems"), 'info': ( - ShowOSInfo, [ArgOs()], [], "", "Show detailed information about " + ShowOSInfo, [ArgOs()], [PRIORITY_OPT], + "", "Show detailed information about " "operating systems"), 'modify': ( - ModifyOS, ARGS_ONE_OS, [HVLIST_OPT, OSPARAMS_OPT], "", - "Modify the OS parameters"), + ModifyOS, ARGS_ONE_OS, + [HVLIST_OPT, OSPARAMS_OPT, DRY_RUN_OPT, PRIORITY_OPT, + HID_OS_OPT, BLK_OS_OPT], + "", "Modify the OS parameters"), } if __name__ == '__main__':