Skip to content

Commit

Permalink
added healthcheck endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldor1510 committed Jul 30, 2024
1 parent be4ea41 commit 4e6a5b7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions esi_leap/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from keystonemiddleware import auth_token
from oslo_context import context
from esi_leap.common.health import Health
import pecan
from pecan import hooks

Expand Down Expand Up @@ -60,6 +61,8 @@ def setup_app(config=None):
if CONF.pecan.auth_enable:
app = auth_token.AuthProtocol(app, dict(CONF.keystone_authtoken))

app = Health(app=app, path="/")

return app


Expand Down
31 changes: 31 additions & 0 deletions esi_leap/common/health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from oslo_serialization import jsonutils


def root(host_url):
return {
"name": "ESI Leap API",
"description": "ESI Leap is an OpenStack service for leasing baremetal nodes, designed to run on top of multi-tenant Ironic.",
"versions": [
{
"id": "v1.0",
"status": "CURRENT",
"links": [{"href": "{0}/v1".format(host_url), "rel": "self"}],
}
],
}


class Health(object):
def __init__(self, app, path):
self.app = app
self.path = path

def __call__(self, environ, start_response):
if environ["PATH_INFO"] == self.path:
start_response("200 OK", [("Content-Type", "application/json")])
return [
jsonutils.dump_as_bytes(
root(environ["wsgi.url_scheme"] + "://" + environ["HTTP_HOST"])
)
]
return self.app(environ, start_response)

0 comments on commit 4e6a5b7

Please sign in to comment.