-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (62 loc) · 1.79 KB
/
main.py
File metadata and controls
80 lines (62 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
OpenStack VM Lifecycle Management API
Main application entry point.
"""
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app import __version__, __description__
from app.config import settings
from app.routes.vm_routes import router as vm_router
# Configure logging
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(_app: FastAPI):
"""Application lifespan event handler"""
# Startup
logger.info(f"Starting {settings.app_name} v{__version__}")
logger.info(f"Environment: {settings.environment}")
logger.info(f"API Version: {settings.api_version}")
logger.info(f"Debug Mode: {settings.debug}")
yield
# Shutdown
logger.info(f"Shutting down {settings.app_name}")
# Create FastAPI application
app = FastAPI(
title="OpenStack VM Lifecycle Management API",
description=__description__,
version=__version__,
docs_url="/docs",
redoc_url="/redoc",
openapi_url="/openapi.json",
lifespan=lifespan,
)
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=settings.cors_origins,
allow_credentials=settings.cors_allow_credentials,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(vm_router)
@app.get("/", tags=["Root"])
async def root():
"""Root endpoint"""
return {
"message": "OpenStack VM Lifecycle Management API",
"version": __version__,
"docs": "/docs",
"health": f"/api/{settings.api_version}/health",
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host=settings.host,
port=settings.port,
reload=settings.debug,
log_level=settings.log_level.lower(),
)