On Tue, Feb 04, 2014 at 05:00:22PM +0100, Santi Raffa wrote:
> We do not want public, private and secret parameters to have
> overlapping keys. This function implements this check.
>
> Signed-off-by: Santi Raffa <[email protected]>
> ---
> lib/rpc_defs.py | 10 +++++-----
> lib/utils/algo.py | 28 ++++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py
> index fbeec1d..7fbbc16 100644
> --- a/lib/rpc_defs.py
> +++ b/lib/rpc_defs.py
> @@ -288,12 +288,12 @@ _INSTANCE_CALLS = [
> ("reason", None, "The reason for the startup"),
> ], None, None, "Starts an instance"),
> ("instance_os_add", SINGLE, None, constants.RPC_TMO_1DAY, [
> - ("instance_osp", ED_INST_DICT_OSP_DP, "Tuple: target instance,"
> + ("instance_osp", ED_INST_DICT_OSP_DP, "Tuple: (target instance,"
> " temporary OS parameters"
> - " overriding configuration."),
> - ("reinstall", None, "Whether the instance is being reinstalled."),
> - ("debug", None, None),
> - ], None, None, "Installs an OS onto an instance"),
> + " overriding configuration)"),
> + ("reinstall", None, "Whether the instance is being reinstalled"),
> + ("debug", None, "Debug level for the OS install script to use"),
> + ], None, None, "Installs an operative system onto an instance"),
This should go with the first patch.
> ("hotplug_device", SINGLE, None, constants.RPC_TMO_NORMAL, [
> ("instance", ED_INST_DICT, "Instance object"),
> ("action", None, "Hotplug Action"),
> diff --git a/lib/utils/algo.py b/lib/utils/algo.py
> index b436f5a..a0d1fc3 100644
> --- a/lib/utils/algo.py
> +++ b/lib/utils/algo.py
> @@ -95,6 +95,34 @@ def FindDuplicates(seq):
> return list(dup)
>
>
> +#pylint: disable=W0142
> +def GetRepeatedKeys(*dicts):
> + """Return the set of keys defined multiple times in the given dicts.
> +
> + >>> GetRepeatedKeys({"foo": 1, "bar": 2},
> + ... {"foo": 5, "baz": 7}
> + ... )
> + set("foo")
Please see ganeti.baserlib.MapFields for an example on how to make an
example docstring.
> + @type dicts: dict
> + @param dicts: The dictionaries to check for duplicate keys.
Remove trailing period.
> + @rtype: set
> + @return: Keys used more than once across all dicts
The first argument starts with an article (i.e., "The") the second
doesn't. It should be consistent. Also, it should not be
capitalized.
> + """
> +
> + if len(dicts) < 2:
> + return set()
> +
> + # It is trivial to generalize this function to more than just dicts
> + # by changing the .keys() call to another "for key in dictionary"
> + keys = [set(dictionary.keys()) for dictionary in dicts]
> + return set.union(*[x & y
> + for x in keys
> + for y in keys
> + if x is not y])
Can't we just use set.intersection and give it a sequence of iterables?
Something like,
set.intersection(*keyss)
Thanks,
Jose
> +
> def _NiceSortTryInt(val):
> """Attempts to convert a string to an integer.
>
> --
> 1.9.0.rc1.175.g0b1dcb5
>
--
Jose Antonio Lopes
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores
Steuernummer: 48/725/00206
Umsatzsteueridentifikationsnummer: DE813741370