2015-02-18 12:06:13 +02:00
|
|
|
Communications
|
|
|
|
===============
|
|
|
|
|
|
|
|
All the communication are done over HTTP using JSON.
|
|
|
|
|
2015-01-14 02:05:26 +02:00
|
|
|
Errors
|
|
|
|
======
|
|
|
|
|
|
|
|
In case of error a standard HTTP error is raise and you got a
|
|
|
|
JSON like that
|
|
|
|
|
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
{
|
|
|
|
"status": 409,
|
|
|
|
"message": "Conflict"
|
|
|
|
}
|
2015-02-25 10:47:55 +02:00
|
|
|
|
2015-02-27 19:39:20 +02:00
|
|
|
Sample session using curl
|
|
|
|
=========================
|
|
|
|
|
|
|
|
.. warning::
|
|
|
|
|
|
|
|
Beware the output of this sample is truncated in order
|
|
|
|
to simplify the understanding. Please read the
|
|
|
|
documentation for the exact output.
|
|
|
|
|
|
|
|
You can check the server version with a simple curl command:
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
2016-05-18 12:23:45 +03:00
|
|
|
# curl "http://localhost:3080/v1/version"
|
2015-02-27 19:39:20 +02:00
|
|
|
{
|
2016-04-18 22:15:24 +03:00
|
|
|
"version": "2.0.0dev1"
|
2015-02-27 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
The next step is to create a project.
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
2016-05-18 12:23:45 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects" -d '{"name": "test"}'
|
2015-02-27 19:39:20 +02:00
|
|
|
{
|
2016-04-18 22:15:24 +03:00
|
|
|
"name": "test",
|
|
|
|
"path": null,
|
|
|
|
"project_id": "994d95b6-7dd4-467b-898c-14cf34900b7b",
|
|
|
|
"temporary": false
|
2015-02-27 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 20:18:37 +03:00
|
|
|
With this project id we can now create two VPCS Node.
|
2015-02-27 19:39:20 +02:00
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
2016-05-18 12:23:45 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects/42f9feee-3217-4104-981e-85d5f0a806ec/vpcs/vms" -d '{"name": "VPCS 1"}'
|
2015-02-27 19:39:20 +02:00
|
|
|
{
|
|
|
|
"console": 2000,
|
|
|
|
"name": "VPCS 1",
|
|
|
|
"project_id": "42f9feee-3217-4104-981e-85d5f0a806ec",
|
|
|
|
"vm_id": "24d2e16b-fbef-4259-ae34-7bc21a41ee28"
|
|
|
|
}%
|
|
|
|
|
2016-05-18 12:23:45 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects/42f9feee-3217-4104-981e-85d5f0a806ec/vpcs/vms" -d '{"name": "VPCS 2"}'
|
2015-02-27 19:39:20 +02:00
|
|
|
{
|
|
|
|
"console": 2001,
|
|
|
|
"name": "VPCS 2",
|
|
|
|
"vm_id": "daefc24a-103c-4717-8e01-6517d931c1ae"
|
|
|
|
}
|
|
|
|
|
|
|
|
Now we need to link the two VPCS. The first step is to allocate on the remote servers
|
|
|
|
two UDP ports.
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
2016-03-25 19:35:55 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects/42f9feee-3217-4104-981e-85d5f0a806ec/ports/udp" -d '{}'
|
2015-02-27 19:39:20 +02:00
|
|
|
{
|
|
|
|
"udp_port": 10000
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:35:55 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects/42f9feee-3217-4104-981e-85d5f0a806ec/ports/udp" -d '{}'
|
2015-02-27 19:39:20 +02:00
|
|
|
{
|
|
|
|
"udp_port": 10001
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
We can create the bidirectionnal communication between the two VPCS. The
|
|
|
|
communication is made by creating two UDP tunnels.
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
2016-05-18 12:23:45 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects/42f9feee-3217-4104-981e-85d5f0a806ec/vpcs/vms/24d2e16b-fbef-4259-ae34-7bc21a41ee28/adapters/0/ports/0/nio" -d '{"lport": 10000, "rhost": "127.0.0.1", "rport": 10001, "type": "nio_udp"}'
|
2015-02-27 19:39:20 +02:00
|
|
|
{
|
|
|
|
"lport": 10000,
|
|
|
|
"rhost": "127.0.0.1",
|
|
|
|
"rport": 10001,
|
|
|
|
"type": "nio_udp"
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:35:55 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects/42f9feee-3217-4104-981e-85d5f0a806ec/vpcs/vms/daefc24a-103c-4717-8e01-6517d931c1ae/adapters/0/ports/0/nio" -d '{"lport": 10001, "rhost": "127.0.0.1", "rport": 10000, "type": "nio_udp"}'
|
2015-02-27 19:39:20 +02:00
|
|
|
{
|
|
|
|
"lport": 10001,
|
|
|
|
"rhost": "127.0.0.1",
|
|
|
|
"rport": 10000,
|
|
|
|
"type": "nio_udp"
|
|
|
|
}
|
|
|
|
|
2016-05-12 20:18:37 +03:00
|
|
|
Now we can start the two Node
|
2015-02-27 19:39:20 +02:00
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
2016-05-18 12:23:45 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects/42f9feee-3217-4104-981e-85d5f0a806ec/vpcs/vms/24d2e16b-fbef-4259-ae34-7bc21a41ee28/start" -d "{}"
|
2016-03-25 19:35:55 +03:00
|
|
|
# curl -X POST "http://localhost:3080/v1/projects/42f9feee-3217-4104-981e-85d5f0a806ec/vpcs/vms/daefc24a-103c-4717-8e01-6517d931c1ae/start" -d '{}'
|
2015-02-27 19:39:20 +02:00
|
|
|
|
2016-05-12 20:18:37 +03:00
|
|
|
Everything should be started now. You can connect via telnet to the different Node.
|
|
|
|
The port is the field console in the create Node request.
|
2015-02-27 19:39:20 +02:00
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
2016-05-18 12:23:45 +03:00
|
|
|
# telnet 127.0.0.1 2000
|
2015-02-27 19:39:20 +02:00
|
|
|
Trying 127.0.0.1...
|
|
|
|
Connected to localhost.
|
|
|
|
Escape character is '^]'.
|
|
|
|
|
|
|
|
Welcome to Virtual PC Simulator, version 0.6
|
|
|
|
Dedicated to Daling.
|
|
|
|
Build time: Dec 29 2014 12:51:46
|
|
|
|
Copyright (c) 2007-2014, Paul Meng (mirnshi@gmail.com)
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
VPCS is free software, distributed under the terms of the "BSD" licence.
|
|
|
|
Source code and license can be found at vpcs.sf.net.
|
|
|
|
For more information, please visit wiki.freecode.com.cn.
|
|
|
|
|
|
|
|
Press '?' to get help.
|
|
|
|
|
|
|
|
VPCS> ip 192.168.1.1
|
|
|
|
Checking for duplicate address...
|
|
|
|
PC1 : 192.168.1.1 255.255.255.0
|
|
|
|
|
|
|
|
VPCS> disconnect
|
|
|
|
|
|
|
|
Good-bye
|
|
|
|
Connection closed by foreign host.
|
|
|
|
|
2016-05-18 12:23:45 +03:00
|
|
|
# telnet 127.0.0.1 2001
|
2015-02-27 19:39:20 +02:00
|
|
|
telnet 127.0.0.1 2001
|
|
|
|
Trying 127.0.0.1...
|
|
|
|
Connected to localhost.
|
|
|
|
Escape character is '^]'.
|
|
|
|
|
|
|
|
Welcome to Virtual PC Simulator, version 0.6
|
|
|
|
Dedicated to Daling.
|
|
|
|
Build time: Dec 29 2014 12:51:46
|
|
|
|
Copyright (c) 2007-2014, Paul Meng (mirnshi@gmail.com)
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
VPCS is free software, distributed under the terms of the "BSD" licence.
|
|
|
|
Source code and license can be found at vpcs.sf.net.
|
|
|
|
For more information, please visit wiki.freecode.com.cn.
|
|
|
|
|
|
|
|
Press '?' to get help.
|
|
|
|
|
|
|
|
VPCS> ip 192.168.1.2
|
|
|
|
Checking for duplicate address...
|
|
|
|
PC1 : 192.168.1.2 255.255.255.0
|
|
|
|
|
|
|
|
VPCS> ping 192.168.1.1
|
|
|
|
84 bytes from 192.168.1.1 icmp_seq=1 ttl=64 time=0.179 ms
|
|
|
|
84 bytes from 192.168.1.1 icmp_seq=2 ttl=64 time=0.218 ms
|
|
|
|
84 bytes from 192.168.1.1 icmp_seq=3 ttl=64 time=0.190 ms
|
|
|
|
84 bytes from 192.168.1.1 icmp_seq=4 ttl=64 time=0.198 ms
|
|
|
|
84 bytes from 192.168.1.1 icmp_seq=5 ttl=64 time=0.185 ms
|
|
|
|
|
|
|
|
VPCS> disconnect
|
|
|
|
Good-bye
|
|
|
|
Connection closed by foreign host.
|
|
|
|
|
2015-02-25 10:47:55 +02:00
|
|
|
Limitations
|
|
|
|
============
|
|
|
|
|
|
|
|
Concurrency
|
|
|
|
------------
|
|
|
|
|
2016-05-12 20:18:37 +03:00
|
|
|
A node can't process multiple request in the same time. But you can make
|
|
|
|
multiple request on multiple node. It's transparent for the client
|
|
|
|
when the first request on a Node start a lock is acquire for this node id
|
2015-02-25 10:47:55 +02:00
|
|
|
and released for the next request at the end. You can safely send all
|
|
|
|
the requests in the same time and let the server manage an efficent concurrency.
|
|
|
|
|
|
|
|
We think it can be a little slower for some operations, but it's remove a big
|
2016-05-12 20:18:37 +03:00
|
|
|
complexity for the client due to the fact only some command on some node can be
|
2015-02-25 10:47:55 +02:00
|
|
|
concurrent.
|
|
|
|
|
|
|
|
|
2016-03-25 19:35:55 +03:00
|
|
|
Authentication
|
2015-02-25 11:29:20 +02:00
|
|
|
-----------------
|
|
|
|
|
2016-04-18 21:55:22 +03:00
|
|
|
You can use HTTP basic auth to protect the access to the API. And run
|
|
|
|
the API over HTTPS.
|
2015-02-25 11:29:20 +02:00
|
|
|
|
|
|
|
|
2015-06-26 15:41:58 +03:00
|
|
|
Notifications
|
|
|
|
=============
|
|
|
|
|
2016-03-17 16:15:30 +02:00
|
|
|
You can receive notification from the server if you listen the HTTP stream /notifications or the websocket.
|
2015-06-26 15:41:58 +03:00
|
|
|
|
|
|
|
The available notification are:
|
2016-03-17 16:15:30 +02:00
|
|
|
* ping
|
2016-05-12 20:18:37 +03:00
|
|
|
* node.created
|
|
|
|
* node.updated
|
|
|
|
* node.deleted
|
2016-03-17 16:15:30 +02:00
|
|
|
* log.error
|
2016-03-18 17:55:54 +02:00
|
|
|
* log.warning
|
2016-04-18 22:15:24 +03:00
|
|
|
* log.info
|
2015-06-26 15:41:58 +03:00
|
|
|
|
2016-03-07 18:57:12 +02:00
|
|
|
Previous versions
|
|
|
|
=================
|
|
|
|
|
|
|
|
API version 1
|
|
|
|
-------------
|
2016-05-18 12:25:41 +03:00
|
|
|
Shipped with GNS3 1.3, 1.4 and 1.5. This API doesn't support the controller system.
|
2016-03-07 18:57:12 +02:00
|
|
|
|