feat: 网元直连补充参数配置接口管理
This commit is contained in:
@@ -68,3 +68,99 @@ func NeConfigInfo(neInfo model.NeInfo, paramName string) (map[string]any, error)
|
||||
}
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// NeConfigInfoEdit 网元配置更新
|
||||
func NeConfigInfoEdit(neInfo model.NeInfo, paramName string, data map[string]any) (map[string]any, error) {
|
||||
// array需要层级
|
||||
loc := ""
|
||||
if v, ok := data["index"]; ok {
|
||||
loc = fmt.Sprintf("?loc=%v", v)
|
||||
}
|
||||
// 网元参数配置新增(array)
|
||||
neUrl := fmt.Sprintf("http://%s:%d/api/rest/systemManagement/v1/elementType/%s/objectType/config/%s%s", neInfo.IP, neInfo.Port, strings.ToLower(neInfo.NeType), paramName, loc)
|
||||
resBytes, err := fetch.PutJSON(neUrl, data, nil)
|
||||
var resData map[string]any
|
||||
if err != nil {
|
||||
status := err.Error()
|
||||
logger.Warnf("NeConfigInfoEdit %s Put \"%s\"", status, neUrl)
|
||||
if strings.HasPrefix(status, "201") || strings.HasPrefix(status, "204") {
|
||||
return resData, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 200 成功无数据时
|
||||
if len(resBytes) == 0 {
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Warnf("NeConfigInfoEdit Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// NeConfigInfoAdd 网元配置新增 array
|
||||
func NeConfigInfoAdd(neInfo model.NeInfo, paramName string, data map[string]any) (map[string]any, error) {
|
||||
loc, locOk := data["index"] // 层级 index
|
||||
if !locOk {
|
||||
return nil, fmt.Errorf("data not index")
|
||||
}
|
||||
// 网元参数配置新增(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)
|
||||
resBytes, err := fetch.PostJSON(neUrl, data, nil)
|
||||
var resData map[string]any
|
||||
if err != nil {
|
||||
status := err.Error()
|
||||
logger.Warnf("NeConfigInfoAdd %s Post \"%s\"", status, neUrl)
|
||||
if strings.HasPrefix(status, "201") || strings.HasPrefix(status, "204") {
|
||||
return resData, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 200 成功无数据时
|
||||
if len(resBytes) == 0 {
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Warnf("NeConfigInfoAdd Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// NeConfigInfoDel 网元配置删除 array
|
||||
func NeConfigInfoDel(neInfo model.NeInfo, paramName, index string) (map[string]any, error) {
|
||||
// 网元参数配置删除(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, index)
|
||||
resBytes, err := fetch.Delete(neUrl, nil)
|
||||
var resData map[string]any
|
||||
if err != nil {
|
||||
status := err.Error()
|
||||
logger.Warnf("NeConfigInfoDel %s Delete \"%s\"", status, neUrl)
|
||||
if strings.HasPrefix(status, "201") || strings.HasPrefix(status, "204") {
|
||||
return resData, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 200 成功无数据时
|
||||
if len(resBytes) == 0 {
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
// 序列化结果
|
||||
err = json.Unmarshal(resBytes, &resData)
|
||||
if err != nil {
|
||||
logger.Warnf("NeConfigInfoDel Unmarshal %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return resData, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user