[ClusterLabs] Added optional parameter "name" to "crm corosync add-node"
Andrei Maruha
Andrei_Maruha at epam.com
Wed Jan 27 13:45:52 CET 2016
Hi,
Attached patch contains functionality to add parameter "name" to "crm
corosync add-node".
May be it will be useful for someone else, because Pacemaker tries to
get "name" parameter in case if "ring0_addr" contains ip address
(https://github.com/ClusterLabs/pacemaker/blob/master/lib/cluster/corosync.c).
Best Regards,
Andrei Maruha
/__/
-------------- next part --------------
commit 097f26cbbc41fe61e5fff8fece243ed4337ac75d
Author: Andrei Maruha <Andrei_Maruha at epam.com>
Date: Wed Jan 27 13:53:22 2016 +0300
added optional parameter [name] to "corosync add-node" function
Parameter "name" in section "nodelist" of corosync.conf is used by
Pacemaker if parameter "ring0_addr" contains ip address instead of
hostname.
diff --git a/doc/crm.8.adoc b/doc/crm.8.adoc
index f874cc2..3d8b35d 100644
--- a/doc/crm.8.adoc
+++ b/doc/crm.8.adoc
@@ -1211,7 +1211,7 @@ sets only the address for ring0.
Usage:
.........
-add-node <addr>
+add-node <addr> [name]
.........
[[cmdhelp_corosync_del-node,Remove a corosync node]]
diff --git a/modules/corosync.py b/modules/corosync.py
index cba061f..5c7080d 100644
--- a/modules/corosync.py
+++ b/modules/corosync.py
@@ -368,35 +368,45 @@ def set_value(path, value):
f.close()
-def add_node(name):
+def add_node(addr, name=None):
'''
Add node to corosync.conf
'''
coronodes = None
nodes = None
+ nodenames = None
coronodes = utils.list_corosync_nodes()
+ nodenames = utils.list_corosync_node_names()
try:
nodes = utils.list_cluster_nodes()
except Exception:
nodes = []
- ipaddr = get_ip(name)
- if name in coronodes or (ipaddr and ipaddr in coronodes):
+ ipaddr = get_ip(addr)
+ if addr in nodenames + coronodes or (ipaddr and ipaddr in coronodes):
+ err_buf.warning("%s already in corosync.conf" % (addr))
+ return
+ if name and name in nodenames + coronodes:
err_buf.warning("%s already in corosync.conf" % (name))
return
- if name in nodes:
+ if addr in nodes:
+ err_buf.warning("%s already in configuration" % (addr))
+ return
+ if name and name in nodes:
err_buf.warning("%s already in configuration" % (name))
return
f = open(conf()).read()
p = Parser(f)
- node_addr = name
+ node_addr = addr
node_id = next_nodeid(p)
+ node_name = name
+ node_value = (make_value('nodelist.node.ring0_addr', node_addr) +
+ make_value('nodelist.node.nodeid', str(node_id)))
+ if node_name:
+ node_value += make_value('nodelist.node.name', node_name)
- p.add('nodelist',
- make_section('nodelist.node',
- make_value('nodelist.node.ring0_addr', node_addr) +
- make_value('nodelist.node.nodeid', str(node_id))))
+ p.add('nodelist', make_section('nodelist.node', node_value))
num_nodes = p.count('nodelist.node')
if num_nodes > 2:
@@ -414,6 +424,10 @@ def add_node(name):
utils.ext_cmd(["corosync-cmapctl",
"-s", "nodelist.node.%s.ring0_addr" % (num_nodes - 1),
"str", node_addr], shell=False)
+ if node_name:
+ utils.ext_cmd(["corosync-cmapctl",
+ "-s", "nodelist.node.%s.name" % (num_nodes - 1),
+ "str", node_name], shell=False)
def del_node(addr):
@@ -443,3 +457,5 @@ def del_node(addr):
shell=False)
utils.ext_cmd(["corosync-cmapctl", "-D", "nodelist.node.%s.ring0_addr" % (nth)],
shell=False)
+ utils.ext_cmd(["corosync-cmapctl", "-D", "nodelist.node.%s.name" % (nth)],
+ shell=False)
diff --git a/modules/ui_corosync.py b/modules/ui_corosync.py
index 771acdf..0dec867 100644
--- a/modules/ui_corosync.py
+++ b/modules/ui_corosync.py
@@ -120,9 +120,9 @@ class Corosync(command.UI):
@command.name('add-node')
@command.alias('add_node')
@command.skill_level('administrator')
- def do_addnode(self, context, name):
+ def do_addnode(self, context, addr, name=None):
"Add a node to the corosync nodelist"
- corosync.add_node(name)
+ corosync.add_node(addr, name)
@command.name('del-node')
@command.alias('del_node')
diff --git a/modules/utils.py b/modules/utils.py
index e958c8a..05db843 100644
--- a/modules/utils.py
+++ b/modules/utils.py
@@ -1337,6 +1337,25 @@ def resolve_hostnames(hostnames):
return True, None
+def list_corosync_node_names():
+ '''
+ Returns list of nodes configured
+ in corosync.conf
+ '''
+ try:
+ cfg = os.getenv('COROSYNC_MAIN_CONFIG_FILE', '/etc/corosync/corosync.conf')
+ lines = open(cfg).read().split('\n')
+ name_re = re.compile(r'\s*name:\s+(.*)')
+ names = []
+ for line in lines:
+ name = name_re.match(line)
+ if name:
+ names.append(name.group(1))
+ return names
+ except Exception:
+ return []
+
+
def list_corosync_nodes():
'''
Returns list of nodes configured
More information about the Users
mailing list