Skip to content

EVE-NG API 参考文档

EVE-NG API 使用 JSend 规范,返回如下格式的 JSON 响应:

{
    "code": 404,
    "message": "Requested folder does not exist (60008).",
    "status": "fail"
}
  • code:HTTP 响应状态码
  • message:描述响应信息的字符串
  • status:表示响应状态的单词,共有五种类型:
    • success — 对应 2xx HTTP 状态码
    • unauthorized — 对应 400 HTTP 状态码,表示用户会话已超时
    • unauthorized — 对应 401 HTTP 状态码,表示用户需要登录
    • forbidden — 对应 403 HTTP 状态码,表示用户权限不足
    • fail — 对应其他 4xx HTTP 状态码
    • error — 对应 5xx HTTP 状态码

以下 API 请求用于登录和登出流程。所有其他 API 请求都需要已认证的用户。

社区版(Community Edition):

curl -s -b /tmp/cookie -c /tmp/cookie -X POST \
  -d '{"username":"admin","password":"eve"}' \
  http://127.0.0.1/api/auth/login

专业版(Pro Edition):

curl -k -s -b /tmp/cookie -c /tmp/cookie -X POST \
  -d '{"username":"admin","password":"eve","html5":"0"}' \
  https://127.0.0.1/api/auth/login

登录成功返回:

{
    "code": 200,
    "message": "User logged in (90013).",
    "status": "success"
}
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/auth

已认证用户可以获取自己的信息:

{
    "code": 200,
    "data": {
        "email": "root@localhost",
        "folder": "/",
        "lab": null,
        "lang": "en",
        "name": "EVE-NG Administrator",
        "role": "admin",
        "tenant": "0",
        "username": "admin"
    },
    "message": "User has been loaded (90002).",
    "status": "success"
}
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/auth/logout

所有用户均可登出,此请求不会失败:

{
    "code": 200,
    "message": "User logged out (90019).",
    "status": "success"
}

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/status

已认证用户可以获取系统统计信息:

{
    "code": 200,
    "data": {
        "cached": 5,
        "cpu": 1,
        "disk": 31,
        "dynamips": 0,
        "iol": 0,
        "mem": 8,
        "qemu": 0,
        "qemu_version": "2.4.0",
        "swap": 0,
        "version": "development"
    },
    "message": "Fetched system status (60001).",
    "status": "success"
}
字段说明
cached缓存使用量
cpuCPU 使用率
disk磁盘使用率
dynamips运行中的 Dynamips 节点数
iol运行中的 IOL 节点数
mem内存使用率
qemu运行中的 QEMU 节点数
qemu_versionQEMU 版本
swapSwap 使用率
versionEVE-NG 版本

列出节点模板(List Node Templates)

Section titled “列出节点模板(List Node Templates)”
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/list/templates/

已认证用户可以列出所有可用的节点模板:

{
    "code": 200,
    "data": {
        "a10": "A10 vThunder",
        "acs": "Cisco ACS",
        "asa": "Cisco ASA",
        "asav": "Cisco ASAv",
        "bigip": "F5 BIG-IP LTM VE",
        "brocadevadx": "Brocade vADX",
        "c1710": "Cisco IOS 1710 (Dynamips)",
        "c3725": "Cisco IOS 3725 (Dynamips)",
        "c7200": "Cisco IOS 7206VXR (Dynamips)",
        "clearpass": "Aruba ClearPass",
        "coeus": "Cisco Web Security Appliance",
        "cpsg": "CheckPoint Security Gateway VE",
        "csr1000v": "Cisco CSR 1000V",
        "cumulus": "Cumulus VX",
        "extremexos": "ExtremeXOS",
        "fortinet": "Fortinet FortiGate",
        "hpvsr": "HP VSR1000",
        "iol": "Cisco IOL",
        "ise": "Cisco ISE",
        "linux": "Linux",
        "mikrotik": "MikroTik RouterOS",
        "nsvpx": "Citrix Netscaler",
        "olive": "Juniper Olive",
        "ostinato": "Ostinato",
        "paloalto": "Palo Alto VM-100 Firewall",
        "sourcefire": "Cisco Sourcefire",
        "sterra": "S-Terra",
        "timos": "Alcatel 7750 SR",
        "titanium": "Cisco NX-OSv (Titanium)",
        "ucspe": "Cisco UCS-PE",
        "veos": "Arista vEOS",
        "vios": "Cisco vIOS",
        "viosl2": "Cisco vIOS L2",
        "vmx": "Juniper vMX",
        "vnam": "Cisco vNAM",
        "vsrx": "Juniper vSRX",
        "vsrxng": "Juniper vSRX NextGen",
        "vwaas": "Cisco vWAAS",
        "vwlc": "Cisco vWLC",
        "vyos": "VyOS",
        "win": "Windows",
        "xrv": "Cisco XRv"
    },
    "message": "Successfully listed node templates (60003).",
    "status": "success"
}
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/list/templates/iol

