查看: 268|回复: 2

EVE-NG API中文文档

377

主题

881

回帖

985万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
9850511

推广达人宣传达人突出贡献优秀版主论坛元老

QQ

1 EVE-NG API 文档

1.1 概述

EVE-NG API 使用 JSend 格式的 JSON 响应,语法如下:

{ "code": 404, "message": "Requested folder does not exist (60008).", "status": "fail" }

  • code: HTTP 响应代码。
  • message: 解释当前情况的简单字符串。
  • status: 解释响应的单个单词。以下是五种状态类型:
    • success: 用于 20x HTTP 代码。
    • unauthorized: 用于 400 HTTP 代码,表示用户会话已过期。
    • unauthorized: 用于 401 HTTP 代码,表示用户需要登录。
    • forbidden: 用于 403 HTTP 代码,表示用户权限不足。
    • fail: 用于其他 40x HTTP 代码。
    • error: 用于 50x HTTP 代码。

默认的 Web-UI 仅使用 API,因此这是开发新 Web-UI 主题、集成等的关键部分。请注意,每个用户只能从一个位置登录。如果同一用户登录两次,第二次登录将禁用第一次登录。

EVE-NG Pro 使用 SSL 协议。所有示例都需要添加 -khttps作为协议,因此请根据此文档进行调整。

建议: 由于 EVE-NG 代码的演变,某些调用的文档可能已过时(支持更多参数)。建议使用 GET 方法获取完整的参数集。使用浏览器的开发者工具(网络选项卡)来监视 API 调用,并通过标头、请求和响应获取最新的 API 信息。

1.2 认证

以下 API 请求涉及登录和注销过程。所有其他 API 请求都需要经过身份验证的用户。

1.2.1 登录

社区版:

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

Pro 版:

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" }

1.2.2 用户信息

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"
}

1.2.3 注销

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" }

1.3 系统状态

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"
}

1.4 列表节点模板

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)",
    "cda": "Cisco Context Directory Agent",
    "cips": "Cisco IPS",
    "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": {
          "Desktop.png": "Desktop",
          "Firewall.png": "Firewall",
          "Frame Relay.png": "Frame Relay",
          "HUB.png": "HUB",
          "Load Balancer.png": "Load Balancer",
          "MPLS.png": "MPLS",
          "Network Analyzer.png": "Network Analyzer",
          "Router.png": "Router",
          "Server.png": "Server",
          "Switch L3.png": "Switch L3",
          "Switch.png": "Switch",
          "WAN Optimizer.png": "WAN Optimizer"
        },
        "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"
}

1.5 列表网络类型

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"
}

1.6 列表用户角色

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"
}

1.7 导航文件夹

以下 API 请求允许管理文件夹和实验室作为文件。

1.7.1 列出文件夹内容

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"
}

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

1.7.2 添加新文件夹

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" }

1.7.3 移动/重命名现有文件夹

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" }

1.7.4 删除现有文件夹

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" }

1.8 管理用户

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

1.8.1 获取用户

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"
}

1.8.2 获取单个用户

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"
}

1.8.3 添加新用户

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

经过身份验证的用户可以添加新的 EVE-NG 用户:

{ "code": 201, "message": "User saved (60042).", "status": "success" }

参数:

  • email: 用户的电子邮件地址。
  • expiration: 用户的有效期(UNIX 时间戳),如果永不过期则为 -1
  • name: 用户的描述,通常是称呼。
  • password(必填): 用户登录时使用的密码。
  • role: 参见“列表用户角色”。
  • username(必填): 用于登录的唯一字母数字字符串。

1.8.4 编辑用户

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

经过身份验证的用户可以编辑现有的 EVE-NG 用户:

{ "code": 200, "message": "User saved (60042).", "status": "success" }

参数:

  • email: 用户的电子邮件地址。
  • expiration: 用户的有效期(UNIX 时间戳),如果永不过期则为 -1
  • name: 用户的描述,通常是称呼。
  • password: 用户登录时使用的密码。
  • role: 参见“列表用户角色”。

