查询实例列表
获取当前用户的所有实例列表,支持分页查询。在线测试: 您可以在右侧的API Playground中输入您的API Key,然后点击”Try it”按钮直接测试这个接口。API Key格式为
Bearer your_api_key
。请求参数
此接口不需要任何请求参数。响应参数
响应码
响应信息
返回数据
Show data
Show data
实例列表
Show instance_list
Show instance_list
实例uuid
实例状态
2
: 运行中21
: 关机中22
: 已关机24
: 开机中27
: 重启中
实例名称
实例创建时间,秒级时间戳
实例启动时间,秒级时间戳
开放服务url列表
实例镜像保存状态
1
: 上传中2
: 上传成功3
: 上传失败
计费类型
实例使用的镜像uuid
实例使用的镜像名称
实例使用的镜像tag
实例使用的gpu uuid
实例使用的gpu名称
实例使用的gpu数量
总记录数量
代码示例
Copy
import requests
from datetime import datetime
url = "https://www.chenyu.cn/api/open/v2/instance/list"
headers = {
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
}
params = {
"page": 1,
"page_size": 10
}
response = requests.get(url, headers=headers, params=params)
result = response.json()
if result['code'] == 0:
print(f"总共有 {result['data']['total']} 个实例")
for instance in result['data']['instance_list']:
create_time = datetime.fromtimestamp(instance['create_time'])
print(f"实例名称: {instance['title']}")
print(f"实例UUID: {instance['instance_uuid']}")
print(f"状态: {instance['status']}")
print(f"GPU: {instance['gpu_name']} x{instance['gpu_nums']}")
print(f"镜像: {instance['image_name']}")
print(f"创建时间: {create_time.strftime('%Y-%m-%d %H:%M:%S')}")
if instance['server_url']:
print("服务地址:")
for url in instance['server_url']:
print(f" - {url}")
if instance.get('server_map'):
print("服务详情:")
for service in instance['server_map']:
print(f" - {service['title']}: {service['url']}")
if service.get('ssh_info'):
ssh = service['ssh_info']
print(f" SSH连接: {ssh['username']}@{ssh['host']}:{ssh['port']}")
print("---")
else:
print(f"查询失败: {result['msg']}")
响应示例
Copy
{
"code": 0,
"msg": "success",
"data": {
"instance_list": [
{
"instance_uuid": "inst_12345678-1234-1234-1234-123456789012",
"status": 2,
"title": "我的PyTorch实例",
"create_time": 1703145600,
"start_time": 1703145660,
"server_url": [
"https://jupyter-inst123.chenyu.cn",
"https://ssh-inst123.chenyu.cn"
],
"server_map": [
{
"title": "Jupyter Lab",
"url": "https://jupyter-inst123.chenyu.cn",
"port_type": "http",
"protocol": "tcp"
},
{
"title": "SSH Terminal",
"url": "ssh://ssh-inst123.chenyu.cn:22",
"port_type": "ssh",
"protocol": "tcp",
"ssh_info": {
"host": "inst12345678123412341234123456789012.gzxx.chenyu.cn",
"port": 22001,
"username": "root",
"password": "generated_password_123"
}
}
],
"save_image_status": 2,
"charging_type": 1,
"shutdown_regular": {
"shutdown_time": 1703232000,
"enable": true
},
"image_uuid": "img_87654321-4321-4321-4321-210987654321",
"image_name": "PyTorch 2.0 环境",
"image_tag": "v2.0",
"gpu_uuid": "gpu_87654321-4321-4321-4321-210987654321",
"gpu_name": "NVIDIA RTX 4090",
"gpu_nums": 1
}
],
"total": 1
}
}