generated from Luis/nextjs-python-web-template
draft emulating flag
This commit is contained in:
@@ -11,6 +11,12 @@ class Status(Enum):
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
|
||||
class Roles(Enum):
|
||||
PROSUMER = "service_prosumer"
|
||||
AP = "AP"
|
||||
DLG = "DLG"
|
||||
|
||||
|
||||
class Machine(BaseModel):
|
||||
name: str
|
||||
status: Status
|
||||
@@ -25,6 +31,10 @@ class EntityBase(BaseModel):
|
||||
did: str = Field(..., example="did:sov:test:1234")
|
||||
name: str = Field(..., example="C1")
|
||||
ip: str = Field(..., example="127.0.0.1")
|
||||
network: str = Field(..., example="255.255.0.0")
|
||||
role: Roles = Field(
|
||||
..., example=Roles("service_prosumer")
|
||||
) # roles are needed for UI to show the correct view
|
||||
visible: bool = Field(..., example=True)
|
||||
other: dict = Field(
|
||||
...,
|
||||
|
||||
@@ -126,6 +126,27 @@ def start_server(args: argparse.Namespace) -> None:
|
||||
cmd = ["pytest", "-s", str(test_db_api)]
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
if args.emulate:
|
||||
# todo move emu
|
||||
from .emulate_fastapi import (app_dlg, app_ap, app_c1, app_c2)
|
||||
from .api import (get_health, port_dlg, port_ap, port_client_base)
|
||||
import multiprocessing as mp
|
||||
port = port_dlg
|
||||
host = host
|
||||
# server
|
||||
proc = mp.Process(
|
||||
target=uvicorn.run,
|
||||
args=(app_dlg,),
|
||||
kwargs={"host": host, "port": port, "log_level": "info"},
|
||||
daemon=True,
|
||||
)
|
||||
proc.start()
|
||||
|
||||
url = f"http://{host}:{port}"
|
||||
res = get_health(url=url + "/health")
|
||||
if res is None:
|
||||
raise Exception(f"Couldn't reach {url} after starting server")
|
||||
|
||||
uvicorn.run(
|
||||
"clan_cli.webui.app:app",
|
||||
host=args.host,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String, Text, Enum
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from .schemas import Roles
|
||||
from .sql_db import Base
|
||||
|
||||
# Relationsship example
|
||||
@@ -14,12 +15,14 @@ class Entity(Base):
|
||||
did = Column(String, primary_key=True, index=True)
|
||||
name = Column(String, index=True, unique=True)
|
||||
ip = Column(String, index=True)
|
||||
network = Column(String, index=True)
|
||||
role = Column(Enum(Roles), index=True)
|
||||
attached = Column(Boolean, index=True)
|
||||
visible = Column(Boolean, index=True)
|
||||
stop_health_task = Column(Boolean)
|
||||
|
||||
## Non queryable body ##
|
||||
# In here we deposit: Network, Roles, Visible, etc.
|
||||
# In here we deposit: Not yet defined stuff
|
||||
other = Column(JSON)
|
||||
|
||||
## Relations ##
|
||||
|
||||
Reference in New Issue
Block a user