feat: 教学应用配置下发到网元功能
This commit is contained in:
@@ -225,7 +225,7 @@ func (s *NeConfigController) DataEdit(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 网元直连
|
// 网元直连
|
||||||
resData, err := neFetchlink.NeConfigInfoEdit(neInfo, body.ParamName, body.Loc, body.ParamData)
|
resData, err := neFetchlink.NeConfigUpdate(neInfo, body.ParamName, body.Loc, body.ParamData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, result.ErrMsg(err.Error()))
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
return
|
return
|
||||||
@@ -270,7 +270,7 @@ func (s *NeConfigController) DataAdd(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 网元直连
|
// 网元直连
|
||||||
resData, err := neFetchlink.NeConfigInfoAdd(neInfo, body.ParamName, body.Loc, body.ParamData)
|
resData, err := neFetchlink.NeConfigInstall(neInfo, body.ParamName, body.Loc, body.ParamData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, result.ErrMsg(err.Error()))
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
return
|
return
|
||||||
@@ -308,7 +308,7 @@ func (s *NeConfigController) DataRemove(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 网元直连
|
// 网元直连
|
||||||
resData, err := neFetchlink.NeConfigInfoDel(neInfo, query.ParamName, query.Loc)
|
resData, err := neFetchlink.NeConfigDelete(neInfo, query.ParamName, query.Loc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, result.ErrMsg(err.Error()))
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ func NeConfigInfo(neInfo model.NeInfo, paramName string) (map[string]any, error)
|
|||||||
return resData, nil
|
return resData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeConfigInfoEdit 网元配置更新
|
// NeConfigUpdate 网元配置更新
|
||||||
func NeConfigInfoEdit(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) {
|
func NeConfigUpdate(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) {
|
||||||
// array需要层级
|
// array需要层级
|
||||||
if loc != "" {
|
if loc != "" {
|
||||||
loc = fmt.Sprintf("?loc=%v", loc)
|
loc = fmt.Sprintf("?loc=%v", loc)
|
||||||
@@ -102,8 +102,8 @@ func NeConfigInfoEdit(neInfo model.NeInfo, paramName, loc string, data map[strin
|
|||||||
return resData, nil
|
return resData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeConfigInfoAdd 网元配置新增 array
|
// NeConfigInstall 网元配置新增 array
|
||||||
func NeConfigInfoAdd(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) {
|
func NeConfigInstall(neInfo model.NeInfo, paramName, loc string, data map[string]any) (map[string]any, error) {
|
||||||
// 网元参数配置新增(array)
|
// 网元参数配置新增(array)
|
||||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc)
|
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc)
|
||||||
resBytes, err := fetch.PostJSON(neUrl, data, nil)
|
resBytes, err := fetch.PostJSON(neUrl, data, nil)
|
||||||
@@ -131,8 +131,8 @@ func NeConfigInfoAdd(neInfo model.NeInfo, paramName, loc string, data map[string
|
|||||||
return resData, nil
|
return resData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeConfigInfoDel 网元配置删除 array
|
// NeConfigDelete 网元配置删除 array
|
||||||
func NeConfigInfoDel(neInfo model.NeInfo, paramName, loc string) (map[string]any, error) {
|
func NeConfigDelete(neInfo model.NeInfo, paramName, loc string) (map[string]any, error) {
|
||||||
// 网元参数配置删除(array)
|
// 网元参数配置删除(array)
|
||||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc)
|
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s?loc=%v", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc)
|
||||||
resBytes, err := fetch.Delete(neUrl, nil)
|
resBytes, err := fetch.Delete(neUrl, nil)
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package service
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"be.ems/src/framework/utils/parse"
|
||||||
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
neFetchlink "be.ems/src/modules/network_element/fetch_link"
|
||||||
neModel "be.ems/src/modules/network_element/model"
|
neModel "be.ems/src/modules/network_element/model"
|
||||||
neService "be.ems/src/modules/network_element/service"
|
neService "be.ems/src/modules/network_element/service"
|
||||||
@@ -205,11 +207,43 @@ func (r *PtNeConfigDataService) ApplyToNe(paramUser, neType string) error {
|
|||||||
if len(ptConf.ParamData) == 0 {
|
if len(ptConf.ParamData) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// 单层逐个更新
|
||||||
if ptConf.ParamType == "list" {
|
if ptConf.ParamType == "list" {
|
||||||
dataMap := ptConf.ParamData[0]
|
for k, v := range ptConf.ParamData[0] {
|
||||||
for k, v := range dataMap {
|
neFetchlink.NeConfigUpdate(neInfo, ptConf.ParamName, "", map[string]any{k: v})
|
||||||
fmt.Println(k, v)
|
}
|
||||||
|
}
|
||||||
|
// 多层逐个更新
|
||||||
|
if ptConf.ParamType == "array" {
|
||||||
|
// 删除原先配置
|
||||||
|
resData, err := neFetchlink.NeConfigInfo(neInfo, ptConf.ParamName)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if data, ok := resData["data"]; ok {
|
||||||
|
for i := 0; i < len(data.([]any)); i++ { // 倒序遍历
|
||||||
|
originIndex := i
|
||||||
|
newIndex := len(data.([]any)) - originIndex - 1
|
||||||
|
element := data.([]any)[newIndex]
|
||||||
|
loc := parse.Number(element.(map[string]any)["index"])
|
||||||
|
neFetchlink.NeConfigDelete(neInfo, ptConf.ParamName, fmt.Sprint(loc))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历新增
|
||||||
|
for _, v := range ptConf.ParamData {
|
||||||
|
loc := parse.Number(v["index"])
|
||||||
|
neFetchlink.NeConfigInstall(neInfo, ptConf.ParamName, fmt.Sprint(loc), v)
|
||||||
|
// 检查是否有array子层
|
||||||
|
for vk, vv := range v {
|
||||||
|
if reflect.TypeOf(vv).Kind() == reflect.Slice {
|
||||||
|
for i, item := range vv.([]any) {
|
||||||
|
data := item.(map[string]any)
|
||||||
|
data["index"] = i
|
||||||
|
neFetchlink.NeConfigInstall(neInfo, ptConf.ParamName, fmt.Sprintf("%v/%s/%v", loc, vk, i), data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user