容器
创建容器实例
1.接口说明
接口路径:/ai/openapi/v2/instance-service/task
请求方式:POST
请求数据类型:
接口描述:创建容器实例
2.请求消息
请求参数:
Headers:
名称 | 类型 | 必填 | 描述 | 示例 |
---|---|---|---|---|
token | string | 是 | 接口凭证 | eyJhbGciOiJIUzI1... |
参数:
名称 | 类型 | 必填 | 描述 | 示例 |
---|---|---|---|---|
acceleratorType | string | 是 | 加速器类型 | 包括:mlu,dcu,gpu,cpu |
containerPortInfoList | array | 否 | 服务端口 | |
containerPort | int | 是 | 端口 | |
protocolType | string | 是 | 协议类型 | 包括: SSH | HTTP |
cpuNumber | int | 是 | CPU数量 | 3 |
description | string | 否 | 描述信息 | |
gpuNumber | int | 是 | GPU数量 | 1 |
imagePath | string | 是 | 镜像路径 | 10.0.35.26:5000/gpu/admin/base/jupyter:4.4-py3.7-cpu |
instanceServiceName | string | 是 | 名称 | Instances_2205113838 |
mountInfoList | array | 否 | 挂载信息 | |
sourcePath | string | 是 | 源路径 | /public/home/username/source_mount |
targetPath | string | 是 | 目标路径 | /mnt/test_mount |
type | string | 是 | 类型 | 包括: data | path |
ramSize | int | 是 | 内存,单位为MB | 15360 |
resourceGroup | string | 是 | 资源分组 | TeslaM40 |
startScriptActionScope | string | 是 | 启动脚本范围:all代表所有容器,header代表首个容器 | all |
startScriptContent | string | 当useStartScript为true时必填;多行命令时需在每行末尾加入\n换行转义符 | 启动脚本的内容 | all |
taskNumber | int | 是 | 实例任务数量 | 1 |
taskType | string | 是 | 任务类型 | 包括: ssh | jupyter | codeserver | rstudio |
timeoutLimit | string | 是 | 自动停止时间 | 01:00:00 |
useStartScript | boolean | 是 | 启用脚本,true代表启用,默认为false | false |
version | string | 是 | 镜像名称 | jupyter:4.4-py3.7-cpu |
3.请求示例
cURL请求示例
curl --location 'https://api01.xxx.com:65106/ai/openapi/v2/instance-service/task' \
--header 'token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb21wdXRlVXNlciI6InNsdXJtdGVzdCIsImFjY291bnRTdGF0dXMiOiJUcmlhbCIsImNyZWF0b3IiOiJhYyIsInJvbGUiOiIxIiwiZXhwaXJlVGltZSI6IjE2ODYxMjMzNDY1NjgiLCJjbHVzdGVySWQiOiIxMTExMiIsImludm9rZXIiOiI2MDQ4Y2U3YmExNWMyYWYyZThjZWMxMjk5MWVjMTNjZiIsInVzZXIiOiJzbHVybXRlc3QiLCJ1c2VySWQiOiIxMTY1NTA0ODU0MSJ9.iQUBzN32jiCeeFuJ9lFS_XjBpxenEEupQRiyA3Ef334' \
--header 'Content-Type: application/json' \
--data '{
"instanceServiceName": "Instances_2205113838",
"description": "",
"taskType": "ssh",
"acceleratorType": "gpu",
"version": "jupyter:4.4-py3.7-cpu",
"imagePath": "10.0.35.26:5000/gpu/admin/base/jupyter:4.4-py3.7-cpu",
"timeoutLimit": "unlimited",
"taskNumber": 1,
"resourceGroup": "TeslaM40",
"useStartScript": false,
"startScriptActionScope": "all",
"startScriptContent": "",
"cpuNumber": 3,
"ramSize": 15360,
"gpuNumber": 1,
"mountInfoList": [
{
"sourcePath": "/public1/home/lizb0530d/test_mount",
"targetPath": "/mnt/test_mount",
"type": "data"
}
],
"containerPortInfoList": [
{
"protocolType": "HTTP",
"containerPort": "18888"
}
]
}'
Java请求示例
import okhttp3.*;
public class CreateContainerDemo {
public static final String TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb21wdXRlVXNlciI6InNsdXJtdGVzdCIsImFjY291bnRTdGF0dXMiOiJUcmlhbCIsImNyZWF0b3IiOiJhYyIsInJvbGUiOiIxIiwiZXhwaXJlVGltZSI6IjE2ODY5MDg1MDkyMzEiLCJjbHVzdGVySWQiOiIxMTExMiIsImludm9rZXIiOiI2MDQ4Y2U3YmExNWMyYWYyZThjZWMxMjk5MWVjMTNjZiIsInVzZXIiOiJzbHVybXRlc3QiLCJ1c2VySWQiOiIxMTY1NTA0ODU0MSJ9.U7pZKgO_K6NuRwOWPxblDfgRpGeVxS-BYieOdLhGDK4";
public static final String URL = "https://api01.xxx.com:65106/ai/openapi/v2/instance-service/task";
public static void main(String[] args) throws Exception {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"instanceServiceName\": \"Instances_2205113838\",\n \"description\": \"\",\n \"taskType\": \"ssh\",\n \"acceleratorType\": \"gpu\",\n \"version\": \"jupyter:4.4-py3.7-cpu\",\n \"imagePath\": \"10.0.35.26:5000/gpu/admin/base/jupyter:4.4-py3.7-cpu\",\n \"timeoutLimit\": \"unlimited\",\n \"taskNumber\": 1,\n \"resourceGroup\": \"TeslaM40\",\n \"useStartScript\": false,\n \"startScriptActionScope\": \"all\",\n \"startScriptContent\": \"\",\n \"cpuNumber\": 3,\n \"ramSize\": 15360,\n \"gpuNumber\": 1,\n \"mountInfoList\": [\n {\n \"sourcePath\": \"/public1/home/lizb0530d/test_mount\",\n \"targetPath\": \"/mnt/test_mount\",\n \"type\": \"data\"\n }\n ],\n \"containerPortInfoList\": [\n {\n \"protocolType\": \"HTTP\",\n \"containerPort\": \"18888\"\n }\n ]\n}");
Request request = new Request.Builder()
.url(URL)
.method("POST", body)
.addHeader("token", TOKEN)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
Python请求示例
import requests
import json
url = "https://api01.xxx.com:65106/ai/openapi/v2/instance-service/task"
payload = json.dumps({
"instanceServiceName": "Instances_2205113838",
"description": "",
"taskType": "ssh",
"acceleratorType": "gpu",
"version": "jupyter:4.4-py3.7-cpu",
"imagePath": "10.0.35.26:5000/gpu/admin/base/jupyter:4.4-py3.7-cpu",
"timeoutLimit": "unlimited",
"taskNumber": 1,
"resourceGroup": "TeslaM40",
"useStartScript": False,
"startScriptActionScope": "all",
"startScriptContent": "",
"cpuNumber": 3,
"ramSize": 15360,
"gpuNumber": 1,
"mountInfoList": [
{
"sourcePath": "/public1/home/lizb0530d/test_mount",
"targetPath": "/mnt/test_mount",
"type": "data"
}
],
"containerPortInfoList": [
{
"protocolType": "HTTP",
"containerPort": "18888"
}
]
})
headers = {
'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb21wdXRlVXNlciI6InNsdXJtdGVzdCIsImFjY291bnRTdGF0dXMiOiJUcmlhbCIsImNyZWF0b3IiOiJhYyIsInJvbGUiOiIxIiwiZXhwaXJlVGltZSI6IjE2ODYxMjMzNDY1NjgiLCJjbHVzdGVySWQiOiIxMTExMiIsImludm9rZXIiOiI2MDQ4Y2U3YmExNWMyYWYyZThjZWMxMjk5MWVjMTNjZiIsInVzZXIiOiJzbHVybXRlc3QiLCJ1c2VySWQiOiIxMTY1NTA0ODU0MSJ9.iQUBzN32jiCeeFuJ9lFS_XjBpxenEEupQRiyA3Ef334',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
4.响应消息
返回参数:
名称 | 类型 | 描述 | 示例 |
---|---|---|---|
msg | string | 信息 | 操作成功 |
code | string | 状态码 | 0 |
data | string | 任务ID | 530491fa7c8e47348f01de73e627a6a7 |
返回示例:
{
"code":"0",
"msg":"success",
"data":"530491fa7c8e47348f01de73e627a6a7"
}
5.错误码
错误码 | 说明 |
---|---|
0 | 成功 |
10001 | 内部异常(其他异常) |
10003 | 参数不全 |
10004 | 参数无效 |
10007 | 用户已被冻结 |
10008 | 权限不足 |
10009 | 没有权限访问接口 |
10010 | 文件校验失败 |
10011 | 文件过大 |
10012 | 连接中断 |
716865 | 创建任务错误 |