Well, I guess that means Asterix and Obelix have won then. LGTM

On Wed, Apr 3, 2013 at 6:02 PM, Bernardo Dal Seno <[email protected]>wrote:

> The new function can be used for group-level instance policies. Support for
> roman numeral formatting has been dropped to make the code simpler. For
> other info items is already not supported, and it's not exactly documented
> anyway.
>
> Signed-off-by: Bernardo Dal Seno <[email protected]>
> ---
>  lib/cli.py                | 52
> +++++++++++++++++++++++++++++++++++++++++++++++
>  lib/client/gnt_cluster.py | 18 +---------------
>  2 files changed, 53 insertions(+), 17 deletions(-)
>
> diff --git a/lib/cli.py b/lib/cli.py
> index 0e7918a..fea2c1d 100644
> --- a/lib/cli.py
> +++ b/lib/cli.py
> @@ -236,6 +236,7 @@ __all__ = [
>    "FormatQueryResult",
>    "FormatParameterDict",
>    "FormatParamsDictInfo",
> +  "FormatPolicyInfo",
>    "PrintGenericInfo",
>    "GenerateTable",
>    "AskUser",
> @@ -3639,6 +3640,57 @@ def FormatParamsDictInfo(param_dict, actual):
>    return ret
>
>
> +def _FormatListInfoDefault(data, def_data):
> +  if data is not None:
> +    ret = utils.CommaJoin(data)
> +  else:
> +    ret = "default (%s)" % utils.CommaJoin(def_data)
> +  return ret
> +
> +
> +def FormatPolicyInfo(custom_ipolicy, eff_ipolicy, iscluster):
> +  """Formats an instance policy.
> +
> +  @type custom_ipolicy: dict
> +  @param custom_ipolicy: own policy
> +  @type eff_ipolicy: dict
> +  @param eff_ipolicy: effective policy (including defaults); ignored for
> +      cluster
> +  @type iscluster: bool
> +  @param iscluster: the policy is at cluster level
> +  @rtype: list of pairs
> +  @return: formatted data, suitable for L{PrintGenericInfo}
> +
> +  """
> +  if iscluster:
> +    eff_ipolicy = custom_ipolicy
> +
> +  custom_minmax = custom_ipolicy.get(constants.ISPECS_MINMAX)
> +  ret = [
> +    (key,
> +     FormatParamsDictInfo(custom_minmax.get(key, {}),
> +                          eff_ipolicy[constants.ISPECS_MINMAX][key]))
> +    for key in constants.ISPECS_MINMAX_KEYS
> +    ]
> +  if iscluster:
> +    stdspecs = custom_ipolicy[constants.ISPECS_STD]
> +    ret.append(
> +      (constants.ISPECS_STD,
> +       FormatParamsDictInfo(stdspecs, stdspecs))
> +      )
> +
> +  ret.append(
> +    ("enabled disk templates",
> +     _FormatListInfoDefault(custom_ipolicy.get(constants.IPOLICY_DTS),
> +                            eff_ipolicy[constants.IPOLICY_DTS]))
> +    )
> +  ret.extend([
> +    (key, str(custom_ipolicy.get(key, "default (%s)" % eff_ipolicy[key])))
> +    for key in constants.IPOLICY_PARAMETERS
> +    ])
> +  return ret
> +
> +
>  def ConfirmOperation(names, list_type, text, extra=""):
>    """Ask the user to confirm an operation on a list of list_type.
>
> diff --git a/lib/client/gnt_cluster.py b/lib/client/gnt_cluster.py
> index bbee602..e44f834 100644
> --- a/lib/client/gnt_cluster.py
> +++ b/lib/client/gnt_cluster.py
> @@ -474,23 +474,7 @@ def ShowClusterConfig(opts, args):
>       _FormatGroupedParams(result["diskparams"],
> roman=opts.roman_integers)),
>
>      ("Instance policy - limits for instances",
> -     [
> -       (key,
> -
>  _FormatGroupedParams(result["ipolicy"][constants.ISPECS_MINMAX][key],
> -                             roman=opts.roman_integers))
> -       for key in constants.ISPECS_MINMAX_KEYS
> -       ] +
> -     [
> -       (constants.ISPECS_STD,
> -        _FormatGroupedParams(result["ipolicy"][constants.ISPECS_STD],
> -                             roman=opts.roman_integers)),
> -       ("enabled disk templates",
> -        utils.CommaJoin(result["ipolicy"][constants.IPOLICY_DTS])),
> -       ] +
> -     [
> -       (key, result["ipolicy"][key])
> -       for key in constants.IPOLICY_PARAMETERS
> -       ]),
> +     FormatPolicyInfo(result["ipolicy"], None, True)),
>      ]
>
>    PrintGenericInfo(info)
> --
> 1.8.1.3
>
>

Reply via email to