2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-09-01 23:16:05 +00:00

Block user from naming group/node the same thing

If a node and a group have the same name, things can get very confusing and hard to deal with.
This commit is contained in:
Jarrod Johnson
2026-08-25 10:47:39 -04:00
parent 7a0a2d0e48
commit 8a57216803
2 changed files with 13 additions and 5 deletions
@@ -2023,7 +2023,11 @@ class ConfigManager(object):
continue # next node, this node already in
self._node_added_to_group(node, group, changeset)
async def add_group_attributes(self, attribmap):
async def add_group_attributes(self, attribmap, checkconflict=False):
if checkconflict:
for groupname in attribmap:
if groupname in self._cfgstore.get('nodes', {}):
raise ValueError('Group "{}" conflicts with an existing node'.format(groupname))
await self.set_group_attributes(attribmap, autocreate=True)
async def set_group_attributes(self, attribmap, autocreate=False, merge="replace", keydata=None, skipped=None):
@@ -2422,7 +2426,11 @@ class ConfigManager(object):
self._notif_attribwatchers(changeset)
self._bg_sync_to_file()
async def add_node_attributes(self, attribmap):
async def add_node_attributes(self, attribmap, checkconflict=False):
if checkconflict:
for nodename in attribmap:
if nodename in self._cfgstore.get('nodegroups', {}):
raise ValueError('Node "{}" conflicts with an existing group'.format(nodename))
await self.set_node_attributes(attribmap, autocreate=True)
async def rename_nodes(self, renamemap):
+3 -3
View File
@@ -818,7 +818,7 @@ async def create_group(inputdata, configmanager):
except KeyError:
raise exc.InvalidArgumentException()
try:
await configmanager.add_group_attributes(attribmap)
await configmanager.add_group_attributes(attribmap, checkconflict=True)
except ValueError as e:
raise exc.InvalidArgumentException(str(e))
yield msg.CreatedResource(groupname)
@@ -834,7 +834,7 @@ async def create_node(inputdata, configmanager):
except KeyError:
raise exc.InvalidArgumentException('name not specified')
try:
await configmanager.add_node_attributes(attribmap)
await configmanager.add_node_attributes(attribmap, checkconflict=True)
except ValueError as e:
raise exc.InvalidArgumentException(str(e))
yield msg.CreatedResource(nodename)
@@ -850,7 +850,7 @@ async def create_noderange(inputdata, configmanager):
except KeyError:
raise exc.InvalidArgumentException('name not specified')
try:
await configmanager.add_node_attributes(attribmap)
await configmanager.add_node_attributes(attribmap, checkconflict=True)
except ValueError as e:
raise exc.InvalidArgumentException(str(e))
for node in attribmap: