Skip to content

Commit

Permalink
chore: bump up version to 1.0.0 ⬆️
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Feb 8, 2021
1 parent 329fa2a commit 6171a2c
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 31 deletions.
45 changes: 41 additions & 4 deletions API/v1/Console/__init__.py
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"])
45 changes: 41 additions & 4 deletions API/v1/GuestMetrics/__init__.py
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"])
41 changes: 39 additions & 2 deletions API/v1/Host/__init__.py
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"])
42 changes: 40 additions & 2 deletions API/v1/SR/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
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.SR import SR

from API.v1.SR.find import router as _sr_find
from API.v1.SR.info import router as _sr_info
from API.v1.SR.list import router as _sr_list
from API.v1.SR.scan import router as _sr_scan

sr_router = APIRouter()

# === Condition Checker ===
async def verify_sr_uuid(cluster_id: str, sr_uuid: Optional[str] = None):
if sr_uuid is None:
return

session = create_session(cluster_id, get_xen_clusters=Settings.get_xen_clusters())

try:
sr = SR.get_by_uuid(session, sr_uuid)

except Failure as xenapi_error:
if xenapi_error.details[0] == "UUID_INVALID":
raise HTTPException(status_code=404, detail=f"SR {sr_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 ===

sr_router = APIRouter(dependencies=[Depends(verify_sr_uuid)])

sr_router.include_router(_sr_list, tags=["sr"])
sr_router.include_router(_sr_find, tags=["sr"])
sr_router.include_router(_sr_info, tags=["sr"])
Expand Down
41 changes: 39 additions & 2 deletions API/v1/VBD/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
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.VBD import VBD

from API.v1.VBD.delete import router as _vbd_delete
from API.v1.VBD.find_vdi import router as _vbd_find_by_vdi
from API.v1.VBD.info import router as _vbd_info
from API.v1.VBD.list import router as _vbd_list
from API.v1.VBD.media import router as _vbd_media

vbd_router = APIRouter()

# === Condition Checker ===
async def verify_vbd_uuid(cluster_id: str, vbd_uuid: Optional[str] = None):
if vbd_uuid is None:
return

session = create_session(cluster_id, get_xen_clusters=Settings.get_xen_clusters())

try:
vbd = VBD.get_by_uuid(session, vbd_uuid)

except Failure as xenapi_error:
if xenapi_error.details[0] == "UUID_INVALID":
raise HTTPException(status_code=404, detail=f"VBD {vbd_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 ===
vbd_router = APIRouter(dependencies=[Depends(verify_vbd_uuid)])

vbd_router.include_router(_vbd_list, tags=["vbd"])
vbd_router.include_router(_vbd_info, tags=["vbd"])
vbd_router.include_router(_vbd_find_by_vdi, tags=["vbd"])
Expand Down
40 changes: 38 additions & 2 deletions API/v1/VDI/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
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.VDI import VDI

from API.v1.VDI.delete import router as _vdi_delete
from API.v1.VDI.find import router as _vdi_find
from API.v1.VDI.info import router as _vdi_info
from API.v1.VDI.list import router as _vdi_list

vdi_router = APIRouter()
# === Condition Checker ===
async def verify_vdi_uuid(cluster_id: str, vdi_uuid: Optional[str] = None):
if vdi_uuid is None:
return

session = create_session(cluster_id, get_xen_clusters=Settings.get_xen_clusters())

try:
vdi = VDI.get_by_uuid(session, vdi_uuid)

except Failure as xenapi_error:
if xenapi_error.details[0] == "UUID_INVALID":
raise HTTPException(status_code=404, detail=f"VDI {vdi_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 ===
vdi_router = APIRouter(dependencies=[Depends(verify_vdi_uuid)])

vdi_router.include_router(_vdi_list, tags=["vdi"])
vdi_router.include_router(_vdi_find, tags=["vdi"])
vdi_router.include_router(_vdi_info, tags=["vdi"])
Expand Down
43 changes: 40 additions & 3 deletions API/v1/VIF/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
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.VIF import VIF

from API.v1.VIF.info import router as _vif_info
from API.v1.VIF.ipv4 import router as _vif_ipv4
Expand All @@ -9,9 +17,38 @@
from API.v1.VIF.lock import router as _vif_lock
from API.v1.VIF.qos import router as _vif_qos

vif_router = APIRouter()
vif_router.include_router(_vif_info, tags=["vif"])

# === Condition Checker ===
async def verify_vif_uuid(cluster_id: str, vif_uuid: Optional[str] = None):
if vif_uuid is None:
return

session = create_session(cluster_id, get_xen_clusters=Settings.get_xen_clusters())

try:
vif = VIF.get_by_uuid(session, vif_uuid)

except Failure as xenapi_error:
if xenapi_error.details[0] == "UUID_INVALID":
raise HTTPException(status_code=404, detail=f"VIF {vif_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 ===
vif_router = APIRouter(dependencies=[Depends(verify_vif_uuid)])

vif_router.include_router(_vif_list, tags=["vif"])
vif_router.include_router(_vif_info, tags=["vif"])
vif_router.include_router(_vif_ipv4, tags=["vif"])
vif_router.include_router(_vif_ipv4_allowed, tags=["vif"])
vif_router.include_router(_vif_ipv6, tags=["vif"])
Expand Down
Loading

0 comments on commit 6171a2c

Please sign in to comment.