设置定时关机
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/instance/shutdown_timer \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"enable": true,
"shutdown_time": 123,
"instance_uuid": "<string>"
}
'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/shutdown_timer"
payload = {
"enable": True,
"shutdown_time": 123,
"instance_uuid": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({enable: true, shutdown_time: 123, instance_uuid: '<string>'})
};
fetch('https://www.chenyu.cn/api/open/v2/instance/shutdown_timer', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.chenyu.cn/api/open/v2/instance/shutdown_timer",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'enable' => true,
'shutdown_time' => 123,
'instance_uuid' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.chenyu.cn/api/open/v2/instance/shutdown_timer"
payload := strings.NewReader("{\n \"enable\": true,\n \"shutdown_time\": 123,\n \"instance_uuid\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.chenyu.cn/api/open/v2/instance/shutdown_timer")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"enable\": true,\n \"shutdown_time\": 123,\n \"instance_uuid\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/instance/shutdown_timer")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"enable\": true,\n \"shutdown_time\": 123,\n \"instance_uuid\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>"
}实例管理
设置定时关机
为实例设置定时关机
POST
/
api
/
open
/
v2
/
instance
/
shutdown_timer
设置定时关机
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/instance/shutdown_timer \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"enable": true,
"shutdown_time": 123,
"instance_uuid": "<string>"
}
'import requests
url = "https://www.chenyu.cn/api/open/v2/instance/shutdown_timer"
payload = {
"enable": True,
"shutdown_time": 123,
"instance_uuid": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({enable: true, shutdown_time: 123, instance_uuid: '<string>'})
};
fetch('https://www.chenyu.cn/api/open/v2/instance/shutdown_timer', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.chenyu.cn/api/open/v2/instance/shutdown_timer",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'enable' => true,
'shutdown_time' => 123,
'instance_uuid' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.chenyu.cn/api/open/v2/instance/shutdown_timer"
payload := strings.NewReader("{\n \"enable\": true,\n \"shutdown_time\": 123,\n \"instance_uuid\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.chenyu.cn/api/open/v2/instance/shutdown_timer")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"enable\": true,\n \"shutdown_time\": 123,\n \"instance_uuid\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/instance/shutdown_timer")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"enable\": true,\n \"shutdown_time\": 123,\n \"instance_uuid\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>"
}设置定时关机
为指定实例设置定时关机功能,可以在指定时间后自动关闭实例。实例定时关机时间最小为5分钟后。
请求参数
boolean
required
true: 启用实例定时关机 false: 取消实例定时关机
integer
required
实例定时关机时间,秒级时间戳
string
required
实例uuid
响应参数
integer
响应码
string
响应信息
代码示例
import requests
url = "https://www.chenyu.cn/api/open/v2/instance/shutdown_timer"
headers = {
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
}
# 设置60分钟后自动关机
data = {
"instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
"shutdown_time": 60
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
if result['code'] == 0:
print("定时关机设置成功")
else:
print(f"设置失败: {result['msg']}")
const axios = require('axios');
const url = 'https://www.chenyu.cn/api/open/v2/instance/shutdown_timer';
const headers = {
'Authorization': 'Bearer your_api_key',
'Content-Type': 'application/json'
};
// 设置60分钟后自动关机
const data = {
instance_uuid: 'inst_12345678-1234-1234-1234-123456789012',
shutdown_time: 60
};
axios.post(url, data, { headers })
.then(response => {
const result = response.data;
if (result.code === 0) {
console.log('定时关机设置成功');
} else {
console.log(`设置失败: ${result.msg}`);
}
})
.catch(error => {
console.error('Error:', error.response.data);
});
curl -X POST "https://www.chenyu.cn/api/open/v2/instance/shutdown_timer" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
"shutdown_time": 60
}'
响应示例
{
"code": 0,
"msg": "设置成功"
}
{
"code": -1,
"msg": "实例不存在或状态异常"
}
注意事项
- 设置
shutdown_time为 0 可以取消已设置的定时关机 - 定时关机时间以分钟为单位
- 只有运行中的实例才能设置定时关机
⌘I