On Wed, Aug 05, 2009 at 02:05:06PM +0100, Luca Bigliardi wrote:
>
> Having a list of primary/secondary IPs of all the nodes in ssconf can be
> useful
> for scripts/hooks which need to automatically configure network properties for
> the whole cluster (e.g.: ipsec/netfilter rules) without relying on a
> working DNS.
>
> Signed-off-by: Luca Bigliardi <[email protected]>
> ---
> lib/config.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
> lib/constants.py | 2 ++
> lib/ssconf.py | 18 ++++++++++++++++++
> 3 files changed, 67 insertions(+), 1 deletions(-)
>
> diff --git a/lib/config.py b/lib/config.py
> index ba4bbdf..7f58cda 100644
> --- a/lib/config.py
> +++ b/lib/config.py
> @@ -886,6 +886,42 @@ class ConfigWriter:
> return utils.MatchNameComponent(short_name,
> self._config_data.nodes.keys())
>
> + def _UnlockedGetNodePrimaryIP(self, node_name):
> + """Get the primary IP of a node, as stored in the config.
> +
> + This function is for internal use, when the config lock is already
> + held.
> +
> + @param node_name: the node name, e.g. I{node1.example.com}
> +
> + @rtype: string
> + @return: primary IP of a node
> +
> + """
> + if node_name not in self._config_data.nodes:
> + return None
> +
> + return self._config_data.nodes[node_name].primary_ip
> +
> +
> + def _UnlockedGetNodeSecondaryIP(self, node_name):
> + """Get the secondary IP of a node, as stored in the config.
> +
> + This function is for internal use, when the config lock is already
> + held.
> +
> + @param node_name: the node name, e.g. I{node1.example.com}
> +
> + @rtype: string
> + @return: secondary IP of a node
> +
> + """
> + if node_name not in self._config_data.nodes:
> + return None
> +
> + return self._config_data.nodes[node_name].secondary_ip
> +
> +
> def _UnlockedGetNodeInfo(self, node_name):
> """Get the configuration of a node, as stored in the config.
>
> @@ -1147,13 +1183,21 @@ class ConfigWriter:
> fn = "\n".join
> instance_names = utils.NiceSort(self._UnlockedGetInstanceList())
> node_names = utils.NiceSort(self._UnlockedGetNodeList())
> - node_info = [self._UnlockedGetNodeInfo(name) for name in node_names]
> + node_info = []
> + node_pri_ips = []
> + node_snd_ips = []
> + for node_name in node_names:
> + node_info.append(self._UnlockedGetNodeInfo(node_name))
> + node_pri_ips.append(self._UnlockedGetNodePrimaryIP(node_name))
> + node_snd_ips.append(self._UnlockedGetNodeSecondaryIP(node_name))
Uh, simplification maybe?:
for node_name in node_names:
ni = self._UnlockedGetNodeInfo(node_name)
node_info.append(ni)
node_pri_ips.append(ni.primary_ip)
node_snd_ips.append(ni.secondary_ip)
And then you don't need two new functions.
Plus, you're half way into Guido's patch from yesterday about optimising
this, so why not go 100% (and change off_data, on_data, mc_data to be
the same).
thanks,
iustin