diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 4cce1ce2244b142bf63e1334d8aa5e0c4e895be5..0000000000000000000000000000000000000000
--- a/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*.exe
-test/
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/ha-api.iml b/.idea/ha-api.iml
new file mode 100644
index 0000000000000000000000000000000000000000..5e764c4f0b9a64bb78a5babfdd583713b2df47bf
--- /dev/null
+++ b/.idea/ha-api.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000000000000000000000000000000000000..8150a2729f28c2c62a9eb98917d40d75a96d05ca
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.en.md b/README.en.md
index 85ee6287807022f3f5acf2cd4219ceef843f55a3..85c5d1089479034760c5a6ec7abaf91830fff1eb 100644
--- a/README.en.md
+++ b/README.en.md
@@ -1,13 +1,13 @@
# ha-api
## Description
-REST API backend for HA manage platform.
+ha-api is the back-end REST API for the HA management platform.
-Another project is [HA-web](https://gitee.com/openeuler/ha-web), which is the frontend of HA manage platform.
+Another project is [HA-web](https://gitee.com/openeuler/ha-web), which is the front-end UI of the HA management platform.
## Screenshots
-TODO: add some screenshots here
+To be added.
## Features
@@ -15,34 +15,34 @@ Easy to use.
## Documents
-The following documents are provide to help you understand the project:
+The following documents are provided to help you understand the project:
- [Build Document](./docs/build_en.md)
- [Architecture Document](./docs/architecture_en.md)
- [API Document](./docs/api_en.md)
-## Install
+## Installation
-HA software is need to run ha-api manage platform backend.
+The HA software is required to run the ha-api.
-On openEuler 20.03 LTS SP1, you can install HA software by yum:
+On openEuler 20.03 LTS SP1, you can install the HA software using Yum:
```
[root@ha1~]# yum install corosync pacemaker pcs fence-agents fence-virt corosync-qdevice sbd drbd drbd-utils
```
-For another OS, you may need to compile it and then install.
-You can get more details in [install documents](./docs/install_en.md) and [build documents](./docs/build_en.md)
+For other OSs, you may need to compile the HA software and then install it.
+For more details, see [install documents](./docs/install_en.md) and [build documents](./docs/build_en.md).
## Contribution
-HA-api is developed with golang. We use [Beego framework](https://beego.me/) to help us to develop high performance and reliable manage platform. All contributes are welcomed. If you have any problems in using or developing, please contact us by opening a issue.
+ha-api is developed with Golang. We use the [Beego framework](https://beego.me/) to develop a management platform featuring high performance and solid reliability. All contributions are welcomed. If you have any problems in using or developing, please contact us by opening an issue.
-## Gitee Feature
+## Gitee Features
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+1. Use Readme_XXX.md to mark README files with different languages, such as Readme_en.md and Readme_zh.md.
+2. Gitee blog: blog.gitee.com
+3. You can visit https://gitee.com/explore to learn about excellent open source projects on Gitee.
+4. GVP is short for Gitee Most Valuable Project.
+5. User manual provided by Gitee: https://gitee.com/help
+6. Gitee Cover People: https://gitee.com/gitee-stars/
diff --git a/controllers/alarms.go b/controllers/alarms.go
index d628be509a574e0b3692fb081891c1c8540390d6..3b62a4849da991adf531aa01ccf6917d943ce603 100644
--- a/controllers/alarms.go
+++ b/controllers/alarms.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:59
+ * Description: 告警控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/controllers/cluster.go b/controllers/cluster.go
new file mode 100644
index 0000000000000000000000000000000000000000..ba08b7e63e0abe38194d0c1b01051fc13868c1f6
--- /dev/null
+++ b/controllers/cluster.go
@@ -0,0 +1,179 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:56
+ * Description: HA集群控制器
+ ******************************************************************************/
+package controllers
+
+import (
+ "encoding/json"
+ "openkylin.com/ha-api/models"
+
+ "github.com/beego/beego/v2/core/logs"
+ "github.com/beego/beego/v2/server/web"
+)
+
+type ClustersController struct {
+ web.Controller
+}
+
+type MultipleClustersController struct {
+ web.Controller
+}
+
+type Sync_configController struct {
+ web.Controller
+}
+
+type ClusterSetupController struct {
+ web.Controller
+}
+
+type ClusterDestroyController struct {
+ web.Controller
+}
+
+type ClustersStatusController struct {
+ web.Controller
+}
+
+type ClusterRemoveController struct {
+ web.Controller
+}
+
+func (mcc *MultipleClustersController) Post() {
+ logs.Debug("Handle post request in MultipleClustersController.")
+ result := map[string]interface{}{}
+ reqData := make(map[string]interface{})
+ //need to check whether we want to add or remove cluster
+ if err := json.Unmarshal(mcc.Ctx.Input.RequestBody, &reqData); err != nil {
+ result = make(map[string]interface{})
+ result["action"] = false
+ result["error"] = "invalid input data"
+ } else {
+ result = models.ClusterAdd(reqData)
+ }
+
+ mcc.Data["json"] = &result
+ mcc.ServeJSON()
+
+}
+
+func (sc *Sync_configController) Post() {
+ logs.Debug("handle post request in ClustersController.")
+ result := map[string]interface{}{}
+ reqData := make(map[string]interface{})
+ if err := json.Unmarshal(sc.Ctx.Input.RequestBody, &reqData); err != nil {
+ result = make(map[string]interface{})
+ result["action"] = false
+ result["error"] = "invalid input data"
+ } else {
+ result = models.SyncConfig(reqData)
+ }
+ sc.Data["json"] = &result
+ sc.ServeJSON()
+}
+
+func (csc *ClusterSetupController) Post() {
+ logs.Debug("handle post request in ClustersController.")
+ result := map[string]interface{}{}
+ reqData := make(map[string]interface{})
+ if err := json.Unmarshal(csc.Ctx.Input.RequestBody, &reqData); err != nil {
+ result = make(map[string]interface{})
+ result["action"] = false
+ result["error"] = "invalid input data"
+ } else {
+ result = models.ClusterSetup(reqData)
+ }
+
+ csc.Data["json"] = &result
+ csc.ServeJSON()
+}
+
+//
+//func (mcc *MultipleClustersController) Get() {
+// logs.Debug("Handle get request in MultipleClustersController.")
+// //need to return cluster data through res.
+//
+//}
+
+func (cc *ClustersController) Get() {
+ logs.Debug("handle get request in ClustersController.")
+ result := models.GetClusterPropertiesInfo()
+ cc.Data["json"] = &result
+ cc.ServeJSON()
+}
+
+func (csc *ClustersStatusController) Get() {
+ logs.Debug("handle get request in ClustersController.")
+ result := models.GetClusterInfo()
+ csc.Data["json"] = &result
+ csc.ServeJSON()
+}
+
+func (cc *ClustersController) Post() {
+ logs.Debug("handle post request in ClustersController.")
+ cc.ServeJSON()
+}
+
+func (cd *ClusterDestroyController) Post() {
+ logs.Debug("handle post request in ClustersController.")
+ result := models.ClustersDestroy()
+ cd.Data["json"] = &result
+ // return result of destroying cluster back to user.
+ cd.ServeJSON()
+}
+
+func (crc *ClusterRemoveController) Post() {
+ logs.Debug("handle post request in ClustersController.")
+ var Result models.RemoveRet
+ var ReqData models.RemoveData
+ body := crc.Ctx.Input.RequestBody
+ err := json.Unmarshal(body, &ReqData)
+ if err != nil {
+ Result.Action = false
+ Result.Error = "invalid input data"
+ crc.Data["json"] = &Result
+ crc.ServeJSON()
+ } else {
+ Result2 := models.ClusterRemove(ReqData)
+ crc.Data["json"] = Result2
+ crc.ServeJSON()
+ }
+}
+
+func (cc *ClustersController) Put() {
+ logs.Debug("handle put request in ClustersController.")
+ result := map[string]interface{}{}
+
+ reqData := make(map[string]interface{})
+ if err := json.Unmarshal(cc.Ctx.Input.RequestBody, &reqData); err != nil {
+ result = make(map[string]interface{})
+ result["action"] = false
+ result["error"] = "invalid input data"
+ } else {
+ result = models.UpdateClusterProperties(reqData)
+ }
+
+ cc.Data["json"] = &result
+ cc.ServeJSON()
+}
+
+type LocalHaOperation struct {
+ web.Controller
+}
+
+func (lho *LocalHaOperation) Put() {
+ action := lho.Ctx.Input.Param("action")
+ lho.Data["json"] = models.OperationClusterAction(action)
+ lho.ServeJSON()
+}
diff --git a/controllers/commands.go b/controllers/commands.go
index db39b5bcc02973316ba2fabd8a6ab12864ea1dda..2e0e39563ed78d61173a8df87a2ac6e064f90b76 100644
--- a/controllers/commands.go
+++ b/controllers/commands.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:58
+ * Description: 命令控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/controllers/hacluster.go b/controllers/hacluster.go
deleted file mode 100644
index 9223bb2a20001380a5a56b748994e570791064fb..0000000000000000000000000000000000000000
--- a/controllers/hacluster.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package controllers
-
-import (
- "encoding/json"
-
- "github.com/beego/beego/v2/core/logs"
- "github.com/beego/beego/v2/server/web"
-
- "openkylin.com/ha-api/models"
-)
-
-type HAClustersController struct {
- web.Controller
-}
-
-func (hcc *HAClustersController) Get() {
- // TODO: handle get here
- logs.Debug("handle get request in HAClustersController.")
- result := models.GetClusterPropertiesInfo()
- hcc.Data["json"] = &result
- hcc.ServeJSON()
-}
-
-func (hcc *HAClustersController) Post() {
- logs.Debug("handle post request in HAClustersController.")
- // do nothing here
- hcc.ServeJSON()
-}
-
-func (hcc *HAClustersController) Put() {
- logs.Debug("handle put request in HAClustersController.")
- result := map[string]interface{}{}
-
- reqData := make(map[string]interface{})
- if err := json.Unmarshal(hcc.Ctx.Input.RequestBody, &reqData); err != nil {
- result = make(map[string]interface{})
- result["action"] = false
- result["error"] = "invalid input data"
- } else {
- result = models.UpdateClusterProperties(reqData)
- }
-
- hcc.Data["json"] = &result
- hcc.ServeJSON()
-}
-
-type LocalHaOperation struct {
- web.Controller
-}
-
-func (lho *LocalHaOperation) Put() {
- action := lho.Ctx.Input.Param("action")
- lho.Data["json"] = models.OperationClusterAction(action)
- lho.ServeJSON()
-}
diff --git a/controllers/heatbeat.go b/controllers/heatbeat.go
index 79be1ca844c8eabf8ec9d0781ff7b661ec8a28cd..8318811cb04d085740291a0060308de53cef6719 100644
--- a/controllers/heatbeat.go
+++ b/controllers/heatbeat.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:55
+ * Description: 磁盘心跳控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/controllers/html.go b/controllers/html.go
index ca7df736e82b7290cdaac4af0e82b6998cd9575f..ddf11a7d345b92cc5f25d133a1cf5eac45e4753e 100644
--- a/controllers/html.go
+++ b/controllers/html.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:53
+ * Description: 网页控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/controllers/log.go b/controllers/log.go
index d2f8a4f431f1a98fb6e74116f35df46fa6263bce..57eb27f4c8ff1420d40b999a814dd8000c1a0761 100644
--- a/controllers/log.go
+++ b/controllers/log.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:51
+ * Description: 日志下载控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/controllers/login.go b/controllers/login.go
index 1c67681745beb50eca7486514f366241b183d843..7f2553b7aeef8be2104794b8a6b61dc2b37ee322 100644
--- a/controllers/login.go
+++ b/controllers/login.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:49
+ * Description: 登录控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/controllers/meta.go b/controllers/meta.go
index 6f6081f3976a5398af680819a4da4f91c122cbb7..555c8e6e93a7e8a83a04bf0e3fe83ab5b2986e4c 100644
--- a/controllers/meta.go
+++ b/controllers/meta.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:48
+ * Description: 元控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/controllers/node.go b/controllers/node.go
index c44398c3f43453ad6a4cd98e9cb1a2509540873d..f93e85889cf75679575ed6d6de779fa89524edda 100644
--- a/controllers/node.go
+++ b/controllers/node.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:46
+ * Description: 节点控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/controllers/resource.go b/controllers/resource.go
index f45fd739d64f20b5ed7948db64361bec84f4dc3c..32c62e702eb40663c87b84318203192905937396 100644
--- a/controllers/resource.go
+++ b/controllers/resource.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-19 17:37:45
+ * Description: 资源控制器
+ ******************************************************************************/
package controllers
import (
diff --git a/docs/api.md b/docs/api.md
index 68117447d23d0a8f3c0b03ce65266af7212f93a5..aab66389f659ed975fcb0227de1268f544d862fa 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -483,9 +483,17 @@ Method:PUT
请求参数:
-| 参数名称 | 是否必填 | 传入方式 | 参数类型 | 参数说明 |
-| :---------------------- | ---------------- | :----------------- | :----------------- | ----------------------- |
-| no-quorum-policy(示例) | 是 | json | string | 集群属性名及新的配置 |
+| 参数名称 | 是否必填(其中一项必改) | 传入方式 | 参数类型 | 参数说明 |
+|:-----------------------|--------------|:-----|:--------|------------|
+| no-quorum-policy | 是 | json | string | 集群属性名及新的配置 |
+| symmetric-cluster | 是 | json | boolean | none |
+| maintenance-mode | 是 | json | boolean | none |
+| start-failure-is-fatal | 是 | json | boolean | none |
+| stonith-enabled | 是 | json | boolean | none |
+| node-health-strategy | 是 | json | string | none |
+| node-health-green | 是 | json | string | none |
+| node-health-yellow | 是 | json | string | none |
+| node-health-red | 是 | json | string | none |
请求示例:
@@ -504,6 +512,7 @@ Method:PUT
| action | bool | 返回结果状态 |
| info | string | 执行结果提示信息 |
+
响应示例:
```
@@ -567,6 +576,8 @@ Method:PUT
}
```
+#####
+
### 2.2 节点
#### 2.2.1 获取节点列表
@@ -583,10 +594,13 @@ Method:GET
响应参数:
-| 参数名称 | 参数类型 | 参数说明 |
-| :---------------------------- | :--------------------------------- | ------------------------------------ |
-| action | bool | 返回结果状态 |
-| data | string | 节点信息 |
+| 参数名称 | 参数类型 | 参数说明 |
+|:-------|:---------|-----------------------------|
+| action | bool | 获取节点信息是否成功 |
+| data | [object] | 节点信息,包含t以下的id,status以及is_dc |
+| id | string | 节点名称 |
+| status | string | 节点状态 |
+| is_dc | string | 是否为dc节点 |
响应示例:
@@ -618,19 +632,19 @@ Method:GET
请求参数:
-| 参数名称 | 是否必填 | 传入方式 | 参数类型 | 参数说明 |
-| :---------------- | -------------- | :-------------- | :------------ | --------------------------------- |
-| nodeid | 是 | path | string | 节点id |
+| 参数名称 | 是否必填 | 传入方式 | 参数类型 | 参数说明 |
+|:-------|------|:-----|:-------|------|
+| nodeid | 是 | path | string | 节点id |
响应格式:json
响应参数:
-| 参数名称 | 参数类型 | 参数说明 |
-| :---------------------------- | :--------------------------------- | ------------------------------------ |
-| action | bool | 返回结果状态 |
-| data | string | 节点信息 |
-| ips | array | 节点ip列表 |
+| 参数名称 | 参数类型 | 参数说明 |
+|:-------|:-------|------------|
+| action | bool | 节点信息返回结果状态 |
+| data | string | 节点信息 |
+| ips | array | 节点心跳ip列表 |
响应示例:
@@ -653,10 +667,10 @@ Method:PUT
请求参数:
-| 参数名称 | 是否必填 | 传入方式 | 参数类型 | 参数说明 |
-| :---------------- | -------------- | :-------------- | :------------ | --------------------------------- |
-| node_id | 是 | path | string | 节点id |
-| action | 是 | path | string | 节点操作,包括unstandby、standby、stop、start和restart |
+| 参数名称 | 是否必填 | 传入方式 | 参数类型 | 参数说明 |
+|:--------|------|:-----|:-------|--------------------------------------------------|
+| node_id | 是 | path | string | 节点id |
+| action | 是 | path | string | 支持修改的节点操作,包括unstandby、standby、stop、start和restart |
请求示例:
@@ -671,10 +685,10 @@ Method:PUT
响应参数:
-| 参数名称 | 参数类型 | 参数说明 |
-| :---------------------------- | :--------------------------------- | ------------------------------------ |
-| action | bool | 返回结果状态 |
-| info | string | 节点操作信息 |
+| 参数名称 | 参数类型 | 参数说明 |
+|:-------|:-------|------------|
+| action | bool | 节点修改返回结果状态 |
+| info | string | 节点操作信息 |
响应示例:
@@ -1215,9 +1229,14 @@ Method:POST
请求参数:
-| 参数名称 | 是否必填 | 传入方式 | 参数类型 | 参数说明 |
-| :--------------- | -------------- | :------------- | :------------ | -------------------------- |
-| category | 是 | json | string | 资源类型 |
+| 参数名称 | 是否必填 | 传入方式 | 参数类型 | 参数说明 |
+|:--------------------|------|:-----|:-------|--------|
+| category | 是 | json | string | 资源类型 |
+| id | 是 | json | string | 资源名 |
+| instance_attributes | 是 | json | object | none |
+| class | 是 | json | string | 资源种类 |
+| type | 是 | json | string | 资源脚本名称 |
+| provider | 是 | json | string | 资源提供者 |
请求示例:
@@ -3263,4 +3282,101 @@ Method:PUT
"action": True,
info": "Action on node success"
}
-```
\ No newline at end of file
+```
+
+### 2.13 集群管理
+
+#### 2.13.1 创建集群
+
+URI:/api/v1/managec/cluster_setup
+
+Method:POST
+
+##### 请求参数
+
+| 参数名称 | 位置 | 类型 | 是否必选 | 说明 |
+| --------------- | ---- | -------- | -------- | --------------------- |
+| body | body | object | 否 | none |
+| >>cluster_name | body | string | 是 | 集群名称 |
+| >>data | body | [object] | 是 | 创建集群的节点数据 |
+| >>>>nodeid | body | integer | 是 | 节点id |
+| >>>>name | body | string | 是 | 节点名称 |
+| >>>>password | body | string | 是 | 节点hacluster用户密码 |
+| >>>>ring0_adddr | body | string | 是 | 节点心跳ip |
+
+##### 返回示例:成功
+
+```
+{
+ "action": true,
+ "message": "集群创建成功"
+}
+```
+
+##### 返回结果
+
+| 状态码 | 状态码含义 | 说明 | 数据模型 |
+| ------ | ---------- | ---- | -------- |
+| 200 | OK | 成功 | Inline |
+
+##### 返回数据结构
+
+状态码 **200**
+
+| 参数名称 | 类型 | 是否必选 | 约束 | 说明 |
+| --------- | ------- | -------- | ---- | -------------------- |
+| >>action | boolean | true | none | 创建集群操作是否成功 |
+| >>message | string | true | none | 提示信息 |
+
+
+
+#### 2.13.2 摧毁集群
+
+URI:/api/v1/managec/cluster_destroy
+
+Method:POST
+
+##### Body请求参数
+
+```
+{
+ "cluster_name": [
+ "hacluster"
+ ]
+}
+```
+
+| 参数名称 | 位置 | 类型 | 是否必选 | 说明 |
+| -------------- | ---- | ------ | -------- | -------- |
+| body | body | object | 否 | |
+| >>cluster_name | body | string | 是 | 集群名称 |
+
+##### 返回示例:成功
+
+```
+{
+ "action": true,
+ "data": [
+ true
+ ],
+ "clusters": [],
+ "detailInfo": []
+}
+```
+
+##### 返回结果
+
+| 状态码 | 状态码含义 | 说明 | 数据模型 |
+| ------ | ---------- | ---- | -------- |
+| 200 | OK | 成功 | Inline |
+
+##### 返回数据结构
+
+状态码**200**
+
+| 名称 | 类型 | 必选 | 约束 | 说明 |
+| ------------ | --------- | ---- | ---- | -------------------------- |
+| >>action | boolean | true | none | 摧毁操作是否成功 |
+| >>data | [boolean] | true | none | 每个集群摧毁操作的结果汇总 |
+| >>cluster | [string] | true | none | 摧毁失败的集群列表 |
+| >>detailInfo | [string] | true | none | 摧毁失败集群的详细信息 |
\ No newline at end of file
diff --git a/main.go b/main.go
index d210a115e6679d0b3d81ab8ef0dea2a621b963ed..459fbeb3006b2a84029e333f32816679aeae9419 100644
--- a/main.go
+++ b/main.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 14:21:08
+ * Description: ha-api的入口
+ ******************************************************************************/
package main
import (
diff --git a/models/alarms.go b/models/alarms.go
index 476cbf144200ca92e38879f135fee92a0ccd60d2..00bbd111cbe04d4d3efbfdf5f811613299740128 100644
--- a/models/alarms.go
+++ b/models/alarms.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:05:59
+ * Description: 告警功能
+ ******************************************************************************/
package models
import (
diff --git a/models/cluster.go b/models/cluster.go
index 51b8685ebb25467136791bf00b0926bcaa772b2f..7dcfed40be2cc841b3fb6648764ff8dcd7d9883f 100644
--- a/models/cluster.go
+++ b/models/cluster.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:30:18
+ * Description: 集群相关功能的实现
+ ******************************************************************************/
package models
import (
@@ -38,6 +52,30 @@ func GetClusterPropertiesInfo() map[string]interface{} {
return result
}
+//
+//func CreateCluster(clusterInfo map[string]interface{}) map[string]interface{} {
+// result := map[string]interface{}{}
+// logs.Debug(clusterInfo)
+// if len(clusterInfo) == 0 {
+// result["action"] = false
+// result["error"] = "No input data"
+// return result
+// }
+// authRes := hostAuth(clusterInfo)
+// if !authRes["action"] {
+// return authRes
+// } else {
+// nodeName := clusterInfo["node_name"]
+// url := "https://" + fmt.Sprint(nodeName) + ":" + strconv.Itoa(8080) + "/api/v1/managec/local_cluster_info"
+// resp, err := http.Get(url)
+// if resp.StatusCode == 200 {
+//
+// }
+// }
+// return result
+//
+//}
+
func UpdateClusterProperties(newProp map[string]interface{}) map[string]interface{} {
result := map[string]interface{}{}
@@ -48,26 +86,26 @@ func UpdateClusterProperties(newProp map[string]interface{}) map[string]interfac
return result
}
- for k, v := range newProp {
- var value string
- if t, ok := v.(string); ok {
- value = t
- } else if t, ok := v.(bool); ok {
+ for key, value := range newProp {
+ var strValue string
+ if t, ok := value.(string); ok {
+ strValue = t
+ } else if t, ok := value.(bool); ok {
if t == true {
- value = "true"
+ strValue = "true"
} else {
- value = "false"
+ strValue = "false"
}
- } else if t, ok := v.(float64); ok {
- value = strconv.FormatInt(int64(t), 10)
+ } else if t, ok := value.(float64); ok {
+ strValue = strconv.FormatInt(int64(t), 10)
}
var cmdStr string
// special for getting resource-stickiness property
- if k == "resource-stickiness" {
- cmdStr = "crm_attribute -t rsc_defaults -n resource-stickiness -v " + value
+ if key == "resource-stickiness" {
+ cmdStr = "crm_attribute -t rsc_defaults -n resource-stickiness -v " + strValue
} else {
- cmdStr = "crm_attribute -t crm_config -n " + k + " -v " + value
+ cmdStr = "crm_attribute -t crm_config -n " + key + " -v " + strValue
}
out, err := utils.RunCommand(cmdStr)
diff --git a/models/cluster_test.go b/models/cluster_test.go
index 69b833262f253ab5a9358e246500403244e72413..27839d08390a547f77ee42efdef584dab20a3bf8 100644
--- a/models/cluster_test.go
+++ b/models/cluster_test.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:30:17
+ * Description: 集群测试用例
+ ******************************************************************************/
package models
import "testing"
diff --git a/models/commands.go b/models/commands.go
index a39e9d6f8fa9256e2af840a60b9280823bd5a206..8430fe4328a3b720ba98635c2e9354a728f8e973 100644
--- a/models/commands.go
+++ b/models/commands.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:30:19
+ * Description: 集群命令
+ ******************************************************************************/
package models
import (
diff --git a/models/config.go b/models/config.go
new file mode 100644
index 0000000000000000000000000000000000000000..c9cd494c79bf5b5e671d7241258912bcaf74ef73
--- /dev/null
+++ b/models/config.go
@@ -0,0 +1,50 @@
+package models
+
+import (
+ "bufio"
+ "os"
+ "strings"
+)
+
+func isClusterExist() bool {
+ _, err := os.Stat("/etc/corosync/corosync.conf")
+ return err == nil
+}
+
+func getNodeList() []string {
+
+ filename := "/etc/corosync/corosync.conf"
+ node_list := []string{} // 存储文件内数据
+
+ file, err := os.Open(filename)
+ if err != nil {
+ return []string{"error " + "File " + filename + " doesn't exist!"}
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ foundNodeList := false
+ for scanner.Scan() {
+ line := scanner.Text()
+ if strings.Contains(line, "nodelist {") {
+ foundNodeList = true
+ break
+ }
+ }
+
+ if !foundNodeList {
+ return []string{"No nodelist found in the file."}
+ }
+
+ for scanner.Scan() {
+ line := strings.TrimSpace(scanner.Text())
+ if strings.Contains(line, "quorum {") {
+ break
+ }
+ if line != "nodelist {" && line != "}" && line != "" {
+ node_list = append(node_list, line)
+ }
+ }
+
+ return node_list
+}
diff --git a/models/heartbeat.go b/models/heartbeat.go
index 9c0987949586bd2e444a318aa8f4a6d6100826f4..c3c7d846130628110a726740e53d8588f4761e06 100644
--- a/models/heartbeat.go
+++ b/models/heartbeat.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:31:21
+ * Description: 磁盘心跳相关功能的实现
+ ******************************************************************************/
package models
import (
diff --git a/models/heartbeat_test.go b/models/heartbeat_test.go
index 59f5ad8608ea22fc676e5fe046b5ad06abc351fa..aa7aa235df337bfb0355767c727cbd79881009ff 100644
--- a/models/heartbeat_test.go
+++ b/models/heartbeat_test.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:30:21
+ * Description: 磁盘心跳测试用例
+ ******************************************************************************/
package models
import (
diff --git a/models/internel/cibadmin.go b/models/internel/cibadmin.go
index a5e6d370858e6a1ae176322f9ba3e3c462356ec9..8208cb561a4dbfa974402256dd74f038828bd019 100644
--- a/models/internel/cibadmin.go
+++ b/models/internel/cibadmin.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:00:09
+ * Description: provides direct access to the cluster configuration.
+ ******************************************************************************/
package models
// CibAdmin cibadmin provides direct access to the cluster configuration.
diff --git a/models/internel/crm.go b/models/internel/crm.go
index 71a3897e0bd6c4c3a173321c8059f48fba077a43..1b3216e3a74581d5d9f5d7ab408ad43f9dc35940 100644
--- a/models/internel/crm.go
+++ b/models/internel/crm.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:01:32
+ * Description: Provides a summary of cluster's current state.
+ ******************************************************************************/
package models
type crm_attribute struct{}
diff --git a/models/internel/pcs.go b/models/internel/pcs.go
index 0012ae54dc5ffe14aebf038daba1d8aff28f211b..d63db9c428dcb143208ad48afb743be591ce7e0c 100644
--- a/models/internel/pcs.go
+++ b/models/internel/pcs.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:02:14
+ * Description: Perform tasks related to pcs.
+ ******************************************************************************/
package models
type PCS struct{}
diff --git a/models/internel/stonith_admin.go b/models/internel/stonith_admin.go
index ab76c7cfe86105c3bf7e235304d8e27fa5914fdb..4f31091f9f6deb16bc4e5908df1b80e634221313 100644
--- a/models/internel/stonith_admin.go
+++ b/models/internel/stonith_admin.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:05:00
+ * Description: Perform tasks related to Stonith
+ ******************************************************************************/
package models
type StonithAdmin struct{}
diff --git a/models/log.go b/models/log.go
index f143cb25406833c0cd175bef94afb6c12361d9b1..ab0c031edf361d9a6ee070959a53ddf1d94271a0 100644
--- a/models/log.go
+++ b/models/log.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 10:35:08
+ * Description: 日志功能
+ ******************************************************************************/
package models
import (
diff --git a/models/manage_clusters.go b/models/manage_clusters.go
new file mode 100644
index 0000000000000000000000000000000000000000..b8ca4b507cbed3a84bda382524fc0276922930e8
--- /dev/null
+++ b/models/manage_clusters.go
@@ -0,0 +1,386 @@
+package models
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "openkylin.com/ha-api/utils"
+ "os"
+)
+
+var clustersFileName = "/usr/share/heartbeat-gui/ha-api/ClustersInfo.conf"
+var port = 8088
+
+type RemoveData struct {
+ Cluster_name []string
+}
+
+type RemoveRet struct {
+ Action bool `json:"action,omitempty"`
+ Error string `json:"error,omitempty"`
+ Faild_cluster []string `json:"faild_cluster,omitempty"`
+ Data []bool `json:"data,omitempty"`
+}
+
+// ClusterInfo is a structure representing information about clusters.
+type ClusterInfo struct {
+ Text map[string]interface{}
+ Version int
+ Clusters []interface{}
+}
+
+// NewClustersInfo creates a new ClusterInfo instance using the provided text data.
+// If the text data is nil or empty, default values are initialized.
+func NewClustersInfo(text map[string]interface{}) *ClusterInfo {
+ c := &ClusterInfo{
+ Text: text,
+ }
+
+ if text == nil || len(text) == 0 {
+ c.Text = make(map[string]interface{})
+ c.Version = 0
+ c.Clusters = make([]interface{}, 0)
+ c.Text["version"] = c.Version
+ c.Text["clusters"] = c.Clusters
+ } else {
+ c.Version = int(text["version"].(float64))
+ c.Clusters = text["clusters"].([]interface{})
+ }
+
+ return c
+}
+
+// Save updates the version, performs a backup, and saves the ClusterInfo to a file in JSON format.
+func (ci *ClusterInfo) Save() {
+ ci.Version++
+ ci.Backup()
+ saveConf := ci.UpdateText()
+ file, err := os.Create(clustersFileName)
+ if err != nil {
+ fmt.Println("Error creating file:", err)
+ return
+ }
+ defer file.Close()
+
+ enc := json.NewEncoder(file)
+ enc.SetIndent("", " ")
+ if err := enc.Encode(saveConf); err != nil {
+ fmt.Println("Error encoding JSON:", err)
+ return
+ }
+}
+
+// Backup creates a backup of the cluster information file with a timestamp.
+func (ci *ClusterInfo) Backup() {
+ // Implement backup functionality
+ // You can use the time and date in the file name
+}
+
+// UpdateText updates the version and clusters in the Text field and returns it.
+func (ci *ClusterInfo) UpdateText() map[string]interface{} {
+ ci.Text["version"] = ci.Version
+ ci.Text["clusters"] = ci.Clusters
+ return ci.Text
+}
+
+// AddCluster adds cluster information to the Clusters field.
+func (ci *ClusterInfo) AddCluster(clusterInfo map[string]interface{}) {
+ ci.Clusters = append(ci.Clusters, clusterInfo)
+}
+
+// IsClusterNameInUse checks if a cluster name is already in use.
+func (ci *ClusterInfo) IsClusterNameInUse(clusterName string) bool {
+ for _, c := range ci.Clusters {
+ cV := c.(map[string]interface{})
+ if cV["cluster_name"].(string) == clusterName {
+ return true
+ }
+ }
+ return false
+}
+
+// SetVersion sets the version of the ClusterInfo.
+func (ci *ClusterInfo) SetVersion(version int) {
+ ci.Version = version
+}
+
+func (ci *ClusterInfo) DeleteCluster(clusterNameJson string) bool {
+ for i, c := range ci.Clusters {
+ cV := c.(map[string]interface{})
+ if cV["cluster_name"] == clusterNameJson {
+ ci.Clusters = append(ci.Clusters[:i], ci.Clusters[i+1:]...)
+ return true
+ }
+ }
+ return false
+}
+
+// localClusterInfo retrieves the cluster information locally and returns it as a map.
+// If no cluster exists, an empty map is returned.
+func localClusterInfo() map[string]interface{} {
+ allInfo := GetClusterInfo()
+ if allInfo["cluster_exist"] == true {
+ clusterInfo := clusterInfoParse(allInfo)
+ return clusterInfo
+ }
+ return make(map[string]interface{})
+}
+
+// clusterInfoParse takes cluster information as input and parses it into a map of string to interface
+func clusterInfoParse(clusterInfo map[string]interface{}) map[string]interface{} {
+ clusterParse := make(map[string]interface{})
+ clusterParse["cluster_name"] = clusterInfo["cluster_name"]
+ nodes := make([]string, 0)
+ nodeIDs := make([]interface{}, 0)
+ ips := make([]map[string]interface{}, 0)
+ dataInterface, _ := clusterInfo["data"].([]interface{})
+ var nodesInfo []map[string]interface{}
+ for _, item := range dataInterface {
+ nodesInfo = append(nodesInfo, item.(map[string]interface{}))
+ }
+ for _, nodeInfo := range nodesInfo {
+ nodes = append(nodes, nodeInfo["name"].(string))
+ nodeIDs = append(nodeIDs, nodeInfo["nodeid"])
+
+ ip := make(map[string]interface{})
+ for k, v := range nodeInfo {
+ if k != "name" && k != "nodeid" && k != "password" {
+ ip[k] = v
+ }
+ }
+ ips = append(ips, ip)
+ }
+
+ clusterParse["nodes"] = nodes
+ clusterParse["nodeid"] = nodeIDs
+ clusterParse["ip"] = ips
+ return clusterParse
+}
+
+// getLocalConf reads the local cluster configuration from a file and returns a ClusterInfo instance.
+func getLocalConf() *ClusterInfo {
+ localFile := readFile(clustersFileName)
+
+ localConf := NewClustersInfo(localFile)
+ return localConf
+
+}
+
+// readFile reads a JSON file, decodes its content, and returns it as a map.
+func readFile(filename string) map[string]interface{} {
+ var newDict map[string]interface{}
+
+ infile, err := os.Open(filename)
+ if err != nil {
+ fmt.Println("Error opening file:", err)
+ return newDict
+ }
+ defer infile.Close()
+
+ data, err := ioutil.ReadAll(infile)
+ if err != nil {
+ fmt.Println("Error reading file:", err)
+ return newDict
+ }
+
+ if err := json.Unmarshal(data, &newDict); err != nil {
+ fmt.Println("Error decoding JSON:", err)
+ return newDict
+ }
+
+ return newDict
+}
+
+// comment out due to type error as localconf could not be {}, it should be of type *ClusterInfo
+// SyncConfig synchronizes the local configuration with remote configuration.
+// Returns appropriate results indicating the synchronization status.
+func SyncConfig(remoteConf map[string]interface{}) map[string]interface{} {
+ localConf := getLocalConf()
+ remoteClusterInfo := NewClustersInfo(remoteConf)
+ if remoteClusterInfo.Version >= localConf.Version { //|| localConf == ({}) {
+ remoteClusterInfo.SetVersion(remoteClusterInfo.Version - 1)
+ remoteClusterInfo.Save()
+ return map[string]interface{}{
+ "result": "receive",
+ "conf": remoteClusterInfo.Text,
+ }
+ } else {
+ return map[string]interface{}{
+ "result": "refuse",
+ }
+ }
+}
+
+// syncClusterConfFile synchronizes the cluster configuration file with all nodes in the cluster.
+func syncClusterConfFile(conf *ClusterInfo) {
+ // Get local cluster info
+ clusterInfo := localClusterInfo()
+
+ // If the current node has no cluster config, save the provided config
+ if len(clusterInfo) == 0 {
+ conf.Save()
+ return
+ }
+
+ // Sync config file with all nodes in the cluster
+ nodeList := clusterInfo["nodes"].([]string)
+ for _, node := range nodeList {
+ // Node-to-node config file sync operation
+ url := fmt.Sprintf("https://%s:%s/remote/api/v1/sync_config", node, port)
+ confJSON, err := json.Marshal(conf.Text)
+ if err != nil {
+ fmt.Println("Error marshaling config to JSON:", err)
+ return
+ }
+
+ _, err = http.Post(url, "application/json", bytes.NewBuffer(confJSON))
+ if err != nil {
+ fmt.Println("Error syncing config to node:", err)
+ }
+ }
+
+ fmt.Println("Sync complete")
+}
+
+// hostAuth performs host authentication using the provided information.
+func hostAuth(authInfo map[string]interface{}) map[string]interface{} {
+ authFailed := false
+ nodeList := authInfo["node_list"].([]string)
+ passwordList := authInfo["password"].([]string)
+
+ for i := 0; i < len(nodeList); i++ {
+ authCmd := fmt.Sprintf("pcs host auth %s -u hacluster -p '%s'", nodeList[i], passwordList[i])
+
+ _, err := utils.RunCommand(authCmd)
+
+ if err != nil {
+ authFailed = true
+ break
+ }
+ }
+
+ if authFailed {
+ return map[string]interface{}{
+ "action": false,
+ "error": "host auth failed",
+ }
+ }
+
+ return map[string]interface{}{
+ "action": true,
+ "message": "host auth success",
+ }
+}
+
+// ClusterAdd adds a new cluster using the provided node information.
+// Returns results indicating the success or failure of the operation.
+func ClusterAdd(nodeInfo map[string]interface{}) map[string]interface{} {
+ authInfo := make(map[string]interface{})
+ authInfo["node_list"] = nodeInfo["node_name"].(string)
+ authInfo["password"] = nodeInfo["password"].(string)
+
+ authRes := hostAuth(authInfo)
+
+ if !authRes["action"].(bool) {
+ return authRes
+ }
+
+ url := fmt.Sprintf("https://%s:%s/remote/api/v1/managec/local_cluster_info", authInfo["node_list"], port)
+ resp, err := http.Get(url)
+ if err != nil {
+ return map[string]interface{}{
+ "action": false,
+ "error": "添加集群失败"}
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode == http.StatusOK {
+ var NewClusterInfo map[string]interface{}
+ body, err := io.ReadAll(resp.Body)
+ resp.Body.Close()
+ err = json.Unmarshal(body, &NewClusterInfo)
+ if err != nil {
+ return map[string]interface{}{
+ "action": false,
+ "error": "添加集群失败"}
+ }
+
+ localConf := getLocalConf()
+ if localConf.IsClusterNameInUse(NewClusterInfo["cluster_name"].(string)) {
+ return map[string]interface{}{
+ "action": false,
+ "error": "请勿重复添加"}
+ }
+
+ localConf.AddCluster(NewClusterInfo)
+ localConf.Save()
+ syncClusterConfFile(localConf)
+ return map[string]interface{}{
+ "action": true,
+ "error": "添加集群成功"}
+ }
+
+ return map[string]interface{}{
+ "action": false,
+ "error": "添加集群失败"}
+}
+
+// ClusterSetup performs the setup of a cluster using the provided cluster information.
+func ClusterSetup(clusterInfo map[string]interface{}) map[string]interface{} {
+ authInfo := make(map[string]interface{})
+ nodeList := make([]string, 0)
+ passwords := make([]string, 0)
+
+ dataInterface, _ := clusterInfo["data"].([]interface{})
+
+ var data []map[string]interface{}
+ for _, item := range dataInterface {
+ data = append(data, item.(map[string]interface{}))
+ }
+
+ for _, node := range data {
+ nodeList = append(nodeList, node["name"].(string))
+ passwords = append(passwords, node["password"].(string))
+ }
+
+ authInfo["node_list"] = nodeList
+ authInfo["password"] = passwords
+
+ authRes := hostAuth(authInfo)
+ if !authRes["action"].(bool) {
+ return authRes
+ } else {
+ res := clusterSetup(clusterInfo)
+ if res["action"].(bool) {
+ localConf := getLocalConf()
+ localConf.AddCluster(clusterInfoParse(clusterInfo))
+ localConf.Save()
+ syncClusterConfFile(localConf)
+ }
+ return res
+ }
+}
+
+func ClusterRemove(RemoveInfo RemoveData) *RemoveRet {
+ clusters := RemoveInfo.Cluster_name
+ localConf := getLocalConf()
+ removeRes := make([]bool, 0)
+ faildCluster := make([]string, 0)
+ for _, cluster := range clusters {
+ res := localConf.DeleteCluster(cluster)
+ removeRes = append(removeRes, res)
+ if res == false {
+ faildCluster = append(faildCluster, cluster)
+ }
+ localConf.Save()
+ syncClusterConfFile(localConf)
+ }
+ var RetData RemoveRet
+ RetData.Action = true
+ RetData.Faild_cluster = faildCluster
+ RetData.Data = removeRes
+ return &RetData
+}
diff --git a/models/meta.go b/models/meta.go
index 30a75225920a605a992d69d105356d36efc4d022..dd6487a76a7482df7cc63f4af0b6a942ea1efa86 100644
--- a/models/meta.go
+++ b/models/meta.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:08:52
+ * Description: 资源元代码
+ ******************************************************************************/
package models
import (
diff --git a/models/node.go b/models/node.go
index a9540ed7985f592b9519824cc67c344624f957fe..c8038013faee5f8303a35e47b8262cf84df2bafe 100644
--- a/models/node.go
+++ b/models/node.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:08:21
+ * Description: 节点功能实现
+ ******************************************************************************/
package models
import (
diff --git a/models/node_test.go b/models/node_test.go
index 0b4fff6f3ef82c7472f5bf0b5c2357a800f9c50d..011f23c81d16e66f374fa22346ce1810de3b6c81 100644
--- a/models/node_test.go
+++ b/models/node_test.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:08:08
+ * Description: 节点测试用例
+ ******************************************************************************/
package models
// [root@ha1 ~]# crm_mon --as-xml
diff --git a/models/nodes_management.go b/models/nodes_management.go
new file mode 100644
index 0000000000000000000000000000000000000000..9b3b3ab8248cac9635a8e1e86d492e456f283629
--- /dev/null
+++ b/models/nodes_management.go
@@ -0,0 +1,204 @@
+package models
+
+import (
+ "bufio"
+ "fmt"
+ "openkylin.com/ha-api/utils"
+ "os"
+ "strconv"
+ "strings"
+)
+
+//nodes_info格式
+//{"nodeid": "1", "name": "HA1", "ring0_addr": "192.168.11.1", "ring1_addr": "192.168.11.4"},
+//{"nodeid": "2", "name": "HA2", "ring0_addr": "192.168.11.2", "ring1_addr": "192.168.11.5"}
+
+// getClusterName reads the cluster name from the corosync configuration file.
+// Returns a map indicating the result and the extracted cluster name, if available.
+func getClusterName() map[string]interface{} {
+ filename := "/etc/corosync/corosync.conf"
+ clusterName := ""
+ result := make(map[string]interface{})
+
+ file, err := os.Open(filename)
+ if err != nil {
+ result["action"] = false
+ result["error"] = "File " + filename + " doesn't exist!"
+ return result
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ for scanner.Scan() {
+ line := scanner.Text()
+ parts := strings.Split(line, ":")
+ if len(parts) >= 2 {
+ str1 := strings.TrimSpace(parts[0])
+ str2 := strings.TrimSpace(parts[1])
+ if str1 == "cluster_name" {
+ clusterName = str2
+ break
+ }
+ }
+ }
+
+ result["action"] = true
+ result["clusterName"] = clusterName
+ return result
+}
+
+// getClusterInfo retrieves cluster information, including cluster nodes and their properties.
+// Returns the cluster information in a structured map.
+func GetClusterInfo() map[string]interface{} {
+ _, currentNode := utils.RunCommand("cat /etc/hostname")
+ currentNodeStr := strings.ReplaceAll(fmt.Sprintf("%s", currentNode), "\n", "")
+
+ if isClusterExist() {
+ nodeList := getNodeList()
+ nodes := make([]map[string]string, 0)
+
+ index := 0
+ for index < len(nodeList) {
+ if nodeList[index] == "node {" {
+ index++
+ nodeInfo := make(map[string]string)
+ nodeInfoRet := make(map[string]string)
+
+ for index < len(nodeList) && nodeList[index] != "node {" {
+ d := make(map[string]string)
+ n := strings.Split(nodeList[index], ":")
+ d[n[0]] = strings.TrimSpace(n[1])
+ for k, v := range d {
+ nodeInfo[k] = v
+ }
+ index++
+ }
+
+ count := 0
+ for count < 2 {
+ for k, v := range nodeInfo {
+ item := map[string]string{k: v}
+ for key, value := range item {
+ nodeInfoRet[key] = value
+ }
+ count++
+ delete(nodeInfo, k)
+ }
+ }
+
+ for k, v := range nodeInfo {
+ if k != "nodeid" && k != "name" {
+ if isIPv4(v) {
+ nodeInfoRet[k] = v
+ } else {
+ nodeInfoRet[k] = ""
+ }
+ }
+ }
+
+ nodes = append(nodes, nodeInfoRet)
+ }
+ }
+
+ data := map[string]interface{}{
+ "action": true,
+ "cluster_exist": true,
+ "cluster_name": getClusterName(),
+ "currentNode": currentNodeStr,
+ "data": nodes,
+ }
+ return data
+ } else {
+ data := map[string]interface{}{
+ "action": false,
+ "cluster_exist": false,
+ "cluster_name": getClusterName(),
+ "currentNode": currentNodeStr,
+ "error": "Cluster not established!",
+ }
+ return data
+ }
+}
+
+// clusterSetup sets up a cluster with the provided node information.
+// Returns results indicating the success or failure of the cluster setup.
+func clusterSetup(addNodes map[string]interface{}) map[string]interface{} {
+ clusterName := ""
+ for k, v := range addNodes {
+ if k == "cluster_name" {
+ clusterName = v.(string)
+ }
+ }
+ if clusterName == "" {
+ clusterName = "hacluster"
+ }
+
+ nodeCmdStr := generateNodeCmdStr(addNodes["data"].([]interface{}))
+ cmd := "pcs cluster setup " + clusterName + nodeCmdStr + " totem token=8000 --start"
+ output, err := utils.RunCommand(cmd)
+ outputStr := string(output[:])
+ if err != nil {
+ if strings.Contains(outputStr, "Running cluster services") {
+ return map[string]interface{}{"action": false, "error": "添加的部分节点已在集群中,请先将这些节点从集群中移除,或从已在集群中进行添加节点操作。"}
+ }
+ return map[string]interface{}{"action": false, "error": "集群创建失败"}
+ } else {
+ return map[string]interface{}{"action": true, "message": "集群创建成功"}
+ }
+}
+
+// generateNodeCmdStr generates the command string for adding nodes to the cluster.
+// Returns the generated command string.
+func generateNodeCmdStr(nodesInfo []interface{}) string {
+ hbIPPrefix := "addr="
+ var cmd strings.Builder
+ hbIPCmd := ""
+ for _, nodeInfo := range nodesInfo {
+ nodeInfoV := nodeInfo.(map[string]interface{})
+ nodeStr := fmt.Sprintf("%v", nodeInfoV["name"])
+ for k, v := range nodeInfoV {
+ if k != "nodeid" && k != "name" && k != "port" && k != "password" {
+ hbIPCmd = fmt.Sprintf(" %s%s", hbIPPrefix, v)
+ nodeStr += hbIPCmd
+ }
+ }
+ cmd.WriteString(" " + nodeStr)
+ }
+
+ return cmd.String()
+}
+
+func ClustersDestroy() map[string]interface{} {
+ res := map[string]interface{}{}
+ cmd := "pcs cluster destroy --all"
+ out, err := utils.RunCommand(cmd)
+ if err != nil {
+ res["action"] = false
+ res["error"] = string(out)
+ return res
+ }
+ res["action"] = true
+ res["message"] = string(out)
+ return res
+}
+
+// isIPv4 checks if the provided string is a valid IPv4 address.
+// Returns true if the string is a valid IPv4 address, false otherwise.
+func isIPv4(ip string) bool {
+ parts := strings.Split(ip, ".")
+ if len(parts) != 4 {
+ return false
+ }
+
+ for _, part := range parts {
+ num, err := strconv.Atoi(part)
+ if err != nil {
+ return false
+ }
+ if num < 0 || num > 255 {
+ return false
+ }
+ }
+
+ return true
+}
diff --git a/models/resource.go b/models/resource.go
index 397771a91aee8fc5747af08b23838b8a0d391159..5f6a92af30aeabe7208e91246d50feda0ba8630d 100644
--- a/models/resource.go
+++ b/models/resource.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:09:01
+ * Description: 资源相关功能的实现
+ ******************************************************************************/
package models
import (
diff --git a/models/resource_test.go b/models/resource_test.go
index c745eea365ac7b0f82a08939f2deb68a23721f40..93242e96ece5c380039792b992ae3423c667af60 100644
--- a/models/resource_test.go
+++ b/models/resource_test.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:08:44
+ * Description: 资源测试用例
+ ******************************************************************************/
package models
import (
diff --git a/routers/router.go b/routers/router.go
index e476a554a182216003250e9f7f7f762b66bcc741..772a50375f8e0d71719b3fc823befe9eed22831b 100644
--- a/routers/router.go
+++ b/routers/router.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:12:16
+ * Description: 网页路由
+ ******************************************************************************/
package routers
import (
@@ -17,9 +31,15 @@ func init() {
web.Router("/kylinha-log-:filetail(.*\\.tar$)", &controllers.LogDownloadController{})
ns := web.NewNamespace("/api/v1",
- web.NSRouter("/haclusters/1", &controllers.HAClustersController{}),
+ web.NSRouter("/haclusters/1", &controllers.ClustersController{}),
+ web.NSRouter("/haclusters/1/cluster_status", &controllers.ClustersStatusController{}),
web.NSRouter("/login", &controllers.LoginController{}),
web.NSRouter("/logout", &controllers.LogoutController{}),
+ web.NSRouter("/managec/cluster_add", &controllers.MultipleClustersController{}),
+ web.NSRouter("/managec/sync_config", &controllers.Sync_configController{}),
+ web.NSRouter("/managec/cluster_setup", &controllers.ClusterSetupController{}),
+ web.NSRouter("/managec/cluster_destroy", &controllers.ClusterDestroyController{}),
+ web.NSRouter("/managec/cluster_remove", &controllers.ClusterRemoveController{}),
web.NSRouter("/haclusters/1/resources", &controllers.ResourceController{}),
web.NSRouter("/haclusters/1/resources/:rscID/:action", &controllers.ResourceActionController{}),
@@ -48,5 +68,6 @@ func init() {
web.NSRouter("/haclusters/1/commands", &controllers.CommandsController{}),
web.NSRouter("/haclusters/1/commands/:cmd_type", &controllers.CommandsRunnerController{}),
)
+
web.AddNamespace(ns)
}
diff --git a/service/session.go b/service/session.go
index 7f1f203ef473c6e86f9280b149da6270c35cd98c..5220a7b1e434d73bc4d62671ab219de1bc457b7a 100644
--- a/service/session.go
+++ b/service/session.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:12:13
+ * Description: 服务端配置
+ ******************************************************************************/
package service
import (
diff --git a/settings/settings.go b/settings/settings.go
index 847d790725bac7fc3ec73476c8aa9a0ed33f1ad3..d083c7aaf001773b7b89e315a511bbf28800b0e6 100644
--- a/settings/settings.go
+++ b/settings/settings.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:14:14
+ * Description: 集群中的一些配置
+ ******************************************************************************/
package settings
import (
diff --git a/utils/command.go b/utils/command.go
index 449f4f6a1ce34c48c2f4e781bc4a84203436d612..919d1427b9f44146c829057735e0bc3c2eaf3c23 100644
--- a/utils/command.go
+++ b/utils/command.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:18:25
+ * Description: 运行日志命令获取结果
+ ******************************************************************************/
package utils
import (
diff --git a/utils/command_test.go b/utils/command_test.go
index 2abe671f35e2ee68f75a29de910ff663eba4a73d..da22ddabfa3d6924547d34b92995762290be58e1 100644
--- a/utils/command_test.go
+++ b/utils/command_test.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:18:23
+ * Description: 集群命令的测试用例
+ ******************************************************************************/
package utils
import (
diff --git a/utils/host.go b/utils/host.go
index b86f081634be4f9c511111e2297e98037421953a..20d20ca7024e7a12bb7632892d5a349fee4efd4e 100644
--- a/utils/host.go
+++ b/utils/host.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:22:03
+ * Description: 主机corosync配置
+ ******************************************************************************/
package utils
import (
diff --git a/utils/host_test.go b/utils/host_test.go
index 0219ba6c2bb50bc0d1cd1dd32ebae5538623faa9..24b3258b29f4cae55c8a033e1077504e60bc1299 100644
--- a/utils/host_test.go
+++ b/utils/host_test.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:18:32
+ * Description: corosync配置获取的测试用例
+ ******************************************************************************/
package utils
import (
diff --git a/utils/pam.go b/utils/pam.go
index c9d5ae8e09a810391b6dcc25b7f6b8a7752d86f7..cefcda0c86ef685951c76b67659982004430edf4 100644
--- a/utils/pam.go
+++ b/utils/pam.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:28:40
+ * Description: PAM管理
+ ******************************************************************************/
package utils
import (
diff --git a/utils/utils.go b/utils/utils.go
index d5623c8cde5cb7359caf93463231b73cd5e988ab..92018478cdaeef05c9ca29e4a3c3994b666e019d 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved.
+ * ha-api is licensed under the Mulan PSL v2.
+ * You can use this software accodring to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liqiuyu
+ * Date: 2022-04-19 16:49:51
+ * LastEditTime: 2022-04-20 11:32:56
+ * Description: 删除重复数据,获取数字单位
+ ******************************************************************************/
package utils
import "regexp"