Skip to content

容器

批量执行脚本

1.接口说明

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

请求方式:POST

请求数据类型:

接口描述:批量执行脚本

2.请求消息

请求参数:

Headers:

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

参数:

名称类型必填描述示例
startScriptActionScopestring批量执行脚本范围all(代表所有容器)、 header(代表首个容器)
startScriptContentstring批量执行脚本的内容;多行命令时需在每行末尾加入\n换行转义符echo \"hello world\"
idstring容器实例ID7d64e73803de4a6e9a15a8c79c7da015

3.请求示例

cURL请求示例

shell
curl --location 'https://scnet-demo.accloud.cn/ai/openapi/v2/instance-service/task/actions/execute-script' \
--header 'token: <Token>' \
--header 'Content-Type: application/json' \
--data '{
  "startScriptActionScope": "all",
  "startScriptContent": "echo \"hello world\"",
  "id": "7d64e73803de4a6e9a15a8c79c7da015"
}'

Java请求示例

java
import okhttp3.*;

public class BatchExecuteScriptDemo {

    public static final String TOKEN = "<Token>";
    
    public static final String URL = "https://scnet-demo.accloud.cn/ai/openapi/v2/instance-service/task/actions/execute-script";

    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    \"startScriptActionScope\": \"all\",\n    \"startScriptContent\": \"echo \\\"hello world\\\"\",\n    \"id\": \"7d64e73803de4a6e9a15a8c79c7da015\"\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请求示例

python
import requests
import json

url = "https://scnet-demo.accloud.cn/ai/openapi/v2/instance-service/task/actions/execute-script"
payload = json.dumps({
  "startScriptActionScope": "all",
  "startScriptContent": "echo \"hello world\"",
  "id": "7d64e73803de4a6e9a15a8c79c7da015"
})
headers = {
  "token": "<Token>",
  "Content-Type": "application/json"
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

4.响应消息

返回参数:

名称类型描述示例
msgstring信息操作成功
codestring状态码0
datastring返回值

返回示例:

json
{
  "code":"0",
  "msg":"success",
  "data":null
}

5.错误码

错误码说明
0成功
10001内部异常(其他异常)
10003参数不全
10004参数无效
10007用户已被冻结
10008权限不足
10009没有权限访问接口
10010文件校验失败
10011文件过大
10012连接中断
716020查询数据库错误
716864执行脚本错误
716870实例数量错误