-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
296 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
from fastapi import APIRouter | ||
from fastapi import APIRouter, HTTPException, Depends | ||
from XenGarden.session import create_session | ||
from app.settings import Settings | ||
from XenAPI.XenAPI import Failure | ||
from API.v1.Common import xenapi_failure_jsonify | ||
from xmlrpc.client import Fault | ||
from typing import Optional | ||
|
||
from API.v1.Console.info import router as _console_router | ||
from XenGarden.Console import Console | ||
|
||
console_router = APIRouter() | ||
console_router.include_router(_console_router, tags=["console"]) | ||
from API.v1.Console.info import router as _console_info | ||
|
||
|
||
# === Condition Checker === | ||
async def verify_console_uuid(cluster_id: str, console_uuid: Optional[str] = None): | ||
if console_uuid is None: | ||
return | ||
|
||
session = create_session(cluster_id, get_xen_clusters=Settings.get_xen_clusters()) | ||
|
||
try: | ||
console = Console.get_by_uuid(session, console_uuid) | ||
|
||
except Failure as xenapi_error: | ||
if xenapi_error.details[0] == "UUID_INVALID": | ||
raise HTTPException(status_code=404, detail=f"Console {console_uuid} does not exist") | ||
|
||
raise HTTPException( | ||
status_code=500, detail=xenapi_failure_jsonify(xenapi_error) | ||
) | ||
except Fault as xml_rpc_error: | ||
raise HTTPException( | ||
status_code=int(xml_rpc_error.faultCode), | ||
detail=xml_rpc_error.faultString, | ||
) | ||
|
||
session.xenapi.session.logout() | ||
|
||
|
||
# === Router Actions === | ||
console_router = APIRouter(dependencies=[Depends(verify_console_uuid)]) | ||
|
||
console_router.include_router(_console_info, tags=["console"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
from fastapi import APIRouter | ||
from fastapi import APIRouter, HTTPException, Depends | ||
from XenGarden.session import create_session | ||
from app.settings import Settings | ||
from XenAPI.XenAPI import Failure | ||
from API.v1.Common import xenapi_failure_jsonify | ||
from xmlrpc.client import Fault | ||
from typing import Optional | ||
|
||
from API.v1.GuestMetrics.info import router as _info_router | ||
from XenGarden.GuestMetrics import GuestMetrics | ||
|
||
guest_router = APIRouter() | ||
guest_router.include_router(_info_router, tags=["guest"]) | ||
from API.v1.GuestMetrics.info import router as _guest_info | ||
|
||
|
||
# === Condition Checker === | ||
async def verify_guest_uuid(cluster_id: str, guest_uuid: Optional[str] = None): | ||
if guest_uuid is None: | ||
return | ||
|
||
session = create_session(cluster_id, get_xen_clusters=Settings.get_xen_clusters()) | ||
|
||
try: | ||
guest_metrics = GuestMetrics.get_by_uuid(session, guest_uuid) | ||
|
||
except Failure as xenapi_error: | ||
if xenapi_error.details[0] == "UUID_INVALID": | ||
raise HTTPException(status_code=404, detail=f"GuestMetrics {guest_uuid} does not exist") | ||
|
||
raise HTTPException( | ||
status_code=500, detail=xenapi_failure_jsonify(xenapi_error) | ||
) | ||
except Fault as xml_rpc_error: | ||
raise HTTPException( | ||
status_code=int(xml_rpc_error.faultCode), | ||
detail=xml_rpc_error.faultString, | ||
) | ||
|
||
session.xenapi.session.logout() | ||
|
||
|
||
# === Router Actions === | ||
guest_router = APIRouter(dependencies=[Depends(verify_guest_uuid)]) | ||
|
||
guest_router.include_router(_guest_info, tags=["guest"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
from fastapi import APIRouter | ||
from fastapi import APIRouter, HTTPException, Depends | ||
from XenGarden.session import create_session | ||
from app.settings import Settings | ||
from XenAPI.XenAPI import Failure | ||
from API.v1.Common import xenapi_failure_jsonify | ||
from xmlrpc.client import Fault | ||
from typing import Optional | ||
|
||
from XenGarden.Host import Host | ||
|
||
from API.v1.Host.info import router as _host_info | ||
from API.v1.Host.list import router as _host_list | ||
|
||
host_router = APIRouter() | ||
|
||
# === Condition Checker === | ||
async def verify_host_uuid(cluster_id: str, host_uuid: Optional[str] = None): | ||
if host_uuid is None: | ||
return | ||
|
||
session = create_session(cluster_id, get_xen_clusters=Settings.get_xen_clusters()) | ||
|
||
try: | ||
host = Host.get_by_uuid(session, host_uuid) | ||
|
||
except Failure as xenapi_error: | ||
if xenapi_error.details[0] == "UUID_INVALID": | ||
raise HTTPException(status_code=404, detail=f"Host {host_uuid} does not exist") | ||
|
||
raise HTTPException( | ||
status_code=500, detail=xenapi_failure_jsonify(xenapi_error) | ||
) | ||
except Fault as xml_rpc_error: | ||
raise HTTPException( | ||
status_code=int(xml_rpc_error.faultCode), | ||
detail=xml_rpc_error.faultString, | ||
) | ||
|
||
session.xenapi.session.logout() | ||
|
||
|
||
# === Router Actions === | ||
host_router = APIRouter(dependencies=[Depends(verify_host_uuid)]) | ||
|
||
host_router.include_router(_host_list, tags=["host"]) | ||
host_router.include_router(_host_info, tags=["host"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.