Эх сурвалжийг харах

更新文档,加入系统模板接口描述

James Iter 9 жил өмнө
parent
commit
7250ed2732

+ 3 - 0
README.md

@@ -24,6 +24,7 @@
     - [[状态列表](docs/enum.md)](#状态列表)
     - [[配置](docs/config.md)](#配置)
     - [[实例初始化操作簇](docs/os_init.md)](#实例初始化操作簇)
+    - [[系统模板](docs/os_template.md)](#系统模板)
     - [[Guest](docs/guest.md)](#guest)
     - [[磁盘](docs/disk.md)](#磁盘)
 - [流程图](#流程图)
@@ -212,6 +213,8 @@ gunicorn -c gunicorn_config.py main:app
 
 ### [实例初始化操作簇](docs/os_init.md)
 
+### [系统模板](docs/os_template.md)
+
 ### [Guest](docs/guest.md)
 
 ### [磁盘](docs/disk.md)

+ 180 - 0
docs/os_template.md

@@ -0,0 +1,180 @@
+# OS Template
+
+[TOC]: # "目录"
+
+# 目录
+- [添加系统模板](#添加系统模板)
+- [获取系统模板列表](#获取系统模板列表)
+- [更改系统模板信息](#更改系统模板信息)
+- [删除系统模板](#删除系统模板)
+
+
+## 添加系统模板
+
+>  添加系统模板记录
+
+```http
+POST https://$domain
+  /api/os_template
+Body:
+{
+    "label": "CentOS-7.2",
+    "name": "centos72_multi-user_2016-09-15_128G.qcow2",
+    "active": True,
+    "os_init_id": 3
+}
+```
+
+|  参数名称   | 必须 |  类型   | 说明              |
+|:----------:|:---:|:-------:|:------------------|
+|   label    |  Y  | String  | 标识              |
+|    name    |  Y  | String  | 路径中的模板名称    |
+|   active   |  Y  | Boolean | 是否可用           |
+| os_init_id |  N  |  Long   | 实例初始化操作簇 ID |
+
+响应示例
+
+```json
+{
+    "state": {
+        "en-us": "OK",
+        "zh-cn": "成功",
+        "code": "200"
+    },
+    "data": {
+        "active": 1,
+        "os_init_id": 3,
+        "id": 1,
+        "name": "centos72_multi-user_2016-09-15_128G.qcow2",
+        "label": "CentOS-7.2"
+    }
+}
+```
+
+## 获取系统模板列表
+
+> 获取系统模板列表
+
+```http
+GET https://$domain
+  /api/os_templates?offset={number}&limit={number}
+  or
+  /api/os_templates?page={number}&page_size={number}
+```
+
+|  参数名称  | 必须 |  类型  | 说明                                        |
+|:---------:|:---:|:------:|:--------------------------------------------|
+|  offset   |  N  | Number | 偏移量, 默认值0                              |
+|   limit   |  N  | Number | 返回条目数量, 默认值50                        |
+|   page    |  N  | Number | 页号, 与offset同时存在时, 以offset为准, 默认值1 |
+| page_size |  N  | Number | 页大小, 默认值50                             |
+| order_by  |  N  | String | 所依据的字段                                 |
+|   order   |  N  |  Enum  | 排序策略,`asc`\|`desc`                      |
+
+响应示例
+
+```json
+{
+    "state": {
+        "en-us": "OK",
+        "zh-cn": "成功",
+        "code": "200"
+    },
+    "data": [{
+        "active": 1,
+        "label": "CentOS-7.2",
+        "id": 1,
+        "name": "centos72_multi-user_2016-09-15_128G.qcow2",
+        "os_init_id": 3
+    },{
+        "more" : "more"
+    }],
+    "paging": {
+        "prev": "http://127.0.0.1:8008/api/os_templates?page=1&page_size=50&filter=&order=asc&order_by=id",
+        "last": "http://127.0.0.1:8008/api/os_templates?page=1&page_size=50&filter=&order=asc&order_by=id",
+        "page_size": 50,
+        "next": "http://127.0.0.1:8008/api/os_templates?page=1&page_size=50&filter=&order=asc&order_by=id",
+        "limit": 50,
+        "offset": 0,
+        "total": 1,
+        "page": 1,
+        "first": "http://127.0.0.1:8008/api/os_templates?page=1&page_size=50&filter=&order=asc&order_by=id"
+    }
+}
+```
+
+| 参数名称    | 必须 |  类型   | 说明              |
+|:-----------|:---:|:-------:|:------------------|
+| id         |  Y  |  Long   | 模板 ID           |
+| label      |  Y  | String  | 标识              |
+| name       |  Y  | String  | 路径中的模板名称    |
+| active     |  Y  | Boolean | 是否可用           |
+| os_init_id |  N  |  Long   | 实例初始化操作簇 ID |
+
+
+## 更改系统模板信息
+
+> 更改指定 id 的系统模板信息
+
+```http
+PATCH https://$domain
+  /api/os_template/{id}
+Body:
+{
+    "label": 'CentOS-72'
+}
+```
+
+可用的更新系统模板信息字段描述参见 [获取系统模板列表](#获取系统模板列表)
+
+响应示例
+
+```json
+{
+    "state": {
+        "en-us": "OK",
+        "zh-cn": "成功",
+        "code": "200"
+    },
+    "data": {
+        "active": 1,
+        "label": "CentOS-72",
+        "id": 1,
+        "name": "centos72_multi-user_2016-09-15_128G.qcow2",
+        "os_init_id": 3
+    }
+}
+```
+
+系统模板信息字段描述参见 [获取系统模板列表](#获取系统模板列表)
+
+
+## 删除系统模板
+
+> 删除指定 id 的系统模板
+
+```http
+DELETE https://$domain
+  /api/os_template/{id}
+```
+
+| 参数名称 | 必须 |  类型  | 说明       |
+|:--------|:---:|:------:|:-----------|
+| id      |  Y  | Number | 系统模板 ID |
+
+响应示例
+
+```json
+{
+    "state": {
+        "en-us": "OK",
+        "zh-cn": "成功",
+        "code": "200"
+    }
+}
+```
+
+
+[返回上一级](../README.md)
+=====================
+

+ 13 - 0
docs/todo.md

@@ -1 +1,14 @@
+# TODO
 
+- 添加对 Guest 的IP管理功能
+> 1. 给宿主机替换当前 IP 池中可用的 IP。替换后,新 IP 置为已用状态,被替换的 IP,
+> 要与系统配置中的可用 IP 范围做计算。计算其是不是可以被自动分配的合法 IP。如果是,
+> 则回收。如果不是,则直接丢弃;
+> 2. 给宿主机替换手动指定的任意 IP。此时需要判断手动分配的 IP 是否与已用的 IP 冲突;
+
+- os_init_write 的更新方法里,是否需要支持 os_init_id 参数
+- 增加模板镜像上传功能
+- 抽象出视图层的父类,尤其是 get、get_list、delete 这些方法基本相同
+- guest_disk 表中加入 path 字段,具体磁盘位置由 path 指明
+- guest 的系统磁盘,也需记录到 guest_disk 表中
+- os_template 表中 name 改为 path 字段。又 path 指明完整路径

+ 2 - 1
tests/test_os_template.py

@@ -29,7 +29,8 @@ class TestOSTemplate(unittest.TestCase):
         payload = {
             "label": "CentOS-7.2",
             "name": "centos72_multi-user_2016-09-15_128G.qcow2",
-            "active": True
+            "active": True,
+            "os_init_id": 3
         }
 
         url = TestOSTemplate.base_url + '/os_template'