容器

创建容器实例

1.接口说明

接口路径:/ai/openapi/v2/instance-service/task

请求方式:POST

请求数据类型:

接口描述:创建容器实例

2.请求消息

请求参数:

Headers:

名称 类型 必填 描述 示例
tokenstring接口凭证eyJhbGciOiJIUzI1...

参数:

名称 类型 必填 描述 示例
acceleratorTypestring加速器类型包括:mlu,dcu,gpu,cpu
containerPortInfoListarray服务端口
containerPortint端口
protocolTypestring协议类型包括: SSH | HTTP
cpuNumberintCPU数量3
descriptionstring描述信息
gpuNumberintGPU数量1
imagePathstring镜像路径10.0.35.26:5000/gpu/admin/base/jupyter:4.4-py3.7-cpu
instanceServiceNamestring名称Instances_2205113838
mountInfoListarray挂载信息
sourcePathstring源路径/public/home/username/source_mount
targetPathstring目标路径/mnt/test_mount
typestring类型包括: data | path
ramSizeint内存,单位为MB15360
resourceGroupstring资源分组TeslaM40
startScriptActionScopestring启动脚本范围:all代表所有容器,header代表首个容器 all
startScriptContentstring当useStartScript为true时必填;多行命令时需在每行末尾加入\n换行转义符启动脚本的内容all
taskNumberint实例任务数量1
taskTypestring任务类型包括: ssh | jupyter | codeserver | rstudio
timeoutLimitstring自动停止时间01:00:00
useStartScriptboolean启用脚本,true代表启用,默认为falsefalse
versionstring镜像名称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.响应消息

返回参数:

名称 类型 描述 示例
msgstring信息操作成功
codestring状态码0
datastring任务ID530491fa7c8e47348f01de73e627a6a7

返回示例:

{
    "code":"0",
    "msg":"success",
    "data":"530491fa7c8e47348f01de73e627a6a7"
}

5.错误码

错误码 说明
0 成功
10001 内部异常(其他异常)
10003 参数不全
10004 参数无效
10007 用户已被冻结
10008 权限不足
10009 没有权限访问接口
10010 文件校验失败
10011 文件过大
10012 连接中断
716865 创建任务错误

results matching ""

    No results matching ""