跳到主要内容

创建任务模板

创建任务模板,包括Codepath、Resource、image、ENV等参数。每个用户最多可以创建20个模板。
POST
https://api.alayanew.com/api/serverless-train/v1/template
Authorizations
AuthorizationsStringHeaderRequired

用户可通过已获取Serverless API Key做验证,例如:plain Credential=[YOUR_AK],Signature=[YOUR_SK]。

Body
application/json
nameStringRequired

模板名称,例如:my-debug。

vksIdStringRequired

弹性容器集群ID,例如:vc3jedd7crnd。

namespaceStringRequired

弹性容器集群的命名空间,例如:default。

labelsObject

任务运行的标签。

replicasIntRequired

任务副本数(debug,run,shell为1,task,group为1-100),默认值 1,例如:1。

workDirStringRequired

代码的工作目录,例如:/root/。

cmdArray[String]Required

执行命令。

argsArray[String]

执行命令的参数。

envObject

资源。

resourceObjectRequired

imageStringRequired

镜像名称。

imagePullSecretObject

pvcMountsArray

extensionsObject

扩展字段。

Response
状态码:application/json
codeInt

code是一种常见的返回值形式,表示查询操作的执行结果。

0是成功标识,表示操作成功完成。
dataObjectRequired

msgString

code返回值为-1时,返回异常信息。

curl -X POST 'https://api.alayanew.com/api/serverless-train/v1/template' 
     -H 'Authorization: plain Credential=YOUR_AK,Signature=YOUR_SK' 
     -H 'Content-Type: application/json' 
     -d '{
            "name": "my-debug",
            "vksId": "vc3jedd7crnd",
            "namespace": "default",
            "replicas": 1,
            "workDir": "/root/",
            "cmd": ["bash", "-c", "python3 main.py"],
            "resource": {
                "cpu": 2,
                "mem": 8,
                "gpu": {
                "count": 1,
                "gpuType": "nvidia.com/gpu-tesla-p4"
                },
                "epheneralStorage": 32
            },
            "image": "registry.hd-01.alayanew.com/aladdin/python:3.13",
            "pvcMounts": [
                {
                "pvcName": "pvc-capacity-userdata",
                "subPath": "a",
                "containerPath": "/a",
                "readOnly": false
                }
            ],
            "imagePullSecret": {
                "registry": "https://registry.hd-01.alayanew.com",
                "username": "admin",
                "password": "[password]"
            },
            "extensions": {
                "tag": "3",
                "tenantId": "dc8e48eb-4c05-4466-8ee2-2c3f969352bf"
              }
            }'
{
    "code": 0,
    "data": {
        "id": "5df0ef3c-252a-44c8-aba3-a87e23615c76"
    }
}