mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Rename __json__() to asdict()
This commit is contained in:
1 parent
44074ff7c9
commit
cefab8d362
89 files changed
+286
-282
No files matched your search
@@ -65,7 +65,7 @@ async def create_atm_switch(project_id: UUID, node_data: schemas.ATMSwitchCreate
|
||||
node_type="atm_switch",
|
||||
mappings=node_data.get("mappings"),
|
||||
)
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.ATMSwitch)
|
||||
@@ -74,7 +74,7 @@ def get_atm_switch(node: ATMSwitch = Depends(dep_node)):
|
||||
Return an ATM switch node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/duplicate", response_model=schemas.ATMSwitch, status_code=status.HTTP_201_CREATED)
|
||||
@@ -84,7 +84,7 @@ async def duplicate_atm_switch(destination_node_id: UUID = Body(..., embed=True)
|
||||
"""
|
||||
|
||||
new_node = await Dynamips.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.ATMSwitch)
|
||||
@@ -99,7 +99,7 @@ async def update_atm_switch(node_data: schemas.ATMSwitchUpdate, node: ATMSwitch
|
||||
if "mappings" in node_data:
|
||||
node.mappings = node_data["mappings"]
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -156,7 +156,7 @@ async def create_nio(
|
||||
|
||||
nio = await Dynamips.instance().create_nio(node, jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.add_nio(nio, port_number)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -72,7 +72,7 @@ async def create_cloud(project_id: UUID, node_data: schemas.CloudCreate):
|
||||
node.remote_console_type = node_data.get("remote_console_type", node.remote_console_type)
|
||||
node.remote_console_http_path = node_data.get("remote_console_http_path", node.remote_console_http_path)
|
||||
node.usage = node_data.get("usage", "")
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.Cloud)
|
||||
@@ -81,7 +81,7 @@ def get_cloud(node: Cloud = Depends(dep_node)):
|
||||
Return a cloud node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.Cloud)
|
||||
@@ -95,7 +95,7 @@ def update_cloud(node_data: schemas.CloudUpdate, node: Cloud = Depends(dep_node)
|
||||
if hasattr(node, name) and getattr(node, name) != value:
|
||||
setattr(node, name, value)
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -154,7 +154,7 @@ async def create_cloud_nio(
|
||||
|
||||
nio = Builtin.instance().create_nio(jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.add_nio(nio, port_number)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -177,7 +177,7 @@ async def update_cloud_nio(
|
||||
if nio_data.filters:
|
||||
nio.filters = nio_data.filters
|
||||
await node.update_nio(port_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -72,7 +72,7 @@ def network_ports() -> dict:
|
||||
"""
|
||||
|
||||
m = PortManager.instance()
|
||||
return m.__json__()
|
||||
return m.asdict()
|
||||
|
||||
|
||||
@router.get("/version")
|
||||
|
||||
@@ -82,7 +82,7 @@ async def create_docker_node(project_id: UUID, node_data: schemas.DockerCreate):
|
||||
if hasattr(container, name) and getattr(container, name) != value:
|
||||
setattr(container, name, value)
|
||||
|
||||
return container.__json__()
|
||||
return container.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.Docker)
|
||||
@@ -91,7 +91,7 @@ def get_docker_node(node: DockerVM = Depends(dep_node)):
|
||||
Return a Docker node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.Docker)
|
||||
@@ -128,7 +128,7 @@ async def update_docker_node(node_data: schemas.DockerUpdate, node: DockerVM = D
|
||||
if changed:
|
||||
await node.update()
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/start", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -201,7 +201,7 @@ async def duplicate_docker_node(destination_node_id: UUID = Body(..., embed=True
|
||||
"""
|
||||
|
||||
new_node = await Docker.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -219,7 +219,7 @@ async def create_docker_node_nio(
|
||||
|
||||
nio = Docker.instance().create_nio(jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.adapter_add_nio_binding(adapter_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -239,7 +239,7 @@ async def update_docker_node_nio(
|
||||
if nio_data.filters:
|
||||
nio.filters = nio_data.filters
|
||||
await node.adapter_update_nio_binding(adapter_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -81,7 +81,7 @@ async def create_router(project_id: UUID, node_data: schemas.DynamipsCreate):
|
||||
node_type="dynamips",
|
||||
)
|
||||
await dynamips_manager.update_vm_settings(vm, node_data)
|
||||
return vm.__json__()
|
||||
return vm.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.Dynamips)
|
||||
@@ -90,7 +90,7 @@ def get_router(node: Router = Depends(dep_node)):
|
||||
Return Dynamips router.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.Dynamips)
|
||||
@@ -101,7 +101,7 @@ async def update_router(node_data: schemas.DynamipsUpdate, node: Router = Depend
|
||||
|
||||
await Dynamips.instance().update_vm_settings(node, jsonable_encoder(node_data, exclude_unset=True))
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -171,7 +171,7 @@ async def create_nio(adapter_number: int, port_number: int, nio_data: schemas.UD
|
||||
|
||||
nio = await Dynamips.instance().create_nio(node, jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.slot_add_nio_binding(adapter_number, port_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -188,7 +188,7 @@ async def update_nio(adapter_number: int, port_number: int, nio_data: schemas.UD
|
||||
if nio_data.filters:
|
||||
nio.filters = nio_data.filters
|
||||
await node.slot_update_nio_binding(adapter_number, port_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -273,7 +273,7 @@ async def duplicate_router(destination_node_id: UUID, node: Router = Depends(dep
|
||||
"""
|
||||
|
||||
new_node = await Dynamips.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.websocket("/{node_id}/console/ws")
|
||||
|
||||
@@ -65,7 +65,7 @@ async def create_ethernet_hub(project_id: UUID, node_data: schemas.EthernetHubCr
|
||||
node_type="ethernet_hub",
|
||||
ports=node_data.get("ports_mapping"),
|
||||
)
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.EthernetHub)
|
||||
@@ -74,7 +74,7 @@ def get_ethernet_hub(node: EthernetHub = Depends(dep_node)):
|
||||
Return an Ethernet hub.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/duplicate", response_model=schemas.EthernetHub, status_code=status.HTTP_201_CREATED)
|
||||
@@ -86,7 +86,7 @@ async def duplicate_ethernet_hub(
|
||||
"""
|
||||
|
||||
new_node = await Dynamips.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.EthernetHub)
|
||||
@@ -101,7 +101,7 @@ async def update_ethernet_hub(node_data: schemas.EthernetHubUpdate, node: Ethern
|
||||
if "ports_mapping" in node_data:
|
||||
node.ports_mapping = node_data["ports_mapping"]
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -158,7 +158,7 @@ async def create_nio(
|
||||
|
||||
nio = await Dynamips.instance().create_nio(node, jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.add_nio(nio, port_number)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -68,13 +68,13 @@ async def create_ethernet_switch(project_id: UUID, node_data: schemas.EthernetSw
|
||||
ports=node_data.get("ports_mapping"),
|
||||
)
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.EthernetSwitch)
|
||||
def get_ethernet_switch(node: EthernetSwitch = Depends(dep_node)):
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/duplicate", response_model=schemas.EthernetSwitch, status_code=status.HTTP_201_CREATED)
|
||||
@@ -86,7 +86,7 @@ async def duplicate_ethernet_switch(
|
||||
"""
|
||||
|
||||
new_node = await Dynamips.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.EthernetSwitch)
|
||||
@@ -104,7 +104,7 @@ async def update_ethernet_switch(node_data: schemas.EthernetSwitchUpdate, node:
|
||||
if "console_type" in node_data:
|
||||
node.console_type = node_data["console_type"]
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -157,7 +157,7 @@ async def create_nio(
|
||||
|
||||
nio = await Dynamips.instance().create_nio(node, jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.add_nio(nio, port_number)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -65,7 +65,7 @@ async def create_frame_relay_switch(project_id: UUID, node_data: schemas.FrameRe
|
||||
node_type="frame_relay_switch",
|
||||
mappings=node_data.get("mappings"),
|
||||
)
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.FrameRelaySwitch)
|
||||
@@ -74,7 +74,7 @@ def get_frame_relay_switch(node: FrameRelaySwitch = Depends(dep_node)):
|
||||
Return a Frame Relay switch node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/duplicate", response_model=schemas.FrameRelaySwitch, status_code=status.HTTP_201_CREATED)
|
||||
@@ -86,7 +86,7 @@ async def duplicate_frame_relay_switch(
|
||||
"""
|
||||
|
||||
new_node = await Dynamips.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.FrameRelaySwitch)
|
||||
@@ -103,7 +103,7 @@ async def update_frame_relay_switch(
|
||||
if "mappings" in node_data:
|
||||
node.mappings = node_data["mappings"]
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -160,7 +160,7 @@ async def create_nio(
|
||||
|
||||
nio = await Dynamips.instance().create_nio(node, jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.add_nio(nio, port_number)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -79,7 +79,7 @@ async def create_iou_node(project_id: UUID, node_data: schemas.IOUCreate):
|
||||
if node_data.get("use_default_iou_values") and (name == "ram" or name == "nvram"):
|
||||
continue
|
||||
setattr(vm, name, value)
|
||||
return vm.__json__()
|
||||
return vm.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.IOU)
|
||||
@@ -88,7 +88,7 @@ def get_iou_node(node: IOUVM = Depends(dep_node)):
|
||||
Return an IOU node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.IOU)
|
||||
@@ -109,7 +109,7 @@ async def update_iou_node(node_data: schemas.IOUUpdate, node: IOUVM = Depends(de
|
||||
# this is important to have the correct NVRAM amount in order to correctly push the configs to the NVRAM
|
||||
await node.update_default_iou_values()
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -128,7 +128,7 @@ async def duplicate_iou_node(destination_node_id: UUID = Body(..., embed=True),
|
||||
"""
|
||||
|
||||
new_node = await IOU.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/start", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -143,7 +143,7 @@ async def start_iou_node(start_data: schemas.IOUStart, node: IOUVM = Depends(dep
|
||||
setattr(node, name, value)
|
||||
|
||||
await node.start()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/stop", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -191,7 +191,7 @@ async def create_iou_node_nio(
|
||||
|
||||
nio = IOU.instance().create_nio(jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.adapter_add_nio_binding(adapter_number, port_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -213,7 +213,7 @@ async def update_iou_node_nio(
|
||||
if nio_data.filters:
|
||||
nio.filters = nio_data.filters
|
||||
await node.adapter_update_nio_binding(adapter_number, port_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -67,7 +67,7 @@ async def create_nat_node(project_id: UUID, node_data: schemas.NATCreate):
|
||||
)
|
||||
|
||||
node.usage = node_data.get("usage", "")
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.NAT)
|
||||
@@ -76,7 +76,7 @@ def get_nat_node(node: Nat = Depends(dep_node)):
|
||||
Return a NAT node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.NAT)
|
||||
@@ -90,7 +90,7 @@ def update_nat_node(node_data: schemas.NATUpdate, node: Nat = Depends(dep_node))
|
||||
if hasattr(node, name) and getattr(node, name) != value:
|
||||
setattr(node, name, value)
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -149,7 +149,7 @@ async def create_nat_node_nio(
|
||||
|
||||
nio = Builtin.instance().create_nio(jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.add_nio(nio, port_number)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -172,7 +172,7 @@ async def update_nat_node_nio(
|
||||
if nio_data.filters:
|
||||
nio.filters = nio_data.filters
|
||||
await node.update_nio(port_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -58,7 +58,7 @@ def get_compute_projects():
|
||||
"""
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
return [p.__json__() for p in pm.projects]
|
||||
return [p.asdict() for p in pm.projects]
|
||||
|
||||
|
||||
@router.post("/projects", status_code=status.HTTP_201_CREATED, response_model=schemas.Project)
|
||||
@@ -75,7 +75,7 @@ def create_compute_project(project_data: schemas.ProjectCreate):
|
||||
project_id=project_data.get("project_id"),
|
||||
variables=project_data.get("variables", None),
|
||||
)
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.put("/projects/{project_id}", response_model=schemas.Project)
|
||||
@@ -85,7 +85,7 @@ async def update_compute_project(project_data: schemas.ProjectUpdate, project: P
|
||||
"""
|
||||
|
||||
await project.update(variables=project_data.variables)
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}", response_model=schemas.Project)
|
||||
@@ -94,7 +94,7 @@ def get_compute_project(project: Project = Depends(dep_project)):
|
||||
Return a project from the compute.
|
||||
"""
|
||||
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/close", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -152,8 +152,8 @@ async def delete_compute_project(project: Project = Depends(dep_project)):
|
||||
# while True:
|
||||
# try:
|
||||
# (action, msg) = await asyncio.wait_for(queue.get(), 5)
|
||||
# if hasattr(msg, "__json__"):
|
||||
# msg = json.dumps({"action": action, "event": msg.__json__()}, sort_keys=True)
|
||||
# if hasattr(msg, "asdict"):
|
||||
# msg = json.dumps({"action": action, "event": msg.asdict()}, sort_keys=True)
|
||||
# else:
|
||||
# msg = json.dumps({"action": action, "event": msg}, sort_keys=True)
|
||||
# log.debug("Send notification: %s", msg)
|
||||
|
||||
@@ -76,7 +76,7 @@ async def create_qemu_node(project_id: UUID, node_data: schemas.QemuCreate):
|
||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||
setattr(vm, name, value)
|
||||
|
||||
return vm.__json__()
|
||||
return vm.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.Qemu)
|
||||
@@ -85,7 +85,7 @@ def get_qemu_node(node: QemuVM = Depends(dep_node)):
|
||||
Return a Qemu node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.Qemu)
|
||||
@@ -101,7 +101,7 @@ async def update_qemu_node(node_data: schemas.QemuUpdate, node: QemuVM = Depends
|
||||
if hasattr(node, name) and getattr(node, name) != value:
|
||||
await node.update_property(name, value)
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -120,7 +120,7 @@ async def duplicate_qemu_node(destination_node_id: UUID = Body(..., embed=True),
|
||||
"""
|
||||
|
||||
new_node = await Qemu.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/resize_disk", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -196,7 +196,7 @@ async def create_qemu_node_nio(
|
||||
|
||||
nio = Qemu.instance().create_nio(jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.adapter_add_nio_binding(adapter_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -218,7 +218,7 @@ async def update_qemu_node_nio(
|
||||
if nio_data.suspend:
|
||||
nio.suspend = nio_data.suspend
|
||||
await node.adapter_update_nio_binding(adapter_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -80,7 +80,7 @@ async def create_virtualbox_node(project_id: UUID, node_data: schemas.VirtualBox
|
||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||
setattr(vm, name, value)
|
||||
|
||||
return vm.__json__()
|
||||
return vm.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.VirtualBox)
|
||||
@@ -89,7 +89,7 @@ def get_virtualbox_node(node: VirtualBoxVM = Depends(dep_node)):
|
||||
Return a VirtualBox node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.VirtualBox)
|
||||
@@ -131,7 +131,7 @@ async def update_virtualbox_node(node_data: schemas.VirtualBoxUpdate, node: Virt
|
||||
setattr(node, name, value)
|
||||
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -203,7 +203,7 @@ async def create_virtualbox_node_nio(
|
||||
|
||||
nio = VirtualBox.instance().create_nio(jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.adapter_add_nio_binding(adapter_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -225,7 +225,7 @@ async def update_virtualbox_node_nio(
|
||||
if nio_data.suspend:
|
||||
nio.suspend = nio_data.suspend
|
||||
await node.adapter_update_nio_binding(adapter_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -73,7 +73,7 @@ async def create_vmware_node(project_id: UUID, node_data: schemas.VMwareCreate):
|
||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||
setattr(vm, name, value)
|
||||
|
||||
return vm.__json__()
|
||||
return vm.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.VMware)
|
||||
@@ -82,7 +82,7 @@ def get_vmware_node(node: VMwareVM = Depends(dep_node)):
|
||||
Return a VMware node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.VMware)
|
||||
@@ -99,7 +99,7 @@ def update_vmware_node(node_data: schemas.VMwareUpdate, node: VMwareVM = Depends
|
||||
setattr(node, name, value)
|
||||
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -171,7 +171,7 @@ async def create_vmware_node_nio(
|
||||
|
||||
nio = VMware.instance().create_nio(jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.adapter_add_nio_binding(adapter_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -191,7 +191,7 @@ async def update_vmware_node_nio(
|
||||
if nio_data.filters:
|
||||
nio.filters = nio_data.filters
|
||||
await node.adapter_update_nio_binding(adapter_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -66,7 +66,7 @@ async def create_vpcs_node(project_id: UUID, node_data: schemas.VPCSCreate):
|
||||
startup_script=node_data.get("startup_script"),
|
||||
)
|
||||
|
||||
return vm.__json__()
|
||||
return vm.asdict()
|
||||
|
||||
|
||||
@router.get("/{node_id}", response_model=schemas.VPCS)
|
||||
@@ -75,7 +75,7 @@ def get_vpcs_node(node: VPCSVM = Depends(dep_node)):
|
||||
Return a VPCS node.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.VPCS)
|
||||
@@ -89,7 +89,7 @@ def update_vpcs_node(node_data: schemas.VPCSUpdate, node: VPCSVM = Depends(dep_n
|
||||
node.console = node_data.get("console", node.console)
|
||||
node.console_type = node_data.get("console_type", node.console_type)
|
||||
node.updated()
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -108,7 +108,7 @@ async def duplicate_vpcs_node(destination_node_id: UUID = Body(..., embed=True),
|
||||
"""
|
||||
|
||||
new_node = await VPCS.instance().duplicate_node(node.id, str(destination_node_id))
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/start", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -163,7 +163,7 @@ async def create_vpcs_node_nio(
|
||||
|
||||
nio = VPCS.instance().create_nio(jsonable_encoder(nio_data, exclude_unset=True))
|
||||
await node.port_add_nio_binding(port_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.put(
|
||||
@@ -183,7 +183,7 @@ async def update_vpcs_node_nio(
|
||||
if nio_data.filters:
|
||||
nio.filters = nio_data.filters
|
||||
await node.port_update_nio_binding(port_number, nio)
|
||||
return nio.__json__()
|
||||
return nio.asdict()
|
||||
|
||||
|
||||
@router.delete("/{node_id}/adapters/{adapter_number}/ports/{port_number}/nio", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -36,4 +36,4 @@ async def get_appliances(update: Optional[bool] = None, symbol_theme: Optional[s
|
||||
if update:
|
||||
await controller.appliance_manager.download_appliances()
|
||||
controller.appliance_manager.load_appliances(symbol_theme=symbol_theme)
|
||||
return [c.__json__() for c in controller.appliance_manager.appliances.values()]
|
||||
return [c.asdict() for c in controller.appliance_manager.appliances.values()]
|
||||
@@ -38,7 +38,7 @@ async def get_drawings(project_id: UUID):
|
||||
"""
|
||||
|
||||
project = await Controller.instance().get_loaded_project(str(project_id))
|
||||
return [v.__json__() for v in project.drawings.values()]
|
||||
return [v.asdict() for v in project.drawings.values()]
|
||||
|
||||
|
||||
@router.post("", status_code=status.HTTP_201_CREATED, response_model=schemas.Drawing)
|
||||
@@ -49,7 +49,7 @@ async def create_drawing(project_id: UUID, drawing_data: schemas.Drawing):
|
||||
|
||||
project = await Controller.instance().get_loaded_project(str(project_id))
|
||||
drawing = await project.add_drawing(**jsonable_encoder(drawing_data, exclude_unset=True))
|
||||
return drawing.__json__()
|
||||
return drawing.asdict()
|
||||
|
||||
|
||||
@router.get("/{drawing_id}", response_model=schemas.Drawing, response_model_exclude_unset=True)
|
||||
@@ -60,7 +60,7 @@ async def get_drawing(project_id: UUID, drawing_id: UUID):
|
||||
|
||||
project = await Controller.instance().get_loaded_project(str(project_id))
|
||||
drawing = project.get_drawing(str(drawing_id))
|
||||
return drawing.__json__()
|
||||
return drawing.asdict()
|
||||
|
||||
|
||||
@router.put("/{drawing_id}", response_model=schemas.Drawing, response_model_exclude_unset=True)
|
||||
@@ -72,7 +72,7 @@ async def update_drawing(project_id: UUID, drawing_id: UUID, drawing_data: schem
|
||||
project = await Controller.instance().get_loaded_project(str(project_id))
|
||||
drawing = project.get_drawing(str(drawing_id))
|
||||
await drawing.update(**jsonable_encoder(drawing_data, exclude_unset=True))
|
||||
return drawing.__json__()
|
||||
return drawing.asdict()
|
||||
|
||||
|
||||
@router.delete("/{drawing_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -54,7 +54,7 @@ async def get_gns3vm_settings():
|
||||
Return the GNS3 VM settings.
|
||||
"""
|
||||
|
||||
return Controller.instance().gns3vm.__json__()
|
||||
return Controller.instance().gns3vm.asdict()
|
||||
|
||||
|
||||
@router.put("", response_model=schemas.GNS3VM, response_model_exclude_unset=True)
|
||||
@@ -67,4 +67,4 @@ async def update_gns3vm_settings(gns3vm_data: schemas.GNS3VM):
|
||||
gns3_vm = controller.gns3vm
|
||||
await gns3_vm.update_settings(jsonable_encoder(gns3vm_data, exclude_unset=True))
|
||||
controller.save()
|
||||
return gns3_vm.__json__()
|
||||
return gns3_vm.asdict()
|
||||
@@ -59,7 +59,7 @@ async def get_links(project_id: UUID):
|
||||
"""
|
||||
|
||||
project = await Controller.instance().get_loaded_project(str(project_id))
|
||||
return [v.__json__() for v in project.links.values()]
|
||||
return [v.asdict() for v in project.links.values()]
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -94,7 +94,7 @@ async def create_link(project_id: UUID, link_data: schemas.LinkCreate):
|
||||
except ControllerError as e:
|
||||
await project.delete_link(link.id)
|
||||
raise e
|
||||
return link.__json__()
|
||||
return link.asdict()
|
||||
|
||||
|
||||
@router.get("/{link_id}/available_filters")
|
||||
@@ -112,7 +112,7 @@ async def get_link(link: Link = Depends(dep_link)):
|
||||
Return a link.
|
||||
"""
|
||||
|
||||
return link.__json__()
|
||||
return link.asdict()
|
||||
|
||||
|
||||
@router.put("/{link_id}", response_model=schemas.Link, response_model_exclude_unset=True)
|
||||
@@ -128,7 +128,7 @@ async def update_link(link_data: schemas.LinkUpdate, link: Link = Depends(dep_li
|
||||
await link.update_suspend(link_data["suspend"])
|
||||
if "nodes" in link_data:
|
||||
await link.update_nodes(link_data["nodes"])
|
||||
return link.__json__()
|
||||
return link.asdict()
|
||||
|
||||
|
||||
@router.delete("/{link_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -148,7 +148,7 @@ async def reset_link(link: Link = Depends(dep_link)):
|
||||
"""
|
||||
|
||||
await link.reset()
|
||||
return link.__json__()
|
||||
return link.asdict()
|
||||
|
||||
|
||||
@router.post("/{link_id}/capture/start", status_code=status.HTTP_201_CREATED, response_model=schemas.Link)
|
||||
@@ -161,7 +161,7 @@ async def start_capture(capture_data: dict, link: Link = Depends(dep_link)):
|
||||
data_link_type=capture_data.get("data_link_type", "DLT_EN10MB"),
|
||||
capture_file_name=capture_data.get("capture_file_name"),
|
||||
)
|
||||
return link.__json__()
|
||||
return link.asdict()
|
||||
|
||||
|
||||
@router.post("/{link_id}/capture/stop", status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
@@ -117,7 +117,7 @@ async def create_node(node_data: schemas.NodeCreate, project: Project = Depends(
|
||||
compute = controller.get_compute(str(node_data.compute_id))
|
||||
node_data = jsonable_encoder(node_data, exclude_unset=True)
|
||||
node = await project.add_node(compute, node_data.pop("name"), node_data.pop("node_id", None), **node_data)
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.get("", response_model=List[schemas.Node], response_model_exclude_unset=True)
|
||||
@@ -126,7 +126,7 @@ async def get_nodes(project: Project = Depends(dep_project)):
|
||||
Return all nodes belonging to a given project.
|
||||
"""
|
||||
|
||||
return [v.__json__() for v in project.nodes.values()]
|
||||
return [v.asdict() for v in project.nodes.values()]
|
||||
|
||||
|
||||
@router.post("/start", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -172,7 +172,7 @@ def get_node(node: Node = Depends(dep_node)):
|
||||
Return a node from a given project.
|
||||
"""
|
||||
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.put("/{node_id}", response_model=schemas.Node, response_model_exclude_unset=True)
|
||||
@@ -189,7 +189,7 @@ async def update_node(node_data: schemas.NodeUpdate, node: Node = Depends(dep_no
|
||||
node_data.pop("compute_id", None)
|
||||
|
||||
await node.update(**node_data)
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
|
||||
|
||||
@router.delete(
|
||||
@@ -212,7 +212,7 @@ async def duplicate_node(duplicate_data: schemas.NodeDuplicate, node: Node = Dep
|
||||
"""
|
||||
|
||||
new_node = await node.project.duplicate_node(node, duplicate_data.x, duplicate_data.y, duplicate_data.z)
|
||||
return new_node.__json__()
|
||||
return new_node.asdict()
|
||||
|
||||
|
||||
@router.post("/{node_id}/start", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -259,7 +259,7 @@ async def get_node_links(node: Node = Depends(dep_node)):
|
||||
|
||||
links = []
|
||||
for link in node.links:
|
||||
links.append(link.__json__())
|
||||
links.append(link.asdict())
|
||||
return links
|
||||
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ def get_projects():
|
||||
"""
|
||||
|
||||
controller = Controller.instance()
|
||||
return [p.__json__() for p in controller.projects.values()]
|
||||
return [p.asdict() for p in controller.projects.values()]
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -87,7 +87,7 @@ async def create_project(project_data: schemas.ProjectCreate):
|
||||
|
||||
controller = Controller.instance()
|
||||
project = await controller.add_project(**jsonable_encoder(project_data, exclude_unset=True))
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.get("/{project_id}", response_model=schemas.Project)
|
||||
@@ -96,7 +96,7 @@ def get_project(project: Project = Depends(dep_project)):
|
||||
Return a project.
|
||||
"""
|
||||
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.put("/{project_id}", response_model=schemas.Project, response_model_exclude_unset=True)
|
||||
@@ -106,7 +106,7 @@ async def update_project(project_data: schemas.ProjectUpdate, project: Project =
|
||||
"""
|
||||
|
||||
await project.update(**jsonable_encoder(project_data, exclude_unset=True))
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.delete("/{project_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -154,7 +154,7 @@ async def open_project(project: Project = Depends(dep_project)):
|
||||
"""
|
||||
|
||||
await project.open()
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -176,7 +176,7 @@ async def load_project(path: str = Body(..., embed=True)):
|
||||
project = await controller.load_project(
|
||||
dot_gns3_file,
|
||||
)
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.get("/{project_id}/notifications")
|
||||
@@ -323,7 +323,7 @@ async def import_project(project_id: UUID, request: Request, path: Optional[Path
|
||||
log.info(f"Project '{project.name}' imported in {time.time() - begin:.4f} seconds")
|
||||
except OSError as e:
|
||||
raise ControllerError(f"Could not import the project: {e}")
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
|
||||
|
||||
@router.post(
|
||||
@@ -348,7 +348,7 @@ async def duplicate_project(project_data: schemas.ProjectDuplicate, project: Pro
|
||||
new_project = await project.duplicate(
|
||||
name=project_data.name, location=location, reset_mac_addresses=reset_mac_addresses
|
||||
)
|
||||
return new_project.__json__()
|
||||
return new_project.asdict()
|
||||
|
||||
|
||||
@router.get("/{project_id}/files/{file_path:path}")
|
||||
|
||||
@@ -52,7 +52,7 @@ async def create_snapshot(snapshot_data: schemas.SnapshotCreate, project: Projec
|
||||
"""
|
||||
|
||||
snapshot = await project.snapshot(snapshot_data.name)
|
||||
return snapshot.__json__()
|
||||
return snapshot.asdict()
|
||||
|
||||
|
||||
@router.get("", response_model=List[schemas.Snapshot], response_model_exclude_unset=True)
|
||||
@@ -62,7 +62,7 @@ def get_snapshots(project: Project = Depends(dep_project)):
|
||||
"""
|
||||
|
||||
snapshots = [s for s in project.snapshots.values()]
|
||||
return [s.__json__() for s in sorted(snapshots, key=lambda s: (s.created_at, s.name))]
|
||||
return [s.asdict() for s in sorted(snapshots, key=lambda s: (s.created_at, s.name))]
|
||||
|
||||
|
||||
@router.delete("/{snapshot_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -82,4 +82,4 @@ async def restore_snapshot(snapshot_id: UUID, project: Project = Depends(dep_pro
|
||||
|
||||
snapshot = project.get_snapshot(str(snapshot_id))
|
||||
project = await snapshot.restore()
|
||||
return project.__json__()
|
||||
return project.asdict()
|
||||
@@ -145,4 +145,4 @@ async def create_node_from_template(
|
||||
node = await project.add_node_from_template(
|
||||
template, x=template_usage.x, y=template_usage.y, compute_id=template_usage.compute_id
|
||||
)
|
||||
return node.__json__()
|
||||
return node.asdict()
|
||||
Reference in new issue
Block a user