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)) instance_data = fn(instance_names) off_data = fn(node.name for node in node_info if node.offline) on_data = fn(node.name for node in node_info if not node.offline) mc_data = fn(node.name for node in node_info if node.master_candidate) node_data = fn(node_names) + node_pri_ips_data = fn(node_pri_ips) + node_snd_ips_data = fn(node_snd_ips) cluster = self._config_data.cluster cluster_tags = fn(cluster.GetTags()) @@ -1166,6 +1210,8 @@ class ConfigWriter: constants.SS_MASTER_NETDEV: cluster.master_netdev, constants.SS_MASTER_NODE: cluster.master_node, constants.SS_NODE_LIST: node_data, + constants.SS_NODE_PRIMARY_IPS: node_pri_ips_data, + constants.SS_NODE_SECONDARY_IPS: node_snd_ips_data, constants.SS_OFFLINE_NODES: off_data, constants.SS_ONLINE_NODES: on_data, constants.SS_INSTANCE_LIST: instance_data, diff --git a/lib/constants.py b/lib/constants.py index 09f7917..95c3898 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -545,6 +545,8 @@ SS_MASTER_IP = "master_ip" SS_MASTER_NETDEV = "master_netdev" SS_MASTER_NODE = "master_node" SS_NODE_LIST = "node_list" +SS_NODE_PRIMARY_IPS = "node_primary_ips" +SS_NODE_SECONDARY_IPS = "node_secondary_ips" SS_OFFLINE_NODES = "offline_nodes" SS_ONLINE_NODES = "online_nodes" SS_INSTANCE_LIST = "instance_list" diff --git a/lib/ssconf.py b/lib/ssconf.py index 93c057d..6e69eb0 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -101,6 +101,8 @@ class SimpleStore(object): constants.SS_MASTER_NETDEV, constants.SS_MASTER_NODE, constants.SS_NODE_LIST, + constants.SS_NODE_PRIMARY_IPS, + constants.SS_NODE_SECONDARY_IPS, constants.SS_OFFLINE_NODES, constants.SS_ONLINE_NODES, constants.SS_INSTANCE_LIST, @@ -214,6 +216,22 @@ class SimpleStore(object): nl = data.splitlines(False) return nl + def GetNodePrimaryIPList(self): + """Return the list of cluster nodes' primary IP. + + """ + data = self._ReadFile(constants.SS_NODE_PRIMARY_IPS) + nl = data.splitlines(False) + return nl + + def GetNodeSecondaryIPList(self): + """Return the list of cluster nodes' secondary IP. + + """ + data = self._ReadFile(constants.SS_NODE_SECONDARY_IPS) + nl = data.splitlines(False) + return nl + def GetClusterTags(self): """Return the cluster tags. -- 1.5.4.3