返回结果会包含该模板所有可用的镜像及配置选项:

{
    "code": 200,
    "data": {
        "description": "Cisco IOL",
        "options": {
            "config": {
                "list": {
                    "Saved": "Saved",
                    "Unconfigured": "Unconfigured"
                },
                "name": "Startup configuration",
                "type": "list",
                "value": "Unconfigured"
            },
            "delay": {
                "name": "Delay (s)",
                "type": "input",
                "value": 0
            },
            "ethernet": {
                "name": "Ethernet portgroups (4 int each)",
                "type": "input",
                "value": 1
            },
            "icon": {
                "list": {
                    "Router.png": "Router",
                    "Switch L3.png": "Switch L3",
                    "Switch.png": "Switch"
                },
                "name": "Icon",
                "type": "list",
                "value": "Router.png"
            },
            "image": {
                "list": {
                    "L2-IPBASEK9-M-15.1-20130726.bin": "L2-IPBASEK9-M-15.1-20130726.bin",
                    "L3-ADVENTERPRISEK9-M-15.4-1T.bin": "L3-ADVENTERPRISEK9-M-15.4-1T.bin"
                },
                "name": "Image",
                "type": "list",
                "value": "L3-ADVENTERPRISEK9-M-15.4-1T.bin"
            },
            "name": {
                "name": "Name/prefix",
                "type": "input",
                "value": "R"
            },
            "nvram": {
                "name": "NVRAM",
                "type": "input",
                "value": 1024
            },
            "ram": {
                "name": "RAM",
                "type": "input",
                "value": 256
            },
            "serial": {
                "name": "Serial portgroups (4 int each)",
                "type": "input",
                "value": 1
            }
        },
        "type": "iol"
    },
    "message": "Successfully listed node template (60032).",
    "status": "success"
}

列出网络类型(List Network Types)

Section titled “列出网络类型(List Network Types)”
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/list/networks

已认证用户可以列出所有可用的网络类型:

{
    "code": 200,
    "data": {
        "bridge": "bridge",
        "ovs": "ovs",
        "pnet0": "pnet0",
        "pnet1": "pnet1",
        "pnet2": "pnet2",
        "pnet3": "pnet3",
        "pnet4": "pnet4",
        "pnet5": "pnet5",
        "pnet6": "pnet6",
        "pnet7": "pnet7",
        "pnet8": "pnet8",
        "pnet9": "pnet9"
    },
    "message": "Successfully listed network types (60002).",
    "status": "success"
}

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/list/roles

已认证用户可以列出所有用户角色:

{
    "code": 200,
    "data": {
        "admin": "Administrator",
        "editor": "Editor",
        "user": "User"
    },
    "message": "Successfully listed user roles (60041).",
    "status": "success"
}
角色说明
admin管理员(Administrator)
editor编辑者(Editor)
user普通用户(User)

文件夹导航(Navigating Between Folders)

Section titled “文件夹导航(Navigating Between Folders)”

以下 API 请求用于将文件夹和实验作为文件进行管理。

列出文件夹内容(List Content Inside a Folder)

Section titled “列出文件夹内容(List Content Inside a Folder)”
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/folders/User1

已认证用户可以列出文件夹内的内容:

{
    "code": 200,
    "data": {
        "folders": [
            { "name": "..", "path": "/" },
            { "name": "Folder 1", "path": "/User1/Folder 1" },
            { "name": "Folder 2", "path": "/User1/Folder 2" },
            { "name": "Folder 3", "path": "/User1/Folder 3" }
        ],
        "labs": [
            { "file": "Lab 1.unl", "path": "/User1/Lab 1.unl" },
            { "file": "Lab 2.unl", "path": "/User1/Lab 2.unl" },
            { "file": "Lab 3.unl", "path": "/User1/Lab 3.unl" }
        ]
    },
    "message": "Successfully listed path (60007).",
    "status": "success"
}

文件夹和实验使用不同的数组列出。

curl -s -c /tmp/cookie -b /tmp/cookie -X POST \
  -d '{"path":"/User1/Folder 3","name":"New Folder"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/folders

