EVE-NG API 参考文档
EVE-NG API 使用指南
Section titled “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 状态码
认证(Authentication)
Section titled “认证(Authentication)”以下 API 请求用于登录和登出流程。所有其他 API 请求都需要已认证的用户。
登录(Login)
Section titled “登录(Login)”社区版(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"
}获取用户信息(User Info)
Section titled “获取用户信息(User Info)”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"
}登出(Logout)
Section titled “登出(Logout)”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"
}系统状态(System Status)
Section titled “系统状态(System Status)”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 | 缓存使用量 |
cpu | CPU 使用率 |
disk | 磁盘使用率 |
dynamips | 运行中的 Dynamips 节点数 |
iol | 运行中的 IOL 节点数 |
mem | 内存使用率 |
qemu | 运行中的 QEMU 节点数 |
qemu_version | QEMU 版本 |
swap | Swap 使用率 |
version | EVE-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"
}获取单个模板详情
Section titled “获取单个模板详情”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"
}列出用户角色(List User Roles)
Section titled “列出用户角色(List User Roles)”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"
}文件夹和实验使用不同的数组列出。
创建新文件夹(Add a New Folder)
Section titled “创建新文件夹(Add a New Folder)”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"
}删除文件夹(Delete a Folder)
Section titled “删除文件夹(Delete a Folder)”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"
}用户管理(Managing Users)
Section titled “用户管理(Managing Users)”以下 API 请求用于管理 EVE-NG 用户和权限。
获取用户列表(Get All Users)
Section titled “获取用户列表(Get All Users)”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"
}获取单个用户(Get a Single User)
Section titled “获取单个用户(Get a Single User)”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"
}添加新用户(Add a New User)
Section titled “添加新用户(Add a New User)”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 | 可选 | 参见”列出用户角色” |
编辑用户(Edit a User)
Section titled “编辑用户(Edit a User)”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 | 参见”列出用户角色” |
删除用户(Delete a User)
Section titled “删除用户(Delete a User)”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"
}实验管理(Managing Labs)
Section titled “实验管理(Managing Labs)”以下 API 请求用于管理实验以及实验内的对象(如节点、网络等)。
获取实验(Get a Lab)
Section titled “获取实验(Get 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已认证用户可以获取实验信息:
{
"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"
}节点操作(Node Operations)
Section titled “节点操作(Node Operations)”启动节点(Start Nodes)
Section titled “启动节点(Start Nodes)”启动所有节点:
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"
}停止节点(Stop Nodes)
Section titled “停止节点(Stop Nodes)”停止所有节点:
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"
}清除节点(Wipe Nodes)
Section titled “清除节点(Wipe Nodes)”清除所有节点:
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"
}导出节点(Export Nodes)
Section titled “导出节点(Export Nodes)”导出所有节点:
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 表示未连接 |
拓扑与图片(Topology & Pictures)
Section titled “拓扑与图片(Topology & Pictures)”获取实验拓扑(Get Lab Topology)
Section titled “获取实验拓扑(Get Lab Topology)”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)”创建新实验(Create a New Lab)
Section titled “创建新实验(Create a New Lab)”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"
}编辑实验(Edit a Lab)
Section titled “编辑实验(Edit a Lab)”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 | 必填 | 节点类型,可选:iol、dynamips、qemu |
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 |
nvram | NVRAM 大小(KB),默认 1024 |
serial | 串行端口组数量(每组配置 4 个接口),默认 2 |
Dynamips 节点专用参数:
| 参数 | 说明 |
|---|---|
idlepc | Dynamips 优化值(如 0x80369ac4),默认 0x0(无优化) |
nvram | NVRAM 大小(KB),默认 1024 |
slot[0-9]+ | 特定插槽中配置的模块(如 slot1=NM-1FE-TX) |
QEMU 节点专用参数:
| 参数 | 说明 |
|---|---|
console | 控制台类型,telnet 或 vnc,默认 telnet |
cpu | CPU 数量,默认 1 |
ethernet | 以太网接口数量,默认 4 |
uuid | UUID,默认为随机 UUID |
删除实验(Delete a Lab)
Section titled “删除实验(Delete a Lab)”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"
}API 接口速查表
Section titled “API 接口速查表”| 类别 | 方法 | 接口路径 | 说明 |
|---|---|---|---|
| 认证 | 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} | 获取调整大小后的图片数据 |