2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-09-21 16:39:32 +00:00

Await asynchronous configuration mutations

This commit is contained in:
Markus Hilger
2026-07-12 23:54:16 +02:00
parent 91654ea0d1
commit 5fc036a2b7
7 changed files with 12 additions and 14 deletions
@@ -187,7 +187,7 @@ async def connect_to_leader(cert=None, name=None, leader=None, remote=None, isre
await cfm.ConfigManager(tenant=None)._load_from_json(dbjson,
sync=False)
cfm.commit_clear()
except Exception:
except Exception as e:
print(repr(e))
await cfm.stop_following()
cfm.rollback_clear()
@@ -895,7 +895,7 @@ async def check_managers():
targets = sorted(expandednoderanges[targets], key=availmanagers.get)
if not targets:
continue
c.set_node_attributes({node: {'collective.manager': {'value': targets[0]}}})
await c.set_node_attributes({node: {'collective.manager': {'value': targets[0]}}})
availmanagers[targets[0]] += 1
await _assimilate_missing()
failovercheck = None
@@ -3232,7 +3232,7 @@ async def dump_db_to_directory(location, password, redact=None, skipkeys=False,
try:
for tenant in os.listdir(
os.path.join(ConfigManager._cfgdir, '/tenants/')):
tenant_data = ConfigManager(tenant=tenant)._dump_to_json(redact=redact)
tenant_data = await ConfigManager(tenant=tenant)._dump_to_json(redact=redact)
with open(os.path.join(location, 'tenants', tenant, f'main.{format}'), 'wb' if format == 'json' else 'w') as cfgfile:
if format == 'json':
cfgfile.write(tenant_data)
+2 -2
View File
@@ -103,7 +103,7 @@ class CredServer(object):
now = datetime.datetime.utcnow()
expiry = datetime.datetime.strptime(apiarmed, "%Y-%m-%dT%H:%M:%SZ")
if now > expiry:
self.cfm.set_node_attributes({nodename: {'deployment.apiarmed': ''}})
await self.cfm.set_node_attributes({nodename: {'deployment.apiarmed': ''}})
client.close()
return
await cloop.sock_sendall(client, b'\x02\x20')
@@ -133,7 +133,7 @@ class CredServer(object):
await cloop.sock_recv(client, 2) # drain end of message
await cloop.sock_sendall(client, b'\x05\x00') # report success
if hmackey and apiarmed != 'continuous':
self.cfm.clear_node_attributes([nodename], ['secret.selfapiarmtoken'])
await self.cfm.clear_node_attributes([nodename], ['secret.selfapiarmtoken'])
if apiarmed != 'continuous':
disarm = {nodename: {'deployment.sealedapikey': '', 'deployment.apiarmed': ''}}
finally:
@@ -254,10 +254,10 @@ def yield_rename_resources(namemap, isnode):
else:
yield msg.RenamedResource(node, namemap[node])
def update_locks(nodes, configmanager, inputdata):
async def update_locks(nodes, configmanager, inputdata):
for node in nodes:
updatestate = inputdata.inputbynode[node]
configmanager.set_node_attributes({node: {'deployment.lock': updatestate}})
await configmanager.set_node_attributes({node: {'deployment.lock': updatestate}})
yield msg.DeploymentLock(node, updatestate)
async def update_nodes(nodes, element, configmanager, inputdata):
@@ -46,7 +46,7 @@ async def create_ident_image(node, configmanager):
tmpd = tempfile.mkdtemp()
ident = { 'nodename': node }
apikey = create_apikey()
configmanager.set_node_attributes({node: {'secret.selfapiarmtoken': apikey}})
await configmanager.set_node_attributes({node: {'secret.selfapiarmtoken': apikey}})
ident['apitoken'] = apikey
# This particular mechanism does not (yet) do anything smart with collective
# It would be a reasonable enhancement to list all collective server addresses
@@ -79,4 +79,3 @@ async def update(nodes, element, configmanager, inputdata):
yield msg.CreatedResource(
'nodes/{0}/deployment/ident_image'.format(node))
@@ -146,7 +146,7 @@ class SshShell(conapi.Console):
if b'\r' in self.keyaction:
action = self.keyaction.split(b'\r')[0]
if action.lower() == b'accept':
self.nodeconfig.set_node_attributes(
await self.nodeconfig.set_node_attributes(
{self.node:
{self.keyattrname: self.candidatefprint}})
await self.datacallback('\r\n')
@@ -157,10 +157,10 @@ class SshShell(conapi.Console):
self.keyaction = b''
await self.datacallback('\r\nEnter "disconnect" or "accept": ')
elif len(data) > 0:
self.datacallback(data)
await self.datacallback(data)
elif self.inputmode == 0:
while len(data) and data[0:1] == b'\x7f' and len(self.username):
self.datacallback('\b \b') # erase previously echoed value
await self.datacallback('\b \b') # erase previously echoed value
self.username = self.username[:-1]
data = data[1:]
while len(data) and data[0:1] == b'\x7f':
+1 -2
View File
@@ -248,7 +248,7 @@ async def handle_api_request(url, req, username, cfm, reqbody, authorized):
if url == '/registration_options':
userinfo = cfm.get_user(username)
if not userinfo:
cfm.create_user(username, role='Stub')
await cfm.create_user(username, role='Stub')
userinfo = cfm.get_user(username)
authid = userinfo.get('webauthid', None)
if not authid: # TODO: index users by authid as well as name
@@ -293,4 +293,3 @@ async def handle_api_request(url, req, username, cfm, reqbody, authorized):
if rsp.get('verified', False):
return json.dumps({'status': 'Success'})