1.8.5 删除用户

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

经过身份验证的用户可以删除现有的 EVE-NG 用户:

{ "code": 201, "message": "User saved (60042).", "status": "success" }

1.9 管理实验室

以下 API 请求允许管理实验室以及实验室内的对象,如节点、网络等。

1.9.1 获取实验室

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"
}

1.9.2 获取实验室中的所有网络

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"
}

1.9.3 获取实验室中的单个网络

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"
}

1.9.4 获取实验室中的所有节点

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"
    },
    "2": {
      "console": "telnet",
      "cpu": 1,
      "delay": 0,
      "ethernet": 4,
      "icon": "Router.png",
      "id": 2,
      "image": "vios-adventerprisek9-m-15.4-1.3.0.181",
      "left": 501,
      "name": "R2",
      "ram": 512,
      "status": 0,
      "template": "vios",
      "top": 330,
      "type": "qemu",
      "url": "telnet://127.0.0.1:32770",
      "uuid": "206323a6-000b-40bc-a765-9c7e7e5751ee"
    },
    "3": {
      "console": "telnet",
      "delay": 0,
      "ethernet": 1,
      "icon": "Router.png",
      "id": 3,
      "image": "L3-ADVENTERPRISEK9-M-15.4-1T.bin",
      "left": 430,
      "name": "R3",
      "nvram": 1024,
      "ram": 256,
      "serial": 1,
      "status": 0,
      "template": "iol",
      "top": 529,
      "type": "iol",
      "url": "telnet://127.0.0.1:32771"
    },
    "4": {
      "console": "telnet",
      "delay": 0,
      "ethernet": 1,
      "icon": "Router.png",
      "id": 4,
      "image": "L3-ADVENTERPRISEK9-M-15.4-1T.bin",
      "left": 430,
      "name": "R4",
      "nvram": 1024,
      "ram": 256,
      "serial": 1,
      "status": 0,
      "template": "iol",
      "top": 192,
      "type": "iol",
      "url": "telnet://127.0.0.1:32772"
    }
  },
  "message": "Successfully listed nodes (60026).",
  "status": "success"
}

1.9.5 获取实验室中的单个节点

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"
}

1.9.6 启动实验室中的所有节点

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" }

1.9.7 启动实验室中的单个节点

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" }

1.9.8 停止实验室中的所有节点

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" }

1.9.9 停止实验室中的单个节点

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" }

1.9.10 擦除实验室中的所有节点

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" }

擦除意味着删除所有用户配置,包括启动配置、VLAN 等。下次启动时将从选定的映像重建节点

1.9.11 擦除实验室中的单个节点

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" }

1.9.12 导出实验室中的所有节点配置

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" }

导出意味着将启动配置保存到实验室文件中。擦除节点后重新启动将加载之前导出的启动配置。

1.9.13 导出实验室中的单个节点配置

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" }

1.9.14 获取节点的配置接口

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"
}

1.9.15 获取实验室拓扑

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": "network1",
      "destination_label": "",
      "destination_type": "network",
      "source": "node2",
      "source_label": "Gi0/0",
      "source_type": "node",
      "type": "ethernet"
    },
    {
      "destination": "network1",
      "destination_label": "",
      "destination_type": "network",
      "source": "node3",
      "source_label": "e0/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"
    },
    {
      "destination": "node1",
      "destination_label": "Gi0/2",
      "destination_type": "node",
      "source": "node3",
      "source_label": "e0/2",
      "source_type": "node",
      "type": "ethernet"
    },
    {
      "destination": "network1",
      "destination_label": "",
      "destination_type": "network",
      "source": "node4",
      "source_label": "e0/0",
      "source_type": "node",
      "type": "ethernet"
    },
    {
      "destination": "node2",
      "destination_label": "Gi0/1",
      "destination_type": "node",
      "source": "node4",
      "source_label": "e0/1",
      "source_type": "node",
      "type": "ethernet"
    },
    {
      "destination": "node2",
      "destination_label": "Gi0/2",
      "destination_type": "node",
      "source": "node4",
      "source_label": "e0/2",
      "source_type": "node",
      "type": "ethernet"
    }
  ],
  "message": "Topology loaded",
  "status": "success"
}

