feat:
--Added API to show c-luster --Added API to show nodes
This commit is contained in:
1 parent
448771cd88
commit
cf4ab374fe
1 file changed
+70
-1
@@ -16,7 +16,7 @@ from models import NodeInterface, Cluster
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
from typing import List
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
origins = os.getenv("CORS_ORIGINS", "").split(",")
|
origins = os.getenv("CORS_ORIGINS", "").split(",")
|
||||||
@@ -70,6 +70,20 @@ class ClusterRequest(BaseModel):
|
|||||||
links: list[tuple[str, str]]
|
links: list[tuple[str, str]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class NodeResponse(BaseModel):
|
||||||
|
node_name: str
|
||||||
|
uuid: UUID
|
||||||
|
|
||||||
|
|
||||||
|
class ClusterNodesResponse(BaseModel):
|
||||||
|
cluster_name: str
|
||||||
|
nodes: List[NodeResponse]
|
||||||
|
|
||||||
|
class ClusterResponse(BaseModel):
|
||||||
|
uuid: UUID
|
||||||
|
cluster_name: str
|
||||||
|
|
||||||
#POST /register-node
|
#POST /register-node
|
||||||
# {
|
# {
|
||||||
# "node_name": "node2",
|
# "node_name": "node2",
|
||||||
@@ -785,3 +799,58 @@ def create_cluster(data: ClusterRequest,db: Session = Depends(get_db),token_data
|
|||||||
status_code=500,
|
status_code=500,
|
||||||
detail="Cluster creation failed"
|
detail="Cluster creation failed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@app.get(
|
||||||
|
"/spock/cluster-nodes/{cluster_uuid}",
|
||||||
|
response_model=ClusterNodesResponse
|
||||||
|
)
|
||||||
|
def get_cluster_nodes(
|
||||||
|
cluster_uuid: UUID,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
token_data=Depends(verify_token)
|
||||||
|
):
|
||||||
|
|
||||||
|
cluster = (
|
||||||
|
db.query(Cluster)
|
||||||
|
.filter(Cluster.uuid == cluster_uuid)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
if not cluster:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=404,
|
||||||
|
detail=f"Cluster with UUID '{cluster_uuid}' not found"
|
||||||
|
)
|
||||||
|
nodes = (
|
||||||
|
db.query(NodeInterface)
|
||||||
|
.filter(NodeInterface.cluster_id == cluster.uuid)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"cluster_name": cluster.cluster_name,
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"node_name": node.if_name,
|
||||||
|
"uuid": node.uuid
|
||||||
|
}
|
||||||
|
for node in nodes
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get(
|
||||||
|
"/spock/clusters",
|
||||||
|
response_model=List[ClusterResponse]
|
||||||
|
)
|
||||||
|
def get_clusters(
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
token_data=Depends(verify_token)
|
||||||
|
):
|
||||||
|
clusters = db.query(Cluster).all()
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"uuid": cluster.uuid,
|
||||||
|
"cluster_name": cluster.cluster_name
|
||||||
|
}
|
||||||
|
for cluster in clusters
|
||||||
|
]
|
||||||
Reference in new issue
Block a user