已认证用户可以在指定路径下创建文件夹:

{
    "code": 200,
    "message": "Folder has been created (60014).",
    "status": "success"
}
参数说明
path父文件夹路径
name新文件夹名称

移动/重命名文件夹(Move/Rename a Folder)

Section titled “移动/重命名文件夹(Move/Rename a Folder)”
curl -s -c /tmp/cookie -b /tmp/cookie -X PUT \
  -d '{"path":"/User1/Folder 3/Test Folder"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/folders/User1/Folder%203/New%20Folder
{
    "code": 200,
    "message": "Folder moved (60049).",
    "status": "success"
}
curl -s -c /tmp/cookie -b /tmp/cookie -X DELETE \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/folders/User1/Folder%203/Test%20Folder
{
    "code": 200,
    "message": "Folder has been deleted (60012).",
    "status": "success"
}

以下 API 请求用于管理 EVE-NG 用户和权限。

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/users/

已认证用户可以获取所有 EVE-NG 用户:

{
    "code": 200,
    "data": {
        "admin": {
            "email": "root@localhost",
            "expiration": "-1",
            "folder": "/User1",
            "ip": "127.0.0.1",
            "lab": null,
            "name": "UNetLab Administrator",
            "pexpiration": "-1",
            "pod": "0",
            "role": "admin",
            "session": "1447319929",
            "username": "admin"
        },
        "User1": {
            "email": "User1.Lastname@gmail.com",
            "expiration": "-1",
            "folder": "/Featured/Cisco/Basic",
            "ip": "192.168.19.1",
            "lab": "/Featured/Cisco/Basic/STP.unl",
            "name": "User1 Lastname",
            "pexpiration": "-1",
            "pod": "1",
            "role": "admin",
            "session": "1447319925",
            "username": "User1"
        }
    },
    "message": "Successfully listed users (60040).",
    "status": "success"
}
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/users/admin
{
    "code": 200,
    "data": {
        "email": "root@localhost",
        "expiration": "-1",
        "ip": "127.0.0.1",
        "name": "UNetLab Administrator",
        "pexpiration": "-1",
        "pod": "0",
        "role": "admin",
        "session": "1447319929",
        "username": "admin"
    },
    "message": "Successfully listed users (60040).",
    "status": "success"
}
curl -s -c /tmp/cookie -b /tmp/cookie -X POST \
  -d '{"username":"testuser","name":"Test User","email":"test@unetlab.com","password":"testpassword1","role":"user","expiration":"-1","pod":127,"pexpiration":"1451520000"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/users
{
    "code": 201,
    "message": "User saved (60042).",
    "status": "success"
}

参数说明:

参数是否必填说明
username必填唯一字母数字字符串,用于登录
password必填用户登录密码
email可选用户邮箱地址
expiration可选用户有效截止日期(UNIX 时间戳),-1 表示永不过期
name可选用户描述/称呼
role可选参见”列出用户角色”
curl -s -c /tmp/cookie -b /tmp/cookie -X PUT \
  -d '{"name":"New Test User","email":"testuser@unetlab.com","password":"newpassword","role":"user","expiration":"1451520000","pod":127,"pexpiration":"-1"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/users/testuser
{
    "code": 200,
    "message": "User saved (60042).",
    "status": "success"
}

参数说明:

参数说明
email用户邮箱地址
expiration用户有效截止日期(UNIX 时间戳),-1 表示永不过期
name用户描述/称呼
password用户登录密码
role参见”列出用户角色”
curl -s -c /tmp/cookie -b /tmp/cookie -X DELETE \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/users/testuser
{
    "code": 201,
    "message": "User saved (60042).",
    "status": "success"
}

以下 API 请求用于管理实验以及实验内的对象(如节点、网络等)。

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl

已认证用户可以获取实验信息:

{
    "code": 200,
    "data": {
        "author": "User1 Lastname",
        "body": "",
        "description": "A new test lab.",
        "filename": "Lab 1.unl",
        "id": "d34628dd-cc1d-4e52-8f91-4a0673985d87",
        "name": "Lab 1",
        "version": "1"
    },
    "message": "Lab has been loaded (60020).",
    "status": "success"
}

获取实验中的网络(Get Networks in a Lab)

Section titled “获取实验中的网络(Get Networks in a Lab)”

