容器
查询容器实例列表
1.接口说明
接口路径:/ai/openapi/v2/instance-service/task
请求方式:GET
请求数据类型:
接口描述:查询容器实例列表
2.请求消息
请求参数:
Headers:
名称 | 类型 | 必填 | 描述 | 示例 |
---|---|---|---|---|
token | string | 是 | 接口凭证 | eyJhbGciOiJIUzI1... |
参数:
名称 | 类型 | 必填 | 描述 | 示例 |
---|---|---|---|---|
instanceServiceName | array | 否 | 容器实例名称 | |
limit | int | 是 | 限制数量 | 20 |
sort | string | 是 | 排序方式 | desc |
start | int | 否 | 起始值,默认为0 | 0 |
status | string | 否 | 状态 | Running | Deploying | Waiting | Terminated | Failed | Completed |
taskType | string | 否 | 任务类型 | ssh | jupyter | codeserver | rstudio |
3.请求示例
cURL请求示例
curl --location --request GET 'https://api01.xxx.com:65106/ai/openapi/v2/instance-service/task' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb21wdXRlVXNlciI6InNsdXJtdGVzdCIsImFjY291bnRTdGF0dXMiOiJUcmlhbCIsImNyZWF0b3IiOiJhYyIsInJvbGUiOiIxIiwiZXhwaXJlVGltZSI6IjE2ODYxMjMzNDY1NjgiLCJjbHVzdGVySWQiOiIxMTExMiIsImludm9rZXIiOiI2MDQ4Y2U3YmExNWMyYWYyZThjZWMxMjk5MWVjMTNjZiIsInVzZXIiOiJzbHVybXRlc3QiLCJ1c2VySWQiOiIxMTY1NTA0ODU0MSJ9.iQUBzN32jiCeeFuJ9lFS_XjBpxenEEupQRiyA3Ef334' \
--header 'Content-Type: application/json' \
--data '{
"status": null,
"instanceServiceName": null,
"taskType": "ssh",
"start": 0,
"limit": 20,
"sort": "desc"
}'
Java请求示例
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import java.net.*;
public class QueryInstanceServiceDemo {
public static class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {
public final static String METHOD_NAME = "GET";
@Override
public String getMethod() {
return METHOD_NAME;
}
}
public static void main(String[] args) throws Exception {
String token = "sdfb3VudFN0YXR1cyI6Ik93ZSIsImNyZWF0b3IiOiJhYyIsInJvbGUiOiIxIiwiZXhwaXJlVGltZSI6IjE3MDAwMTQ3NzM3NzUiLCJjbHVzdGVySWQiOiIxMTI1MCIsImludm9rZXIiOiJiN2I5NjViNjZkM2IzNWJjMTQ0ZDI5YWY1MWUxNjFhMSIsInVzZXIiOiJqc3lhZG1pbiIsInVzZXJJZCI6IjIxOTI1OTExMzgwIn0.M6SaGPF1oQBrcla-xqnrm3psaA1Lij5nPMHO_KH0cLc";
String url = "https://ai01.xxx.com:65011/ai/openapi/v2/instance-service/task";
String params = "{\n \"status\": null,\n \"instanceServiceName\": null,\n \"taskType\": \"ssh\",\n \"start\": 0,\n \"limit\": 20,\n \"sort\": \"desc\"\n}";
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpGetWithEntity e = new HttpGetWithEntity();
e.setURI(new URI(url));
e.setHeader("token", token);
e.setHeader("Content-Type", "application/json");
HttpEntity yourEntity = new StringEntity(params, ContentType.APPLICATION_JSON);
e.setEntity(yourEntity);
CloseableHttpResponse response = httpClient.execute(e);
HttpEntity entity = response.getEntity();
String body = "";
if (entity != null) {
body = EntityUtils.toString(entity, "UTF-8");
}
System.out.println(body);
response.close();
}
}
Python请求示例
import requests
import json
url = "https://api01.xxx.com:65106/ai/openapi/v2/instance-service/task"
payload = json.dumps({
"status": None,
"instanceServiceName": None,
"taskType": "ssh",
"start": 0,
"limit": 20,
"sort": "desc"
})
headers = {
'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb21wdXRlVXNlciI6InNsdXJtdGVzdCIsImFjY291bnRTdGF0dXMiOiJUcmlhbCIsImNyZWF0b3IiOiJhYyIsInJvbGUiOiIxIiwiZXhwaXJlVGltZSI6IjE2ODYxMjMzNDY1NjgiLCJjbHVzdGVySWQiOiIxMTExMiIsImludm9rZXIiOiI2MDQ4Y2U3YmExNWMyYWYyZThjZWMxMjk5MWVjMTNjZiIsInVzZXIiOiJzbHVybXRlc3QiLCJ1c2VySWQiOiIxMTY1NTA0ODU0MSJ9.iQUBzN32jiCeeFuJ9lFS_XjBpxenEEupQRiyA3Ef334',
'Content-Type': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
4.响应消息
返回参数:
名称 | 类型 | 描述 | 示例 |
---|---|---|---|
msg | string | 信息 | 操作成功 |
code | string | 状态码 | 0 |
data | array | 任务列表 | |
acceleratorType | string | 加速器类型 | |
cpuNumber | int | CPU数量 | |
createTime | string | 创建时间 | |
currentIndex | int | 容器当前索引 | |
description | string | 描述信息 | |
duration | string | 持续时间 | |
endTime | string | 结束时间 | |
gpuNumber | int | GPU数量 | |
headerNotebookId | string | 容器实例关联的首个notebook任务ID | |
headerNotebookIp | string | 容器实例关联的首个notebook任务IP | |
id | string | 容器实例ID | |
imagePath | string | 镜像路径 | |
instanceServiceName | string | 名称 | |
ramSize | int | 内存 | |
remainingTime | string | 剩余时间 | |
resourceGroup | string | 资源分组 | |
resourceSpec | string | 资源配置 | |
startScriptActionScope | string | 启用脚本范围 | |
startScriptPath | string | 启动脚本路径 | |
startScriptContent | string | 启动脚本的内容 | |
startTime | string | 开始时间 | |
status | string | 状态 | |
taskNumber | string | 实例任务数量 | |
taskType | string | 任务类型 | |
tensorboardId | string | TB-ID | |
tensorboardPath | string | TB路径 | |
timeoutLimit | string | 超时时间 | |
useStartScript | boolean | 启用脚本 | |
userName | string | 用户名 | |
version | string | 镜像名称 | |
mountInfoList | array | ||
containerPortInfoList | array |
返回示例:
{"msg":"success",
"total":4,"code":"0",
"data":[{"id":"530491fa7c8e47348f01de73e627a6a7",
"headerNotebookId":"b54439dc621a434a88e8ab37d1897241",
"instanceServiceName":"Instances_2204208761",
"currentIndex":1,
"gpuNumber":2,
"cpuNumber":6,
"ramSize":30720,
"acceleratorType":"gpu",
"resourceGroup":"TeslaM40",
"resourceSpec":"6 核心; 2 加速器; 30.0G 内存",
"taskNumber":1,
"timeoutLimit":"unlimited",
"userName":"demo",
"version":"pytorch:1.2-py3.6-CUDA10.0",
"imagePath":"10.0.35.26:5000/gpu/admin/base/pytorch:1.2-py3.6-CUDA10.0",
"status":"Waiting",
"taskType":"ssh",
"description":"",
"createTime":"2022-04-20 16:16:14",
"startTime":null,
"endTime":null,
"duration":"--",
"remainingTime":"--",
"tensorboardId":null,
"tensorboardPath":null,
"mountInfoList":null,
"containerPortInfoList":null,
"useStartScript":false,
"startScriptContent":"",
"startScriptPath":null,
"startScriptActionScope":"all",
"headerNotebookIp":null}
}
5.错误码
错误码 | 说明 |
---|---|
0 | 成功 |
10001 | 内部异常(其他异常) |
10003 | 参数不全 |
10004 | 参数无效 |
10007 | 用户已被冻结 |
10008 | 权限不足 |
10009 | 没有权限访问接口 |
10010 | 文件校验失败 |
10011 | 文件过大 |
10012 | 连接中断 |