超腾开源平台资源模块

2026-01-07 超腾开源 19 次阅读 0 次点赞
本文档介绍了资源模块中远程主机管理的API接口。该模块提供对远程服务器进行增删改查(CRUD)等管理功能,支持密码和密钥两种认证方式。文档详细说明了创建、更新、获取详情、获取列表、分页查询和删除远程主机的具体接口地址、请求参数、认证要求及响应格式,并提供了Python和JavaScript的调用示例。此外,文档还强调了密码安全、连接测试、权限控制、标签管理和激活状态等使用注意事项,帮助用户安全有效地管理远程主机资源。

资源模块 API

概述

资源模块提供远程服务器的管理、监控、连接等功能。

目录


远程主机管理

远程主机模块提供远程主机的 CRUD 功能。

远程主机 CRUD

接口地址 方法 说明
/api/resource/remote_host/detail GET 获取远程主机详情
/api/resource/remote_host/list GET 获取远程主机列表
/api/resource/remote_host/page GET 获取远程主机分页
/api/resource/remote_host/create POST 创建远程主机
/api/resource/remote_host/update POST 更新远程主机
/api/resource/remote_host/delete POST 删除远程主机

创建远程主机

接口地址: POST /api/resource/remote_host/create

需要认证: 是

请求体:

{
  "name": "生产服务器",
  "host": "192.168.1.100",
  "port": 22,
  "username": "root",
  "password": "your_password",
  "auth_type": "password",
  "description": "主要生产服务器",
  "tags": ["production", "linux"],
  "is_active": true
}

请求字段说明:

字段 类型 必填 说明
name string 主机名称
host string 主机地址(IP 或域名)
port int SSH 端口,默认为 22
username string 登录用户名
password string 登录密码
auth_type string 认证类型(password/key)
private_key string 私钥内容(auth_type 为 key 时必填)
description string 主机描述
tags string[] 标签列表
is_active boolean 是否激活

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "创建成功",
  "data": {
    "id": "1",
    "name": "生产服务器",
    "host": "192.168.1.100",
    "port": 22,
    "username": "root",
    "auth_type": "password",
    "description": "主要生产服务器",
    "tags": ["production", "linux"],
    "is_active": true,
    "last_connect_time": null,
    "create_time": "2026-01-01T00:00:00Z",
    "update_time": "2026-01-01T00:00:00Z"
  }
}

更新远程主机

接口地址: POST /api/resource/remote_host/update

需要认证: 是

请求体: 同创建远程主机,需包含 id 字段。

获取远程主机详情

接口地址: GET /api/resource/remote_host/detail

需要认证: 是

请求参数:

参数 类型 必填 说明
id string 远程主机 ID

获取远程主机列表

接口地址: GET /api/resource/remote_host/list

需要认证: 是

请求参数:

参数 类型 必填 说明
name string 主机名称
host string 主机地址
auth_type string 认证类型
tags string 标签(逗号分隔)
is_active boolean 是否激活
order string 排序字段

响应示例:

{
  "success": true,
  "code": 200,
  "msg": "操作成功",
  "data": [
    {
      "id": "1",
      "name": "生产服务器",
      "host": "192.168.1.100",
      "port": 22,
      "username": "root",
      "auth_type": "password",
      "is_active": true,
      "last_connect_time": "2026-01-01T00:00:00Z"
    }
  ]
}

获取远程主机分页

接口地址: GET /api/resource/remote_host/page

需要认证: 是

请求参数:

参数 类型 必填 说明 默认值
page int 页码 1
page_size int 每页条数 10
name string 主机名称 -
其他参数同列表接口 -

删除远程主机

接口地址: POST /api/resource/remote_host/delete

需要认证: 是

请求参数:

参数 类型 必填 说明
id string 远程主机 ID

枚举类型说明

认证类型 (AuthType)

说明
password 密码认证
key 密钥认证

使用示例

Python 示例

import requests

base_url = 'http://localhost:8000/api/resource/remote_host'
token = 'your_access_token'
headers = {'Authorization': f'Bearer {token}'}

# 创建远程主机
response = requests.post(
    f'{base_url}/create',
    headers=headers,
    json={
        'name': '生产服务器',
        'host': '192.168.1.100',
        'port': 22,
        'username': 'root',
        'password': 'your_password',
        'auth_type': 'password',
        'description': '主要生产服务器'
    }
)
print(response.json())

# 获取远程主机列表
response = requests.get(
    f'{base_url}/list',
    headers=headers,
    params={'is_active': True}
)
print(response.json())

# 更新远程主机
response = requests.post(
    f'{base_url}/update',
    headers=headers,
    json={
        'id': '1',
        'name': '生产服务器(已更新)',
        'is_active': False
    }
)
print(response.json())

JavaScript 示例

// 创建远程主机
async function createRemoteHost(token, hostData) {
  const response = await fetch(
    "http://localhost:8000/api/resource/remote_host/create",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(hostData),
    }
  );
  return await response.json();
}

// 获取远程主机列表
async function getRemoteHosts(token, filters = {}) {
  const params = new URLSearchParams(filters);
  const response = await fetch(
    `http://localhost:8000/api/resource/remote_host/list?${params}`,
    { headers: { Authorization: `Bearer ${token}` } }
  );
  return await response.json();
}

// 使用示例
createRemoteHost(token, {
  name: "测试服务器",
  host: "192.168.1.200",
  port: 22,
  username: "admin",
  password: "password",
  auth_type: "password",
}).then(console.log);

注意事项

  1. 密码安全: 密码和私钥会加密存储,不会在响应中返回。
  2. 连接测试: 添加或更新主机后,建议先测试连接是否正常。
  3. 权限控制: 只有具有相应权限的用户才能管理远程主机。
  4. 标签管理: 使用标签可以方便地对主机进行分类和筛选。
  5. 激活状态: 未激活的主机不会参与自动任务,但可以手动操作。

相关文档

本文由人工编写,AI优化,转载请注明原文地址: 超腾开源平台资源模块

评论 (0)

登录后发表评论

暂无评论,快来发表第一条评论吧!