获取所有网络:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/networks
{
    "code": 200,
    "data": {
        "1": { "id": 1, "left": 409, "name": "Net OVS", "top": 345, "type": "ovs" },
        "2": { "id": 2, "left": 583, "name": "Net2", "top": 261, "type": "bridge" },
        "3": { "id": 3, "left": 256, "name": "Net3", "top": 276, "type": "bridge" },
        "4": { "id": 4, "left": 583, "name": "Net4", "top": 483, "type": "bridge" },
        "5": { "id": 5, "left": 409, "name": "Net5", "top": 491, "type": "bridge" }
    },
    "message": "Successfully listed networks (60004).",
    "status": "success"
}

获取单个网络:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/networks/1
{
    "code": 200,
    "data": {
        "left": 409,
        "name": "Net OVS",
        "top": 345,
        "type": "ovs"
    },
    "message": "Successfully listed network (60005).",
    "status": "success"
}
字段说明
id网络 ID
name网络名称
type网络类型(bridge / ovs / pnetX)
left距左侧边距(像素)
top距顶部边距(像素)

获取所有远程端点(Get All Remote Endpoints)

Section titled “获取所有远程端点(Get All Remote Endpoints)”
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/links

获取实验中的所有可用端点(以太网和串行接口):

{
    "code": 200,
    "data": {
        "ethernet": {
            "1": "Net OVS",
            "2": "Net2",
            "3": "Net3",
            "4": "Net4",
            "5": "Net5"
        },
        "serial": {
            "3": {
                "1": "R3 s1/0",
                "17": "R3 s1/1",
                "33": "R3 s1/2",
                "49": "R3 s1/3"
            },
            "4": {
                "1": "R4 s1/0",
                "17": "R4 s1/1",
                "33": "R4 s1/2",
                "49": "R4 s1/3"
            }
        }
    },
    "message": "Fetced all lab networks and serial endpoints (60024).",
    "status": "success"
}

获取实验中的节点(Get Nodes in a Lab)

Section titled “获取实验中的节点(Get Nodes in a Lab)”

获取所有节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes
{
    "code": 200,
    "data": {
        "1": {
            "console": "telnet",
            "cpu": 1,
            "delay": 0,
            "ethernet": 4,
            "icon": "Router.png",
            "id": 1,
            "image": "vios-adventerprisek9-m-15.4-1.3.0.181",
            "left": 358,
            "name": "R1",
            "ram": 512,
            "status": 0,
            "template": "vios",
            "top": 330,
            "type": "qemu",
            "url": "telnet://127.0.0.1:32769",
            "uuid": "ab60e9de-2599-4b67-919a-b769fb6e270d"
        }
    },
    "message": "Successfully listed nodes (60026).",
    "status": "success"
}

获取单个节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/1
{
    "code": 200,
    "data": {
        "config": "Unconfigured",
        "console": "telnet",
        "cpu": 1,
        "delay": 0,
        "ethernet": 4,
        "icon": "Router.png",
        "image": "vios-adventerprisek9-m-15.4-1.3.0.181",
        "left": 358,
        "name": "R1",
        "ram": 512,
        "status": 0,
        "template": "vios",
        "top": 330,
        "type": "qemu",
        "url": "telnet://127.0.0.1:32769",
        "uuid": "ab60e9de-2599-4b67-919a-b769fb6e270d"
    },
    "message": "Successfully listed node (60025).",
    "status": "success"
}

启动所有节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/start
{
    "code": 400,
    "message": "Failed to start node (12).",
    "status": "fail"
}

启动单个节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/1/start
{
    "code": 200,
    "message": "Node started (80049).",
    "status": "success"
}

停止所有节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/stop
{
    "code": 200,
    "message": "Nodes stopped (80050).",
    "status": "success"
}

停止单个节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/1/stop
{
    "code": 200,
    "message": "Node stopped (80051).",
    "status": "success"
}

清除所有节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/wipe
{
    "code": 200,
    "message": "Nodes cleared (80052).",
    "status": "success"
}

清除单个节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/1/wipe
{
    "code": 200,
    "message": "Node cleared (80053).",
    "status": "success"
}

导出所有节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/export
{
    "code": 200,
    "message": "Nodes exported (80057).",
    "status": "success"
}

导出单个节点:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/1/export
{
    "code": 200,
    "message": "Node exported (80058).",
    "status": "success"
}

获取节点接口(Get Node Interfaces)

