diff --git a/dch_webhooks.py b/dch_webhooks.py index 4006440..44bf4e1 100644 --- a/dch_webhooks.py +++ b/dch_webhooks.py @@ -609,24 +609,29 @@ async def start_ansible_job(): raise Exception(r.read()) -async def publish_host_info(hostname: str, sshkeys: str): +async def publish_host_info( + hostname: str, sshkeys: str, branch: Optional[str] +): + data = { + 'hostname': hostname, + 'sshkeys': sshkeys, + } + if branch: + data['branch'] = branch await context.amqp.connect() await context.amqp.queue_declare(HOST_INFO_QUEUE, durable=True) context.amqp.publish( exchange='', routing_key=HOST_INFO_QUEUE, - body=json.dumps( - { - 'hostname': hostname, - 'sshkeys': sshkeys, - }, - ).encode('utf-8'), + body=json.dumps(data).encode('utf-8'), ) -async def handle_host_online(hostname: str, sshkeys: str): +async def handle_host_online( + hostname: str, sshkeys: str, branch: Optional[str] +): try: - await publish_host_info(hostname, sshkeys) + await publish_host_info(hostname, sshkeys, branch) except asyncio.CancelledError: raise except Exception: @@ -721,5 +726,9 @@ async def jenkins_notify(request: fastapi.Request) -> None: status_code=fastapi.status.HTTP_202_ACCEPTED, response_class=fastapi.responses.PlainTextResponse, ) -async def host_online(hostname: str = Form(), sshkeys: str = Form()) -> None: - asyncio.create_task(handle_host_online(hostname, sshkeys)) +async def host_online( + hostname: str = Form(), + sshkeys: str = Form(), + branch: Optional[str] = Form(None), +) -> None: + asyncio.create_task(handle_host_online(hostname, sshkeys, branch))