feat: 网元OAM配置文件读写接口和部分接口参数变更
This commit is contained in:
@@ -204,31 +204,86 @@ func (s *NeInfoController) ConfigFileWrite(c *gin.Context) {
|
|||||||
c.JSON(200, result.Ok(nil))
|
c.JSON(200, result.Ok(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网元端公共配置文件读取
|
// 网元端OAM配置文件读取
|
||||||
//
|
//
|
||||||
// GET /para5GFile
|
// GET /oamFile
|
||||||
func (s *NeInfoController) Para5GFileRead(c *gin.Context) {
|
func (s *NeInfoController) OAMFileRead(c *gin.Context) {
|
||||||
fileType := c.Query("fileType")
|
language := ctx.AcceptLanguage(c)
|
||||||
data := s.neInfoService.NeConfPara5GRead(fileType)
|
var querys struct {
|
||||||
|
NeType string `form:"neType" binding:"required"`
|
||||||
|
NeID string `form:"neId" binding:"required"`
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||||
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := s.neInfoService.NeConfOAMRead(querys.NeType, querys.NeID)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
c.JSON(200, result.OkData(data))
|
c.JSON(200, result.OkData(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网元端公共配置文件写入
|
// 网元端OAM配置文件写入
|
||||||
//
|
//
|
||||||
// PUT /para5GFile
|
// PUT /oamFile
|
||||||
func (s *NeInfoController) Para5GFileWrite(c *gin.Context) {
|
func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
|
||||||
language := ctx.AcceptLanguage(c)
|
language := ctx.AcceptLanguage(c)
|
||||||
var body struct {
|
var body struct {
|
||||||
FileType string `json:"fileType" binding:"oneof='' txt json yaml yml"` // 解析内容数据到对应文件类型
|
NeType string `json:"neType" binding:"required"`
|
||||||
Content any `json:"content" binding:"required"` // 内容
|
NeID string `json:"neId" binding:"required"`
|
||||||
SyncNE []string `json:"syncNe"` // 同步到网元
|
Content map[string]any `json:"content" binding:"required"` // 内容
|
||||||
|
Sync bool `json:"sync"` // 同步到网元
|
||||||
}
|
}
|
||||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.neInfoService.NeConfPara5GWirte(body.FileType, body.Content, body.SyncNE)
|
// 查询网元获取IP
|
||||||
|
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
|
||||||
|
if neInfo.NeId != body.NeID || neInfo.IP == "" {
|
||||||
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := s.neInfoService.NeConfOAMWirte(body.NeType, body.NeID, body.Content, body.Sync)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, result.Ok(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 网元端Para5G配置文件读取
|
||||||
|
//
|
||||||
|
// GET /para5GFile
|
||||||
|
func (s *NeInfoController) Para5GFileRead(c *gin.Context) {
|
||||||
|
data, err := s.neInfoService.NeConfPara5GRead()
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, result.OkData(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 网元端Para5G配置文件写入
|
||||||
|
//
|
||||||
|
// PUT /para5GFile
|
||||||
|
func (s *NeInfoController) Para5GFileWrite(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
|
var body struct {
|
||||||
|
Content map[string]any `json:"content" binding:"required"` // 内容
|
||||||
|
SyncNE []string `json:"syncNe"` // 同步到网元
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||||
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := s.neInfoService.NeConfPara5GWirte(body.Content, body.SyncNE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, result.ErrMsg(err.Error()))
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -67,6 +67,15 @@ func Setup(router *gin.Engine) {
|
|||||||
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neInfo", collectlogs.BUSINESS_TYPE_OTHER)),
|
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neInfo", collectlogs.BUSINESS_TYPE_OTHER)),
|
||||||
controller.NewNeInfo.ConfigFileWrite,
|
controller.NewNeInfo.ConfigFileWrite,
|
||||||
)
|
)
|
||||||
|
neInfoGroup.GET("/oamFile",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
controller.NewNeInfo.OAMFileRead,
|
||||||
|
)
|
||||||
|
neInfoGroup.PUT("/oamFile",
|
||||||
|
middleware.PreAuthorize(nil),
|
||||||
|
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neInfo", collectlogs.BUSINESS_TYPE_OTHER)),
|
||||||
|
controller.NewNeInfo.OAMFileWrite,
|
||||||
|
)
|
||||||
neInfoGroup.GET("/para5GFile",
|
neInfoGroup.GET("/para5GFile",
|
||||||
middleware.PreAuthorize(nil),
|
middleware.PreAuthorize(nil),
|
||||||
controller.NewNeInfo.Para5GFileRead,
|
controller.NewNeInfo.Para5GFileRead,
|
||||||
|
|||||||
@@ -61,11 +61,15 @@ type INeInfo interface {
|
|||||||
// NeConfigFileWirte 网元配置文件写入 content内容 sync同步到网元端
|
// NeConfigFileWirte 网元配置文件写入 content内容 sync同步到网元端
|
||||||
NeConfigFileWirte(neInfo model.NeInfo, filePath, fileType string, content any, sync bool) error
|
NeConfigFileWirte(neInfo model.NeInfo, filePath, fileType string, content any, sync bool) error
|
||||||
|
|
||||||
|
// NeConfOAMRead 网元OAM配置文件读取
|
||||||
|
NeConfOAMRead(neType, neId string) (map[string]any, error)
|
||||||
|
|
||||||
|
// NeConfOAMWirte 网元OAM配置文件写入 content内容 sync同步到网元端
|
||||||
|
NeConfOAMWirte(neType, neId string, content any, sync bool) error
|
||||||
|
|
||||||
// NeConfPara5GRead 网元公共配置文件读取
|
// NeConfPara5GRead 网元公共配置文件读取
|
||||||
//
|
NeConfPara5GRead() (map[string]any, error)
|
||||||
// 返回 string map[string]any
|
|
||||||
NeConfPara5GRead(fileType string) any
|
|
||||||
|
|
||||||
// NeConfPara5GWirte 网元公共配置文件写入 content内容 syncNE同步到网元端NeType@NeId
|
// NeConfPara5GWirte 网元公共配置文件写入 content内容 syncNE同步到网元端NeType@NeId
|
||||||
NeConfPara5GWirte(fileType string, content any, syncNE []string) error
|
NeConfPara5GWirte(content map[string]any, syncNE []string) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -486,10 +486,80 @@ func (r *NeInfoImpl) NeConfigFileWirte(neInfo model.NeInfo, filePath, fileType s
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NeConfOAMRead 网元OAM配置文件读取
|
||||||
|
func (r *NeInfoImpl) NeConfOAMRead(neType, neId string) (map[string]any, error) {
|
||||||
|
neTypeLower := strings.ToLower(neType)
|
||||||
|
// 网管本地路径
|
||||||
|
omcPath := "/usr/local/etc/omc/ne_config"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
omcPath = fmt.Sprintf("C:%s", omcPath)
|
||||||
|
}
|
||||||
|
localFilePath := fmt.Sprintf("%s/%s/%s/%s", omcPath, neTypeLower, neId, "oam_manager.yaml")
|
||||||
|
|
||||||
|
// 读取文件内容
|
||||||
|
bytes, err := os.ReadFile(localFilePath)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warnf("NeConfOAMRead ReadFile => %s", err.Error())
|
||||||
|
return nil, fmt.Errorf("read file error")
|
||||||
|
}
|
||||||
|
content := string(bytes)
|
||||||
|
|
||||||
|
// 序列化Map
|
||||||
|
mapData, err := parse.ConvertConfigToMap("yaml", content)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warnf("NeConfOAMRead ConvertConfigToMap => %s", err.Error())
|
||||||
|
return nil, fmt.Errorf("content convert type error")
|
||||||
|
}
|
||||||
|
return mapData, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NeConfOAMWirte 网元OAM配置文件写入 content内容 sync同步到网元端
|
||||||
|
func (r *NeInfoImpl) NeConfOAMWirte(neType, neId string, content any, sync bool) error {
|
||||||
|
neTypeLower := strings.ToLower(neType)
|
||||||
|
fileName := "oam_manager.yaml"
|
||||||
|
// 网管本地路径
|
||||||
|
omcPath := "/usr/local/etc/omc/ne_config"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
omcPath = fmt.Sprintf("C:%s", omcPath)
|
||||||
|
}
|
||||||
|
localFilePath := fmt.Sprintf("%s/%s/%s/%s", omcPath, neTypeLower, neId, fileName)
|
||||||
|
|
||||||
|
// 写入文件
|
||||||
|
if err := parse.ConvertConfigToFile("yaml", localFilePath, content); err != nil {
|
||||||
|
return fmt.Errorf("please check if the file exists or write permissions")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 同步到网元端
|
||||||
|
if sync {
|
||||||
|
// 网元主机的SSH客户端
|
||||||
|
sshClient, err := r.NeRunSSHclient(neType, neId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer sshClient.Close()
|
||||||
|
// 网元主机的SSH客户端进行文件传输
|
||||||
|
sftpClient, err := sshClient.NewClientSFTP()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer sftpClient.Close()
|
||||||
|
|
||||||
|
// 网元端配置路径
|
||||||
|
neFilePath := fmt.Sprintf("/usr/local/etc/%s/%s", neTypeLower, fileName)
|
||||||
|
neFileDir := filepath.Dir(neFilePath)
|
||||||
|
// 修改网元文件权限
|
||||||
|
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p %s && sudo chmod o+w %s && sudo chmod o+w %s", neFileDir, neFileDir, neFilePath))
|
||||||
|
// 复制到网元进行覆盖
|
||||||
|
if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil {
|
||||||
|
return fmt.Errorf("please check if scp remote copy is allowed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NeConfPara5GRead 网元公共配置文件读取
|
// NeConfPara5GRead 网元公共配置文件读取
|
||||||
//
|
func (r *NeInfoImpl) NeConfPara5GRead() (map[string]any, error) {
|
||||||
// 返回 string map[string]any
|
|
||||||
func (r *NeInfoImpl) NeConfPara5GRead(fileType string) any {
|
|
||||||
// 网管本地路径
|
// 网管本地路径
|
||||||
omcFilePath := "/usr/local/etc/omc/para5G.yaml"
|
omcFilePath := "/usr/local/etc/omc/para5G.yaml"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@@ -499,37 +569,28 @@ func (r *NeInfoImpl) NeConfPara5GRead(fileType string) any {
|
|||||||
bytes, err := os.ReadFile(omcFilePath)
|
bytes, err := os.ReadFile(omcFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("NeConfPara5GRead ReadFile => %s", err.Error())
|
logger.Warnf("NeConfPara5GRead ReadFile => %s", err.Error())
|
||||||
return "read file error"
|
return nil, fmt.Errorf("read file error")
|
||||||
}
|
}
|
||||||
content := string(bytes)
|
content := string(bytes)
|
||||||
if fileType == "" || fileType == "txt" {
|
|
||||||
return content
|
|
||||||
}
|
|
||||||
// 序列化Map
|
// 序列化Map
|
||||||
mapData, err := parse.ConvertConfigToMap(fileType, content)
|
mapData, err := parse.ConvertConfigToMap("yaml", content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("NeConfPara5GRead ConvertConfigToMap => %s", err.Error())
|
logger.Warnf("NeConfPara5GRead ConvertConfigToMap => %s", err.Error())
|
||||||
return "content convert type error"
|
return nil, fmt.Errorf("content convert type error")
|
||||||
}
|
}
|
||||||
return mapData
|
return mapData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeConfPara5GWirte 网元公共配置文件写入 content内容 syncNE同步到网元端NeType@NeId
|
// NeConfPara5GWirte 网元公共配置文件写入 content内容 syncNE同步到网元端NeType@NeId
|
||||||
func (r *NeInfoImpl) NeConfPara5GWirte(fileType string, content any, syncNE []string) error {
|
func (r *NeInfoImpl) NeConfPara5GWirte(content map[string]any, syncNE []string) error {
|
||||||
// 网管本地路径
|
// 网管本地路径
|
||||||
omcFilePath := "/usr/local/etc/omc/para5G.yaml"
|
omcFilePath := "/usr/local/etc/omc/para5G.yaml"
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
omcFilePath = fmt.Sprintf("C:%s", omcFilePath)
|
omcFilePath = fmt.Sprintf("C:%s", omcFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
if err := parse.ConvertConfigToFile("yaml", omcFilePath, content); err != nil {
|
||||||
if fileType == "" || fileType == "txt" {
|
|
||||||
err = parse.ConvertConfigToFile(fileType, omcFilePath, content)
|
|
||||||
}
|
|
||||||
if fileType == "json" || fileType == "yaml" || fileType == "yml" {
|
|
||||||
err = parse.ConvertConfigToFile(fileType, omcFilePath, content)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("please check if the file exists or write permissions")
|
return fmt.Errorf("please check if the file exists or write permissions")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +616,7 @@ func (r *NeInfoImpl) NeConfPara5GWirte(fileType string, content any, syncNE []st
|
|||||||
|
|
||||||
// 网元端配置路径
|
// 网元端配置路径
|
||||||
neFilePath := "/usr/local/etc/conf/para5G.yaml"
|
neFilePath := "/usr/local/etc/conf/para5G.yaml"
|
||||||
neFileDir := filepath.Dir(neFilePath)
|
neFileDir := filepath.ToSlash(filepath.Dir(neFilePath))
|
||||||
// 修改网元文件权限
|
// 修改网元文件权限
|
||||||
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p %s && sudo chmod o+w %s && sudo chmod o+w %s", neFileDir, neFileDir, neFilePath))
|
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p %s && sudo chmod o+w %s && sudo chmod o+w %s", neFileDir, neFileDir, neFilePath))
|
||||||
// 复制到网元进行覆盖
|
// 复制到网元进行覆盖
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func (r *NeVersionImpl) Operate(action string, neVersion model.NeVersion, preinp
|
|||||||
}
|
}
|
||||||
// 网元端配置路径
|
// 网元端配置路径
|
||||||
nePara5GFilePath := "/usr/local/etc/conf/para5G.yaml"
|
nePara5GFilePath := "/usr/local/etc/conf/para5G.yaml"
|
||||||
nePara5GFileDir := filepath.Dir(nePara5GFilePath)
|
nePara5GFileDir := filepath.ToSlash(filepath.Dir(nePara5GFilePath))
|
||||||
// 修改网元文件权限
|
// 修改网元文件权限
|
||||||
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p %s && sudo chmod o+w %s && sudo chmod o+w %s", nePara5GFileDir, nePara5GFileDir, nePara5GFilePath))
|
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p %s && sudo chmod o+w %s && sudo chmod o+w %s", nePara5GFileDir, nePara5GFileDir, nePara5GFilePath))
|
||||||
// 复制到网元进行覆盖
|
// 复制到网元进行覆盖
|
||||||
|
|||||||
Reference in New Issue
Block a user