Section titled “获取节点接口(Get Node Interfaces)”
curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/nodes/1/interfaces
{
    "code": 200,
    "data": {
        "ethernet": [
            { "name": "Gi0/0", "network_id": 1 },
            { "name": "Gi0/1", "network_id": 3 },
            { "name": "Gi0/2", "network_id": 5 },
            { "name": "Gi0/3", "network_id": 0 }
        ],
        "serial": []
    },
    "message": "Successfully listed node interfaces (60030).",
    "status": "success"
}
字段说明
name接口名称
network_id连接的网络 ID,0 表示未连接

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/topology
{
    "code": "200",
    "data": [
        {
            "destination": "network1",
            "destination_label": "",
            "destination_type": "network",
            "source": "node1",
            "source_label": "Gi0/0",
            "source_type": "node",
            "type": "ethernet"
        },
        {
            "destination": "node1",
            "destination_label": "Gi0/1",
            "destination_type": "node",
            "source": "node3",
            "source_label": "e0/1",
            "source_type": "node",
            "type": "ethernet"
        }
    ],
    "message": "Topology loaded",
    "status": "success"
}
字段说明
source源端点 ID
source_label源接口标签
source_type源端点类型(node / network)
destination目标端点 ID
destination_label目标接口标签
destination_type目标端点类型(node / network)
type连接类型(ethernet / serial)

获取实验中的图片(Get Pictures in a Lab)

Section titled “获取实验中的图片(Get Pictures in a Lab)”

获取所有图片:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/pictures
{
    "code": 200,
    "data": {
        "1": {
            "height": 201,
            "id": 1,
            "name": "RR Logo",
            "type": "image/png",
            "width": 410
        }
    },
    "message": "Successfully listed pictures (60028).",
    "status": "success"
}

获取单个图片:

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/pictures/1
{
    "code": 200,
    "data": {
        "height": 201,
        "id": "1",
        "map": "<area shape='circle' coords='248,66,30' href='telnet://:'>\n",
        "name": "RR Logo",
        "type": "image/png",
        "width": 410
    },
    "message": "Picture loaded",
    "status": "success"
}

获取图片数据(支持调整大小):

curl -s -c /tmp/cookie -b /tmp/cookie -X GET \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Lab%201.unl/pictures/1/data/32/32

创建和管理实验(Creating & Managing Labs)

Section titled “创建和管理实验(Creating & Managing Labs)”
curl -s -c /tmp/cookie -b /tmp/cookie -X POST \
  -d '{"path":"/User1/Folder 3","name":"New Lab","version":"1","author":"User1 Lastname","description":"A new demo lab","body":"Lab usage and guide"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs
{
    "code": 200,
    "message": "Lab has been created (60019).",
    "status": "success"
}
参数说明
path实验所属文件夹路径
name实验名称
version实验版本
author作者名称
description实验描述
body实验使用指南/说明

移动实验到其他文件夹(Move a Lab)

Section titled “移动实验到其他文件夹(Move a Lab)”
curl -s -c /tmp/cookie -b /tmp/cookie -X PUT \
  -d '{"path":"/User1/Folder 2"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Folder%203/New%20Lab.unl/move
{
    "code": 200,
    "message": "Lab moved (60035).",
    "status": "success"
}
curl -s -c /tmp/cookie -b /tmp/cookie -X PUT \
  -d '{"name":"Different Lab","version":"2","author":"AD","description":"A different demo lab"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Folder%202/New%20Lab.unl
{
    "code": 200,
    "message": "Lab has been saved (60023).",
    "status": "success"
}

添加网络到实验(Add a Network to a Lab)

Section titled “添加网络到实验(Add a Network to a Lab)”
curl -s -c /tmp/cookie -b /tmp/cookie -X POST \
  -d '{"type":"bridge","name":"Core Network","left":"35%","top":"25%"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Folder%202/Different%20Lab.unl/networks
{
    "code": 201,
    "message": "Network has been added to the lab (60006).",
    "status": "success"
}
参数是否必填说明
type必填参见”列出网络类型”
name可选网络名称(如 “Core Network”),默认为 NetX(X = 网络ID)
left可选距左侧边距,百分比(如 35%),默认在 30% 到 70% 之间随机
top可选距顶部边距,百分比(如 25%),默认在 30% 到 70% 之间随机

添加节点到实验(Add a Node to a Lab)

Section titled “添加节点到实验(Add a Node to a Lab)”
curl -s -c /tmp/cookie -b /tmp/cookie -X POST \
  -d '{"type":"qemu","template":"vios","config":"Unconfigured","delay":0,"icon":"Router.png","image":"vios-adventerprisek9-m-15.5.3M","name":"Core Router 1","left":"35%","top":"25%","ram":"1024","console":"telnet","cpu":1,"ethernet":2,"uuid":"641a4800-1b19-427c-ae87-4a8ee90b7790"}' \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Folder%202/Different%20Lab.unl/nodes
{
    "code": 201,
    "message": "Lab has been saved (60023).",
    "status": "success"
}