1.9.16 获取实验室中的所有图片

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"
}

1.9.17 获取实验室中的单个图片

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"
}

1.9.18 创建新实验室

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" }

1.9.19 将现有实验室移动到不同文件夹

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" }

1.9.20 编辑现有实验室

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" }

1.9.21 删除现有实验室

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" }

1.9.22 添加新网络到实验室

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" }

参数:

  • left: 左边距,以百分比表示(例如 35%),默认值是 30%70%之间的随机值。
  • name: 网络名称(例如 Core Network),默认值是 NetXX = network_id)。
  • top: 上边距,以百分比表示(例如 25%),默认值是 30%70%之间的随机值。
  • type(必填): 参见“列表网络类型”。

1.9.23 添加新节点到实验室

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" }

参数:

  • config: 可以是 UnconfiguredSaved,默认是 Unconfigured
  • delay: 启动节点前的等待时间(秒),默认是 0
  • icon: 用于显示节点的图标(位于 /opt/unetlab/html/images/icons/),默认是 Router.png
  • image: 用于启动节点的镜像,默认是“列表节点模板”中包含的最新镜像。
  • left: 左边距,以百分比表示(例如 35%),默认值是 30%70%之间的随机值。
  • name: 节点名称(例如 Core1),默认值是 NodeXX = node_id)。
  • ram: 节点配置的 RAM 大小(MB),默认是 1024
  • template(必填): 参见“列表节点模板”。
  • top: 上边距,以百分比表示(例如 25%),默认值是 30%70%之间的随机值。
  • type(必填): 可以是 ioldynamipsqemu

IOL 节点参数:

  • ethernet: 以太网端口组的数量(每个端口组配置四个接口),默认是 2
  • nvram: NVRAM 的大小(KB),默认是 1024
  • serial: 串行端口组的数量(每个端口组配置四个接口),默认是 2

Dynamips 节点参数:

  • idlepc: 用于 Dynamips 优化的值(例如 0x80369ac4),默认是 0x0(无优化)。
  • nvram: NVRAM 的大小(KB),默认是 1024
  • slot[0-9]+: 配置在特定插槽中的模块(例如 slot1=NM-1FE-TX)。

QEMU 节点参数:

  • console: 可以是 telnetvnc,默认是 telnet
  • cpu: 配置的 CPU 数量,默认是 1
  • ethernet: 以太网接口的数量,默认是 4。
  • uuid: 配置的 UUID,默认是随机 UUID(例如 641a4800-1b19-427c-ae87-4a8ee90b7790)。

1.10 总结

EVE-NG API 提供了丰富的功能,允许用户通过编程方式管理实验室、节点、网络、用户等。通过使用 API,可以实现自动化操作、集成到其他系统或开发自定义 Web-UI 主题。

注意事项:

  1. EVE-NG Pro 使用 SSL 协议,所有请求需要使用 https-k参数。
  2. 由于 EVE-NG 代码的不断更新,某些 API 文档可能已过时。建议使用浏览器的开发者工具监控 API 调用,以获取最新的参数和功能。
  3. 每个用户只能从一个位置登录,重复登录会禁用之前的会话。

通过合理利用 EVE-NG API,可以极大地提高实验室管理的效率和灵活性。

不忘初心
回复

使用道具 举报

4

主题

9

回帖

1681

积分

版主

Rank: 7Rank: 7Rank: 7

积分
1681
发表于 2025-4-8 20:07:37 | 显示全部楼层

有了Markdown以后友好好多了。

回复

使用道具 举报

0

主题

28

回帖

135

积分

新手上路

Rank: 1

积分
135
发表于 7 天前 | 显示全部楼层

谢谢楼主分享!!!

回复

使用道具 举报

本版积分规则

Copyright   ©2015-2024  EmulatedLab  Powered by Discuz!©   ( 浙ICP备2021010423号-1 )
快速回复 返回列表 返回顶部