This commit is contained in:
2024-09-04 11:55:42 +08:00
4 changed files with 109 additions and 21 deletions

View File

@@ -193,7 +193,7 @@ func (s *NeInfoController) OAMFileRead(c *gin.Context) {
return
}
data, err := s.neInfoService.NeConfOAMRead(querys.NeType, querys.NeID)
data, err := s.neInfoService.NeConfOAMReadSync(querys.NeType, querys.NeID)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
@@ -224,7 +224,7 @@ func (s *NeInfoController) OAMFileWrite(c *gin.Context) {
return
}
err := s.neInfoService.NeConfOAMSync(neInfo, body.Content, body.Sync)
err := s.neInfoService.NeConfOAMWirteSync(neInfo, body.Content, body.Sync)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return

View File

@@ -58,11 +58,11 @@ type INeInfo interface {
// num 是网元主机telnet 14100 25200
NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTelnet, error)
// neConfOAMRead 网元OAM配置文件读取
NeConfOAMRead(neType, neId string) (map[string]any, error)
// NeConfOAMReadSync 网元OAM配置文件读取
NeConfOAMReadSync(neType, neId string) (map[string]any, error)
// NeConfOAMSync 网元OAM配置文件生成并同步
NeConfOAMSync(neInfo model.NeInfo, content map[string]any, sync bool) error
// NeConfOAMWirteSync 网元OAM配置文件生成并同步
NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any, sync bool) error
// NeConfPara5GRead 网元公共配置文件读取
NeConfPara5GRead() (map[string]any, error)

View File

