EVE-NG API中文文档
<h1>1 EVE-NG API 文档</h1><h2>1.1 概述</h2>
<p>EVE-NG API 使用 JSend 格式的 JSON 响应,语法如下:</p>
<pre><code class="language-JSON">{ "code": 404, "message": "Requested folder does not exist (60008).", "status": "fail" }
</code></pre>
<ul>
<li><code>code</code>: HTTP 响应代码。</li>
<li><code>message</code>: 解释当前情况的简单字符串。</li>
<li><code>status</code>: 解释响应的单个单词。以下是五种状态类型:
<ul>
<li><code>success</code>: 用于 20x HTTP 代码。</li>
<li><code>unauthorized</code>: 用于 400 HTTP 代码,表示用户会话已过期。</li>
<li><code>unauthorized</code>: 用于 401 HTTP 代码,表示用户需要登录。</li>
<li><code>forbidden</code>: 用于 403 HTTP 代码,表示用户权限不足。</li>
<li><code>fail</code>: 用于其他 40x HTTP 代码。</li>
<li><code>error</code>: 用于 50x HTTP 代码。</li>
</ul>
</li>
</ul>
<p>默认的 Web-UI 仅使用 API,因此这是开发新 Web-UI 主题、集成等的关键部分。请注意,每个用户只能从一个位置登录。如果同一用户登录两次,第二次登录将禁用第一次登录。</p>
<p>EVE-NG Pro 使用 SSL 协议。所有示例都需要添加 <code>-k</code>和 <code>https</code>作为协议,因此请根据此文档进行调整。</p>
<p><strong>建议</strong>: 由于 EVE-NG 代码的演变,某些调用的文档可能已过时(支持更多参数)。建议使用 GET 方法获取完整的参数集。使用浏览器的开发者工具(网络选项卡)来监视 API 调用,并通过标头、请求和响应获取最新的 API 信息。</p>
<h2>1.2 认证</h2>
<p>以下 API 请求涉及登录和注销过程。所有其他 API 请求都需要经过身份验证的用户。</p>
<h3>1.2.1 登录</h3>
<p><strong>社区版</strong>:</p>
<pre><code class="language-Bash">curl -s -b /tmp/cookie -c /tmp/cookie -X POST -d '{"username":"admin","password":"eve"}' http://127.0.0.1/api/auth/login
</code></pre>
<p><strong>Pro 版</strong>:</p>
<pre><code class="language-Bash">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></pre>
<p>成功登录后,输出如下:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "User logged in (90013).", "status": "success" }
</code></pre>
<h3>1.2.2 用户信息</h3>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/auth
</code></pre>
<p>经过身份验证的用户可以获取自己的信息:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.2.3 注销</h3>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/auth/logout
</code></pre>
<p>所有用户都可以注销,此请求不会失败:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "User logged out (90019).", "status": "success" }
</code></pre>
<h2>1.3 系统状态</h2>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/status
</code></pre>
<p>经过身份验证的用户可以获取系统统计信息:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h2>1.4 列表节点模板</h2>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/list/templates/
</code></pre>
<p>经过身份验证的用户可以列出所有可用的节点模板:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<p>可以列出单个模板:</p>
<pre><code class="language-Bash">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></pre>
<p>所选模板的所有可用图像将包含在输出中:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h2>1.5 列表网络类型</h2>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/list/networks
</code></pre>
<p>经过身份验证的用户可以列出所有可用的网络类型:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h2>1.6 列表用户角色</h2>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/list/roles
</code></pre>
<p>经过身份验证的用户可以列出所有用户角色:</p>
<pre><code class="language-JSON">{
"code": 200,
"data": { "admin": "Administrator", "editor": "Editor", "user": "User" },
"message": "Successfully listed user roles (60041).",
"status": "success"
}
</code></pre>
<h2>1.7 导航文件夹</h2>
<p>以下 API 请求允许管理文件夹和实验室作为文件。</p>
<h3>1.7.1 列出文件夹内容</h3>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/folders/User1
</code></pre>
<p>经过身份验证的用户可以列出文件夹中的内容:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<p>文件夹和实验室分别使用不同的数组列出。</p>
<h3>1.7.2 添加新文件夹</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以在特定路径中添加文件夹:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Folder has been created (60014).", "status": "success" }
</code></pre>
<h3>1.7.3 移动/重命名现有文件夹</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以在特定路径中添加文件夹:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Folder moved (60049).", "status": "success" }
</code></pre>
<h3>1.7.4 删除现有文件夹</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以删除现有文件夹:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Folder has been deleted (60012).", "status": "success" }
</code></pre>
<h2>1.8 管理用户</h2>
<p>以下 API 请求允许管理 EVE-NG 用户和权限。</p>
<h3>1.8.1 获取用户</h3>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/users/
</code></pre>
<p>经过身份验证的用户可以获取所有 EVE-NG 用户:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.8.2 获取单个用户</h3>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X GET -H 'Content-type: application/json' http://127.0.0.1/api/users/admin
</code></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.8.3 添加新用户</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以添加新的 EVE-NG 用户:</p>
<pre><code class="language-JSON">{ "code": 201, "message": "User saved (60042).", "status": "success" }
</code></pre>
<p><strong>参数</strong>:</p>
<ul>
<li><code>email</code>: 用户的电子邮件地址。</li>
<li><code>expiration</code>: 用户的有效期(UNIX 时间戳),如果永不过期则为 <code>-1</code>。</li>
<li><code>name</code>: 用户的描述,通常是称呼。</li>
<li><code>password</code>(必填): 用户登录时使用的密码。</li>
<li><code>role</code>: 参见“列表用户角色”。</li>
<li><code>username</code>(必填): 用于登录的唯一字母数字字符串。</li>
</ul>
<h3>1.8.4 编辑用户</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以编辑现有的 EVE-NG 用户:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "User saved (60042).", "status": "success" }
</code></pre>
<p><strong>参数</strong>:</p>
<ul>
<li><code>email</code>: 用户的电子邮件地址。</li>
<li><code>expiration</code>: 用户的有效期(UNIX 时间戳),如果永不过期则为 <code>-1</code>。</li>
<li><code>name</code>: 用户的描述,通常是称呼。</li>
<li><code>password</code>: 用户登录时使用的密码。</li>
<li><code>role</code>: 参见“列表用户角色”。</li>
</ul>
<h3>1.8.5 删除用户</h3>
<pre><code class="language-Bash">curl -s -c /tmp/cookie -b /tmp/cookie -X DELETE -H 'Content-type: application/json' http://127.0.0.1/api/users/testuser
</code></pre>
<p>经过身份验证的用户可以删除现有的 EVE-NG 用户:</p>
<pre><code class="language-JSON">{ "code": 201, "message": "User saved (60042).", "status": "success" }
</code></pre>
<h2>1.9 管理实验室</h2>
<p>以下 API 请求允许管理实验室以及实验室内的对象,如节点、网络等。</p>
<h3>1.9.1 获取实验室</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以检索实验室:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.9.2 获取实验室中的所有网络</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以检索实验室中所有配置的网络:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.9.3 获取实验室中的单个网络</h3>
<pre><code class="language-Bash">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></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{
"code": 200,
"data": { "left": 409, "name": "Net OVS", "top": 345, "type": "ovs" },
"message": "Successfully listed network (60005).",
"status": "success"
}
</code></pre>
<h3>1.9.4 获取实验室中的所有节点</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以检索实验室中所有配置的节点:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.9.5 获取实验室中的单个节点</h3>
<pre><code class="language-Bash">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></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.9.6 启动实验室中的所有节点</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以启动实验室中所有配置的节点:</p>
<pre><code class="language-JSON">{ "code": 400, "message": "Failed to start node (12).", "status": "fail" }
</code></pre>
<h3>1.9.7 启动实验室中的单个节点</h3>
<pre><code class="language-Bash">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></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Node started (80049).", "status": "success" }
</code></pre>
<h3>1.9.8 停止实验室中的所有节点</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以停止实验室中所有配置的节点:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Nodes stopped (80050).", "status": "success" }
</code></pre>
<h3>1.9.9 停止实验室中的单个节点</h3>
<pre><code class="language-Bash">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></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Node stopped (80051).", "status": "success" }
</code></pre>
<h3>1.9.10 擦除实验室中的所有节点</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以擦除实验室中所有配置的节点:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Nodes cleared (80052).", "status": "success" }
</code></pre>
<p>擦除意味着删除所有用户配置,包括启动配置、VLAN 等。下次启动时将从选定的映像重建节点</p>
<h3>1.9.11 擦除实验室中的单个节点</h3>
<pre><code class="language-Bash">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></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Node cleared (80053).", "status": "success" }
</code></pre>
<h3>1.9.12 导出实验室中的所有节点配置</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以导出实验室中所有配置的节点:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Nodes exported (80057).", "status": "success" }
</code></pre>
<p>导出意味着将启动配置保存到实验室文件中。擦除节点后重新启动将加载之前导出的启动配置。</p>
<h3>1.9.13 导出实验室中的单个节点配置</h3>
<pre><code class="language-Bash">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></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Node exported (80058).", "status": "success" }
</code></pre>
<h3>1.9.14 获取节点的配置接口</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以检索节点的所有配置接口:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.9.15 获取实验室拓扑</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以获取实验室拓扑:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.9.16 获取实验室中的所有图片</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以获取实验室中所有配置的图片:</p>
<pre><code class="language-JSON">{
"code": 200,
"data": { "1": { "height": 201, "id": 1, "name": "RR Logo", "type": "image/png", "width": 410 } },
"message": "Successfully listed pictures (60028).",
"status": "success"
}
</code></pre>
<h3>1.9.17 获取实验室中的单个图片</h3>
<pre><code class="language-Bash">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></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{
"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"
}
</code></pre>
<h3>1.9.18 创建新实验室</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以创建新实验室:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Lab has been created (60019).", "status": "success" }
</code></pre>
<h3>1.9.19 将现有实验室移动到不同文件夹</h3>
<pre><code class="language-Bash">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></pre>
<p>输出如下:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Lab moved (60035).", "status": "success" }
</code></pre>
<h3>1.9.20 编辑现有实验室</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以编辑现有实验室:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Lab has been saved (60023).", "status": "success" }
</code></pre>
<h3>1.9.21 删除现有实验室</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以删除实验室:</p>
<pre><code class="language-JSON">{ "code": 200, "message": "Lab has been deleted (60022).", "status": "success" }
</code></pre>
<h3>1.9.22 添加新网络到实验室</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以向现有实验室添加网络:</p>
<pre><code class="language-JSON">{ "code": 201, "message": "Network has been added to the lab (60006).", "status": "success" }
</code></pre>
<p><strong>参数</strong>:</p>
<ul>
<li><code>left</code>: 左边距,以百分比表示(例如 <code>35%</code>),默认值是 <code>30%</code>到 <code>70%</code>之间的随机值。</li>
<li><code>name</code>: 网络名称(例如 <code>Core Network</code>),默认值是 <code>NetX</code>(<code>X = network_id</code>)。</li>
<li><code>top</code>: 上边距,以百分比表示(例如 <code>25%</code>),默认值是 <code>30%</code>到 <code>70%</code>之间的随机值。</li>
<li><code>type</code>(必填): 参见“列表网络类型”。</li>
</ul>
<h3>1.9.23 添加新节点到实验室</h3>
<pre><code class="language-Bash">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></pre>
<p>经过身份验证的用户可以向现有实验室添加节点:</p>
<pre><code class="language-JSON">{ "code": 201, "message": "Lab has been saved (60023).", "status": "success" }
</code></pre>
<p><strong>参数</strong>:</p>
<ul>
<li><code>config</code>: 可以是 <code>Unconfigured</code>或 <code>Saved</code>,默认是 <code>Unconfigured</code>。</li>
<li><code>delay</code>: 启动节点前的等待时间(秒),默认是 <code>0</code>。</li>
<li><code>icon</code>: 用于显示节点的图标(位于 <code>/opt/unetlab/html/images/icons/</code>),默认是 <code>Router.png</code>。</li>
<li><code>image</code>: 用于启动节点的镜像,默认是“列表节点模板”中包含的最新镜像。</li>
<li><code>left</code>: 左边距,以百分比表示(例如 <code>35%</code>),默认值是 <code>30%</code>到 <code>70%</code>之间的随机值。</li>
<li><code>name</code>: 节点名称(例如 <code>Core1</code>),默认值是 <code>NodeX</code>(<code>X = node_id</code>)。</li>
<li><code>ram</code>: 节点配置的 RAM 大小(MB),默认是 <code>1024</code>。</li>
<li><code>template</code>(必填): 参见“列表节点模板”。</li>
<li><code>top</code>: 上边距,以百分比表示(例如 <code>25%</code>),默认值是 <code>30%</code>到 <code>70%</code>之间的随机值。</li>
<li><code>type</code>(必填): 可以是 <code>iol</code>、<code>dynamips</code>或 <code>qemu</code>。</li>
</ul>
<p><strong>IOL 节点参数</strong>:</p>
<ul>
<li><code>ethernet</code>: 以太网端口组的数量(每个端口组配置四个接口),默认是 <code>2</code>。</li>
<li><code>nvram</code>: NVRAM 的大小(KB),默认是 <code>1024</code>。</li>
<li><code>serial</code>: 串行端口组的数量(每个端口组配置四个接口),默认是 <code>2</code>。</li>
</ul>
<p><strong>Dynamips 节点参数</strong>:</p>
<ul>
<li><code>idlepc</code>: 用于 Dynamips 优化的值(例如 <code>0x80369ac4</code>),默认是 <code>0x0</code>(无优化)。</li>
<li><code>nvram</code>: NVRAM 的大小(KB),默认是 <code>1024</code>。</li>
<li><code>slot+</code>: 配置在特定插槽中的模块(例如 <code>slot1=NM-1FE-TX</code>)。</li>
</ul>
<p><strong>QEMU 节点参数</strong>:</p>
<ul>
<li><code>console</code>: 可以是 <code>telnet</code>或 <code>vnc</code>,默认是 <code>telnet</code>。</li>
<li><code>cpu</code>: 配置的 CPU 数量,默认是 <code>1</code>。</li>
<li><code>ethernet</code>: 以太网接口的数量,默认是 4。</li>
<li><code>uuid</code>: 配置的 UUID,默认是随机 UUID(例如 <code>641a4800-1b19-427c-ae87-4a8ee90b7790</code>)。</li>
</ul>
<hr />
<h2>1.10 总结</h2>
<p>EVE-NG API 提供了丰富的功能,允许用户通过编程方式管理实验室、节点、网络、用户等。通过使用 API,可以实现自动化操作、集成到其他系统或开发自定义 Web-UI 主题。</p>
<p><strong>注意事项</strong>:</p>
<ol>
<li>EVE-NG Pro 使用 SSL 协议,所有请求需要使用 <code>https</code>和 <code>-k</code>参数。</li>
<li>由于 EVE-NG 代码的不断更新,某些 API 文档可能已过时。建议使用浏览器的开发者工具监控 API 调用,以获取最新的参数和功能。</li>
<li>每个用户只能从一个位置登录,重复登录会禁用之前的会话。</li>
</ol>
<p>通过合理利用 EVE-NG API,可以极大地提高实验室管理的效率和灵活性。</p>
<p>有了Markdown以后友好好多了。</p>
<p>谢谢楼主分享!!!</p>
页:
[1]