通用参数:

参数是否必填说明
type必填节点类型,可选:ioldynamipsqemu
template必填参见”列出节点模板”
config可选Unconfigured(未配置)或 Saved(已保存),默认 Unconfigured
delay可选启动节点前等待秒数,默认 0
icon可选显示图标(位于 /opt/unetlab/html/images/icons/),默认 Router.png
image可选启动节点使用的镜像,默认为”列出节点模板”中的最新镜像
left可选距左侧边距,百分比,默认随机
name可选节点名称,默认 NodeX(X = 节点ID)
ram可选节点内存(MB),默认 1024
top可选距顶部边距,百分比,默认随机

IOL 节点专用参数:

参数说明
ethernet以太网端口组数量(每组配置 4 个接口),默认 2
nvramNVRAM 大小(KB),默认 1024
serial串行端口组数量(每组配置 4 个接口),默认 2

Dynamips 节点专用参数:

参数说明
idlepcDynamips 优化值(如 0x80369ac4),默认 0x0(无优化)
nvramNVRAM 大小(KB),默认 1024
slot[0-9]+特定插槽中配置的模块(如 slot1=NM-1FE-TX

QEMU 节点专用参数:

参数说明
console控制台类型,telnetvnc,默认 telnet
cpuCPU 数量,默认 1
ethernet以太网接口数量,默认 4
uuidUUID,默认为随机 UUID
curl -s -c /tmp/cookie -b /tmp/cookie -X DELETE \
  -H 'Content-type: application/json' \
  http://127.0.0.1/api/labs/User1/Folder%202/Different%20Lab.unl
{
    "code": 200,
    "message": "Lab has been deleted (60022).",
    "status": "success"
}

类别方法接口路径说明
认证POST/api/auth/login用户登录
认证GET/api/auth获取当前用户信息
认证GET/api/auth/logout用户登出
系统GET/api/status获取系统状态
查询GET/api/list/templates/列出所有节点模板
查询GET/api/list/templates/{type}获取单个模板详情
查询GET/api/list/networks列出所有网络类型
查询GET/api/list/roles列出所有用户角色
文件夹GET/api/folders/{path}列出文件夹内容
文件夹POST/api/folders创建新文件夹
文件夹PUT/api/folders/{path}移动/重命名文件夹
文件夹DELETE/api/folders/{path}删除文件夹
用户GET/api/users/获取所有用户
用户GET/api/users/{username}获取单个用户
用户POST/api/users添加新用户
用户PUT/api/users/{username}编辑用户
用户DELETE/api/users/{username}删除用户
实验GET/api/labs/{path}获取实验信息
实验POST/api/labs创建新实验
实验PUT/api/labs/{path}编辑实验
实验PUT/api/labs/{path}/move移动实验
实验DELETE/api/labs/{path}删除实验
网络GET/api/labs/{path}/networks获取实验所有网络
网络GET/api/labs/{path}/networks/{id}获取单个网络
网络POST/api/labs/{path}/networks添加网络
节点GET/api/labs/{path}/nodes获取实验所有节点
节点GET/api/labs/{path}/nodes/{id}获取单个节点
节点POST/api/labs/{path}/nodes添加节点
节点GET/api/labs/{path}/nodes/start启动所有节点
节点GET/api/labs/{path}/nodes/{id}/start启动单个节点
节点GET/api/labs/{path}/nodes/stop停止所有节点
节点GET/api/labs/{path}/nodes/{id}/stop停止单个节点
节点GET/api/labs/{path}/nodes/wipe清除所有节点
节点GET/api/labs/{path}/nodes/{id}/wipe清除单个节点
节点GET/api/labs/{path}/nodes/export导出所有节点
节点GET/api/labs/{path}/nodes/{id}/export导出单个节点
节点GET/api/labs/{path}/nodes/{id}/interfaces获取节点接口
拓扑GET/api/labs/{path}/topology获取实验拓扑
端点GET/api/labs/{path}/links获取所有远程端点
图片GET/api/labs/{path}/pictures获取实验所有图片
图片GET/api/labs/{path}/pictures/{id}获取单个图片
图片GET/api/labs/{path}/pictures/{id}/data/{w}/{h}获取调整大小后的图片数据