GNS3 / gns3-server

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

API : Created containers doesn't appear in the projects. #1341

Closed AJNOURI closed 6 years ago

AJNOURI commented 6 years ago

Using the API to create a contrainer, the command seems to be executed propertly:

$curl -X POST "http://192.168.0.152:3080/v2/compute/projects/47d20179-6de3-4ff4-a091-c2bd93adfdc8/docker/nodes" -d '{"name": "ovs1", "image": "gns3/openvswitch:latest", "console_type": "telnet"}'
{
    "adapters": 1,
    "aux": 5007,
    "console": 5006,
    "console_http_path": "/",
    "console_http_port": 80,
    "console_resolution": "1024x768",
    "console_type": "telnet",
    "container_id": "f3c85bdae355b25de3c3de5fef16c620ecc51bab026b91b5b0f6b0721c534c2d",
    "environment": null,
    "extra_hosts": null,
    "image": "gns3/openvswitch:latest",
    "name": "ovs1",
    "node_directory": "/home/ajn/GNS3/projects/47d20179-6de3-4ff4-a091-c2bd93adfdc8/project-files/docker/e5fb79ac-1b73-4f9e-adfc-d205010c2019",
    "node_id": "e5fb79ac-1b73-4f9e-adfc-d205010c2019",
    "project_id": "47d20179-6de3-4ff4-a091-c2bd93adfdc8",
    "start_command": null,
    "status": "stopped"

But the container is neither listed in the list of nodes nor showed in the GUI:

$ curl -X GET "http://192.168.0.152:3080/v2/projects/47d20179-6de3-4ff4-a091-c2bd93adfdc8/nodes"[
    {
        "command_line": "",
        "compute_id": "local",
        "console": 5000,
        "console_host": "192.168.0.152",
        "console_type": "telnet",
        "first_port_name": null,
        "height": 59,
        "label": {
            "rotation": 0,
            "style": "font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;",
            "text": "VPCS1",
            "x": 4,
            "y": -25
        },
        "name": "VPCS1",
        "node_directory": "/home/ajn/GNS3/projects/47d20179-6de3-4ff4-a091-c2bd93adfdc8/project-files/vpcs/a26a9b73-2555-4ab3-9fe0-7bdb7bec65ac",
        "node_id": "a26a9b73-2555-4ab3-9fe0-7bdb7bec65ac",
        "node_type": "vpcs",
        "port_name_format": "Ethernet{0}",
        "port_segment_size": 0,
        "ports": [
            {
                "adapter_number": 0,
                "data_link_types": {
                    "Ethernet": "DLT_EN10MB"
                },
                "link_type": "ethernet",
                "name": "Ethernet0",
                "port_number": 0,
                "short_name": "e0"
            }
        ],
        "project_id": "47d20179-6de3-4ff4-a091-c2bd93adfdc8",
        "properties": {},
        "status": "stopped",
        "symbol": ":/symbols/computer.svg",
        "width": 65,
        "x": 0,
        "y": 0,
        "z": 0
    },
    {
        "command_line": "",
        "compute_id": "local",
        "console": 5002,
        "console_host": "192.168.0.152",
        "console_type": "telnet",
        "first_port_name": null,
        "height": 59,
        "label": {
            "rotation": 0,
            "style": "font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;",
            "text": "VPCS2",
            "x": 4,
            "y": -25
        },
        "name": "VPCS2",
        "node_directory": "/home/ajn/GNS3/projects/47d20179-6de3-4ff4-a091-c2bd93adfdc8/project-files/vpcs/2118b97a-7ea6-4bf0-9b31-4db93f067991",
        "node_id": "2118b97a-7ea6-4bf0-9b31-4db93f067991",
        "node_type": "vpcs",
        "port_name_format": "Ethernet{0}",
        "port_segment_size": 0,
        "ports": [
            {
                "adapter_number": 0,
                "data_link_types": {
                    "Ethernet": "DLT_EN10MB"
                },
                "link_type": "ethernet",
                "name": "Ethernet0",
                "port_number": 0,
                "short_name": "e0"
            }
        ],
        "project_id": "47d20179-6de3-4ff4-a091-c2bd93adfdc8",
        "properties": {},
        "status": "stopped",
        "symbol": ":/symbols/computer.svg",
        "width": 65,
        "x": -133,
        "y": -2,
        "z": 0
    }

selection_004_01_06


ghost commented 6 years ago

No bug, works as designed.

The controller manages only the projects, nodes, links, ... that are created/modified by controller API calls. By using compute API calls you bypass the controller. It gets no information about those changes.

In short: Don't use the compute API unless you want to implement your own controller. Exclusively use the controller API.

See also the warning in http://api.gns3.net/en/2.1/endpoints.html#compute-endpoints

Warning These endpoints should be considered low level and private. They should only be used by the controller or for debugging purposes.

ghost commented 6 years ago

Here an example to create a docker node with the controller API (done with Postman). Mandatory parameters are compute_id ("vm" for the GNS3-VM), name and node_type. In the properties parameter you add the node specific parameters. Those are documented in the compute API for that node type.

create_node

AJNOURI commented 6 years ago

ok, got it. Thanks @ehlers for your explanations.

nabilovski commented 6 years ago

Thank you very much Mr. ehlers, it worked for me. Could you help me adding an Ubuntu virtual machine the same way? Thanks :)

ghost commented 6 years ago

No, after this initial help you have to figure that out by yourself.

Tip: Besides using the documentation you can use the debug logging or Wireshark to look, how the GNS3 GUI uses the API.

nabilovski commented 6 years ago

Which documentation? Ok I'll do that but I need your help in case it doesn't work hh. Thank you

ghost commented 6 years ago

I won't answer here. This is for discussing issues in GNS3, use https://gns3.com for support. But as I don't have an account there, other people will (hopefully) answer your questions.

nabilovski commented 6 years ago

Please I am kind of stuck here, would you like to show me how to do it? Thank you