@@ -406,13 +406,74 @@ func (r *NeInfoImpl) NeRunTelnetClient(neType, neId string, num int) (*telnet.Co
return telnetClient, nil
}
// NeConfOAMReadSync 网元OAM配置文件读取
func (r *NeInfoImpl) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
oamData, err := r.neConfOAMRead(neType, neId, true)
if err != nil {
return nil, err
}
// UPF和SMF 全小写的key
if _, ok := oamData["httpmanagecfg"]; ok {
content := map[string]any{}
// 网元HTTP服务
// if v, ok := oamData["httpmanagecfg"]; ok {
// item := v.(map[string]any)
// }
// 对网管HTTP配置
if v, ok := oamData["oamconfig"]; ok {
item := v.(map[string]any)
if v, ok := item["iptype"]; ok && v != "" && v != nil {
ipType := v.(string)
if ipType == "ipv6" {
content["omcIP"] = item["ipv6"]
}
if ipType == "ipv4" {
content["omcIP"] = item["ipv4"]
}
}
content["oamEnable"] = item["enable"]
content["oamPort"] = item["port"]
}
// 对网管SNMP配置
if v, ok := oamData["snmpconfig"]; ok {
item := v.(map[string]any)
content["snmpEnable"] = item["enable"]
content["snmpPort"] = item["port"]
}
// 对网管KPI上报配置
if v, ok := oamData["kpiconfig"]; ok {
item := v.(map[string]any)
content["kpiEnable"] = item["enable"]
content["kpiTimer"] = item["timer"]
}
oamData := r.neConfOAMData()
r.neConfOAMWirte(neType, neId, oamData, false)
r.NeConfOAMWirteSync(model.NeInfo{
NeType: neType,
NeId: neId,
}, content, false)
return r.neConfOAMRead(neType, neId, false)
}
// NSSF和MME 配置KPIconfig名不一致时
if v, ok := oamData["KPIconfig"]; ok && v != nil {
item := v.(map[string]any)
oamData["kpiConfig"] = item
delete(oamData, "KPIconfig")
r.neConfOAMWirte(neType, neId, oamData, false)
}
return oamData, nil
}
// neConfOAMData 网元OAM配置文件默认格式数据
func (r *NeInfoImpl) neConfOAMData() map[string]any {
return map[string]any{
"httpManageCfg": map[string]any{
"ipType": "ipv4",
// 必改
"ipv4": "172.60.5.2",
"ipv4": "172.16.5.1", // 必改
"ipv6": "",
"port": 33030,
"scheme": "http",
@@ -420,11 +481,12 @@ func (r *NeInfoImpl) neConfOAMData() map[string]any {
"oamConfig": map[string]any{
"enable": true,
"ipType": "ipv4",
"ipv4": "172.60.5.1", // 必改
"ipv4": "172.16.5.100", // 必改
"ipv6": "",
"port": 33030,
"scheme": "http",
"neConfig": map[string]any{ // 必改
// 必改
"neConfig": map[string]any{
"neId": "001",
"rmUid": "4400HX1XXX001",
"neName": "XXX_001",
@@ -437,7 +499,7 @@ func (r *NeInfoImpl) neConfOAMData() map[string]any {
"snmpConfig": map[string]any{
"enable": false,
"ipType": "ipv4",
"ipv4": "172.60.5.2", // 必改
"ipv4": "172.16.5.1", // 必改
"ipv6": "",
"port": 4957,
},
@@ -449,15 +511,39 @@ func (r *NeInfoImpl) neConfOAMData() map[string]any {
}
}
// neConfOAMRead 网元OAM配置文件读取
func (r *NeInfoImpl) NeConfOAMRead(neType, neId string) (map[string]any, error) {
// neConfOAMRead 网元OAM配置文件读取 sync从网元端同步到本地
func (r *NeInfoImpl) neConfOAMRead(neType, neId string, sync bool) (map[string]any, error) {
neTypeLower := strings.ToLower(neType)
fileName := "oam_manager.yaml"
// 网管本地路径
omcPath := "/usr/local/etc/omc/ne_config"
localFilePath := fmt.Sprintf("/usr/local/etc/omc/ne_config/%s/%s/%s", neTypeLower, neId, fileName)
if runtime.GOOS == "windows" {
omcPath = fmt.Sprintf("C:%s", omcPath)
localFilePath = fmt.Sprintf("C:%s", localFilePath)
}
// 从网元端同步到本地
if sync {
// 网元主机的SSH客户端
sshClient, err := NewNeInfoImpl.NeRunSSHClient(neType, neId)
if err != nil {
return nil, fmt.Errorf("ne info ssh client err")
}
defer sshClient.Close()
// 网元主机的SSH客户端进行文件传输
sftpClient, err := sshClient.NewClientSFTP()
if err != nil {
return nil, fmt.Errorf("ne info sftp client err")
}
defer sftpClient.Close()
// 网元端文件路径
neFilePath := fmt.Sprintf("/usr/local/etc/%s/%s", neTypeLower, fileName)
// 修改网元文件权限
sshClient.RunCMD(fmt.Sprintf("sudo touch %s && sudo chmod o+rw %s", neFilePath, neFilePath))
// 网元端复制到本地
if err = sftpClient.CopyFileRemoteToLocal(neFilePath, localFilePath); err != nil {
return nil, fmt.Errorf("copy oam config err")
}
}
localFilePath := fmt.Sprintf("%s/%s/%s/%s", omcPath, neTypeLower, neId, "oam_manager.yaml")
// 读取文件内容
bytes, err := os.ReadFile(localFilePath)
@@ -515,7 +601,7 @@ func (r *NeInfoImpl) neConfOAMWirte(neType, neId string, content any, sync bool)
neFilePath := fmt.Sprintf("/usr/local/etc/%s/%s", neTypeLower, fileName)
neFileDir := filepath.ToSlash(filepath.Dir(neFilePath))
// 修改网元文件权限
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p %s && sudo chmod 775 %s && sudo touch %s && sudo chmod o+w %s", neFileDir, neFileDir, neFilePath, neFilePath))
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p %s && sudo chmod 775 %s && sudo touch %s && sudo chmod o+rw %s", neFileDir, neFileDir, neFilePath, neFilePath))
// 复制到网元进行覆盖
if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil {
return fmt.Errorf("please check if scp remote copy is allowed")
@@ -525,9 +611,9 @@ func (r *NeInfoImpl) neConfOAMWirte(neType, neId string, content any, sync bool)
return nil
}
// NeConfOAMSync 网元OAM配置文件生成并同步
func (r *NeInfoImpl) NeConfOAMSync(neInfo model.NeInfo, content map[string]any, sync bool) error {
oamData, err := r.NeConfOAMRead(neInfo.NeType, neInfo.NeId)
// NeConfOAMWirteSync 网元OAM配置文件生成并同步
func (r *NeInfoImpl) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any, sync bool) error {
oamData, err := r.neConfOAMRead(neInfo.NeType, neInfo.NeId, false)
if oamData == nil || err != nil {
return fmt.Errorf("error read OAM file info")
}
@@ -615,6 +701,8 @@ func (r *NeInfoImpl) NeConfOAMSync(neInfo model.NeInfo, content map[string]any,
item := v.(map[string]any)
if neInfo.NeType == "UPF" {
item["timer"] = 5
} else {
item["timer"] = 60
}
if kpiEnable, ok := content["kpiEnable"]; ok && kpiEnable != nil {

View File

@@ -612,7 +612,7 @@ func (r *NeVersionImpl) operateDome(action string, neVersion model.NeVersion) er
return fmt.Errorf("error found neinfo")
}
// ========= 网元OAM配置文件 start ==========
if err := NewNeInfoImpl.NeConfOAMSync(neInfo, nil, true); err != nil {
if err := NewNeInfoImpl.NeConfOAMWirteSync(neInfo, nil, true); err != nil {
return fmt.Errorf("error wirte OAM file info")
}
// ========= 网元OAM配置文件 end ===========