GNS3 / gns3-server

GNS3 server
GNU General Public License v3.0
811 stars 263 forks source link

API call to get running children #1677

Open grossmj opened 5 years ago

grossmj commented 5 years ago

Idea from B3r3n:

Would it be possible to have a GNS3 REST order to get the running children on a specific server. As master father of all these processes, should be easy to deploy that and it would permit to identify which projects/nodes are running and then be able to start/stop the associated process. Today I TCP poll node console to figure out what's running for real (my PHP control tower). Upon telnet console issue (also detected with a simple perl script greping the display), I can relaunch failed nodes).

candlerb commented 5 years ago

Could you clarify what you'd like to see?

The REST API under /v2/projects/<uuid>/nodes already returns a status field for each node (e.g. "started", "stopped"), so you can see which nodes are running - it should update automatically if the child dies.

Is it the PID of the node process you want to see, so you can forcibly kill it?

You can use the REST API to ask gns3server to stop the process for you. However if you've configured "On Close: Send the shutdown signal (ACPI)" then a hung process may not respond. (An option in the API to force-kill a process in that situation would be helpful).

Or are you looking for the PID of something else? e.g. if you're using dynamips then is it the dynamips hypervisor process you're after?

I have a couple of other suggestions.

(1) If all you want is a list of running children across all projects, then you can run gns3server under systemd, and don't use Type=forking (#1678). systemd can tell you exactly what the child processes are at any instant:

$ systemctl status gns3-server@nsrc | head
● gns3-server@nsrc.service - GNS3 network simulator
   Loaded: loaded (/etc/systemd/system/gns3-server@.service; indirect; vendor preset: enabled)
   Active: active (running) since Sun 2019-10-27 20:33:26 GMT; 2 days ago
 Main PID: 8126 (gns3server)
    Tasks: 499 (limit: 4915)
   CGroup: /system.slice/system-gns3\x2dserver.slice/gns3-server@nsrc.service
           ├─ 8126 /usr/share/gns3/gns3-server/bin/python /usr/bin/gns3server
           ├─ 8132 /usr/bin/ubridge -H 0.0.0.0:33703
           ├─ 8220 /usr/bin/qemu-system-x86_64 -name noc -m 2560M -smp cpus=4 -enable-kvm ...
           ├─ 8222 /usr/bin/ubridge -H 0.0.0.0:32837

API access may be available over dbus.

(2) For qemu children, the API returns "command_line" for each node, so you can search /proc for a process running exactly the same command line. Or you can extract the pattern -serial telnet:127.0.0.1:5002,server,nowait and use lsof -i :5002 -sTCP:LISTEN to find which process is bound to port 5002.

Those are a bit hacky I'll agree :-)