curl --request GET \
--url https://www.chenyu.cn/api/open/v2/instance/list \
--header 'Authorization: Bearer <token>'{
"code": 123,
"msg": "<string>",
"data": {
"instance_list": [
{
"instance_uuid": "<string>",
"status": 123,
"title": "<string>",
"create_time": 123,
"start_time": 123,
"server_url": [
{}
],
"server_map": [
{
"title": "<string>",
"url": "<string>",
"port_type": "<string>",
"protocol": "<string>",
"ssh_info": {
"host": "<string>",
"port": 123,
"username": "<string>",
"password": "<string>"
}
}
],
"save_image_status": 123,
"charging_type": 123,
"shutdown_regular": {
"shutdown_time": 123,
"enable": true
},
"image_uuid": "<string>",
"image_name": "<string>",
"image_tag": "<string>",
"gpu_uuid": "<string>",
"gpu_name": "<string>",
"gpu_nums": 123
}
],
"total": 123
}
}查询用户的实例列表
curl --request GET \
--url https://www.chenyu.cn/api/open/v2/instance/list \
--header 'Authorization: Bearer <token>'{
"code": 123,
"msg": "<string>",
"data": {
"instance_list": [
{
"instance_uuid": "<string>",
"status": 123,
"title": "<string>",
"create_time": 123,
"start_time": 123,
"server_url": [
{}
],
"server_map": [
{
"title": "<string>",
"url": "<string>",
"port_type": "<string>",
"protocol": "<string>",
"ssh_info": {
"host": "<string>",
"port": 123,
"username": "<string>",
"password": "<string>"
}
}
],
"save_image_status": 123,
"charging_type": 123,
"shutdown_regular": {
"shutdown_time": 123,
"enable": true
},
"image_uuid": "<string>",
"image_name": "<string>",
"image_tag": "<string>",
"gpu_uuid": "<string>",
"gpu_name": "<string>",
"gpu_nums": 123
}
],
"total": 123
}
}Bearer your_api_key。Show data
Show instance_list
2: 运行中21: 关机中22: 已关机24: 开机中27: 重启中1: 上传中2: 上传成功3: 上传失败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']}")
{
"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
}
}