ref: v3变更,,同步v2.2508.4
This commit is contained in:
@@ -35,10 +35,11 @@ type NeInfo struct {
|
||||
Para5GData map[string]string
|
||||
}
|
||||
|
||||
// FindByNeTypeAndNeID 通过ne_type和ne_id查询网元信息
|
||||
func (r NeInfo) FindByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
// FindByCoreUidAndNeUid 通过core_uid和ne_uid查询网元信息
|
||||
// coreUid 为*时,根据neUid查询
|
||||
func (r NeInfo) FindByCoreUidAndNeUid(coreUid string, neUid string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
key := fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, strings.ToUpper(neType), neID)
|
||||
key := fmt.Sprintf("%s:%s:*:%s", constants.CACHE_NE_INFO, coreUid, neUid)
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
err := json.Unmarshal([]byte(jsonStr), &neInfo)
|
||||
@@ -46,8 +47,8 @@ func (r NeInfo) FindByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
neInfo = model.NeInfo{}
|
||||
}
|
||||
} else {
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||
if neInfo.ID != 0 && neInfo.NeId == neID {
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByCoreUidAndNeUid(coreUid, neUid)
|
||||
if neInfo.CoreUID == coreUid && neInfo.NeUID == neUid {
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(neInfo)
|
||||
redis.Set("", key, string(values), 0)
|
||||
@@ -56,36 +57,27 @@ func (r NeInfo) FindByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// RefreshByNeTypeAndNeID 通过ne_type和ne_id刷新redis中的缓存
|
||||
func (r NeInfo) RefreshByNeTypeAndNeID(neType, neID string) model.NeInfo {
|
||||
// RefreshByCoreUidAndNeUid 通过core_id和ne_uid刷新缓存
|
||||
func (r NeInfo) RefreshByCoreUidAndNeUid(coreuid string, neUid string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
key := fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, strings.ToUpper(neType), neID)
|
||||
if coreuid == "*" || coreuid == "" {
|
||||
return neInfo
|
||||
}
|
||||
key := fmt.Sprintf("%s:%s:*:%s", constants.CACHE_NE_INFO, coreuid, neUid)
|
||||
redis.Del("", key)
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByNeTypeAndNeID(neType, neID)
|
||||
if neInfo.ID != 0 && neInfo.NeId == neID {
|
||||
neInfo = r.neInfoRepository.SelectNeInfoByCoreUidAndNeUid(coreuid, neUid)
|
||||
if neInfo.CoreUID == coreuid && neInfo.NeUID == neUid {
|
||||
values, _ := json.Marshal(neInfo)
|
||||
redis.Set("", key, string(values), 0)
|
||||
}
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// ClearNeCacheByNeType 清除网元类型缓存
|
||||
func (r NeInfo) ClearNeCacheByNeType(neType string) bool {
|
||||
key := fmt.Sprintf("%s:*", constants.CACHE_NE_INFO)
|
||||
if neType != "*" {
|
||||
key = fmt.Sprintf("%s:%s*", constants.CACHE_NE_INFO, neType)
|
||||
}
|
||||
keys, err := redis.GetKeys("", key)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return redis.DelKeys("", keys) == nil
|
||||
}
|
||||
|
||||
// FindByNeType 通过ne_type查询网元信息
|
||||
func (r NeInfo) FindByNeType(neType string) []model.NeInfo {
|
||||
// FindByCoreUidAndNeType 通过core_uid和ne_type查询网元信息
|
||||
// coreUid 为*时,根据neType查询
|
||||
func (r NeInfo) FindByCoreUidAndNeType(coreUid string, neType string) []model.NeInfo {
|
||||
neInfo := make([]model.NeInfo, 0)
|
||||
key := fmt.Sprintf("%s:%s:*", constants.CACHE_NE_INFO, strings.ToUpper(neType))
|
||||
key := fmt.Sprintf("%s:%s:%s:*", constants.CACHE_NE_INFO, coreUid, neType)
|
||||
cacheKeys, _ := redis.GetKeys("", key)
|
||||
if len(cacheKeys) > 0 {
|
||||
for _, key := range cacheKeys {
|
||||
@@ -98,9 +90,9 @@ func (r NeInfo) FindByNeType(neType string) []model.NeInfo {
|
||||
}
|
||||
return neInfo
|
||||
} else {
|
||||
neInfo = r.neInfoRepository.SelectList(model.NeInfo{NeType: neType})
|
||||
neInfo = r.neInfoRepository.SelectList(model.NeInfo{CoreUID: coreUid, NeType: neType})
|
||||
for _, v := range neInfo {
|
||||
key := fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, strings.ToUpper(v.NeType), v.NeId)
|
||||
key := fmt.Sprintf("%s:%s:%s:%s", constants.CACHE_NE_INFO, v.CoreUID, v.NeType, v.NeUID)
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values), 0)
|
||||
@@ -109,35 +101,33 @@ func (r NeInfo) FindByNeType(neType string) []model.NeInfo {
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// FindByRmuid 通过rmUID查询网元信息
|
||||
func (r NeInfo) FindByRmuid(rmUid string) model.NeInfo {
|
||||
var neInfo model.NeInfo
|
||||
cacheKeys, _ := redis.GetKeys("", constants.CACHE_NE_INFO+":*")
|
||||
if len(cacheKeys) > 0 {
|
||||
for _, key := range cacheKeys {
|
||||
var v model.NeInfo
|
||||
jsonStr, _ := redis.Get("", key)
|
||||
if len(jsonStr) > 7 {
|
||||
json.Unmarshal([]byte(jsonStr), &v)
|
||||
}
|
||||
if v.RmUID == rmUid {
|
||||
neInfo = v
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
neInfos := r.Find(neInfo, false, false)
|
||||
for _, v := range neInfos {
|
||||
key := fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, strings.ToUpper(v.NeType), v.NeId)
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values), 0)
|
||||
if v.RmUID == rmUid {
|
||||
neInfo = v
|
||||
}
|
||||
}
|
||||
// ClearNeCacheByCoreUidOrNeUid 清除核心网下网元信息缓存
|
||||
// coreUid 核心网唯一标识 *表示清除所有
|
||||
func (r NeInfo) ClearNeCacheByCoreUid(coreUid string) bool {
|
||||
key := fmt.Sprintf("%s:*", constants.CACHE_NE_INFO)
|
||||
if coreUid != "*" {
|
||||
key = fmt.Sprintf("%s:%s:*", constants.CACHE_NE_INFO, coreUid)
|
||||
}
|
||||
keys, err := redis.GetKeys("", key)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return redis.DelKeys("", keys) == nil
|
||||
}
|
||||
|
||||
// RefreshNeCacheByCoreUid 刷新核心网下网元信息缓存
|
||||
// coreUid 核心网唯一标识 *表示所有
|
||||
func (r NeInfo) RefreshNeCacheByCoreUid(coreUid string) {
|
||||
if coreUid == "*" {
|
||||
coreUid = ""
|
||||
}
|
||||
neInfos := r.Find(model.NeInfo{CoreUID: coreUid}, false, false)
|
||||
for _, v := range neInfos {
|
||||
key := fmt.Sprintf("%s:%s:%s:%s", constants.CACHE_NE_INFO, v.CoreUID, v.NeType, v.NeUID)
|
||||
redis.Del("", key)
|
||||
values, _ := json.Marshal(v)
|
||||
redis.Set("", key, string(values), 0)
|
||||
}
|
||||
return neInfo
|
||||
}
|
||||
|
||||
// FindByPage 根据条件分页查询
|
||||
@@ -252,6 +242,27 @@ func (r NeInfo) FindById(id int64, bandHost bool) model.NeInfo {
|
||||
|
||||
// Insert 新增信息
|
||||
func (r NeInfo) Insert(neInfo model.NeInfo) int64 {
|
||||
if neInfo.CoreUID == "" {
|
||||
return 0
|
||||
}
|
||||
neInfo.NeUID = strings.ToUpper(generate.Code(8))
|
||||
|
||||
// 获取网元状态是否正常
|
||||
serverState, err := neFetchlink.NeState(neInfo)
|
||||
if err != nil {
|
||||
neInfo.Status = 0
|
||||
} else {
|
||||
// 网元状态设置为在线
|
||||
neInfo.Status = 1
|
||||
if parse.Boolean(serverState["standby"]) {
|
||||
neInfo.Status = 3
|
||||
}
|
||||
// 下发网管配置信息给网元
|
||||
if _, err = neFetchlink.NeConfigOMC(neInfo); err != nil {
|
||||
neInfo.Status = 2
|
||||
}
|
||||
}
|
||||
|
||||
// 主机信息新增
|
||||
if neInfo.Hosts != nil {
|
||||
uuid := generate.Code(4)
|
||||
@@ -270,20 +281,75 @@ func (r NeInfo) Insert(neInfo model.NeInfo) int64 {
|
||||
|
||||
insertId := r.neInfoRepository.Insert(neInfo)
|
||||
if insertId > 0 {
|
||||
// 刷新缓存
|
||||
r.RefreshByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
// 新增Version信息
|
||||
neVersion := model.NeVersion{
|
||||
CoreUID: neInfo.CoreUID,
|
||||
NeUID: neInfo.NeUID,
|
||||
NeType: neInfo.NeType,
|
||||
CreateBy: neInfo.CreateBy,
|
||||
}
|
||||
if v, ok := serverState["version"]; ok && v != nil {
|
||||
neVersion.Name = "-"
|
||||
neVersion.Path = "-"
|
||||
neVersion.Version = fmt.Sprint(v)
|
||||
}
|
||||
NewNeVersion.Insert(neVersion)
|
||||
|
||||
// 新增License信息
|
||||
neLicense := model.NeLicense{
|
||||
CoreUID: neInfo.CoreUID,
|
||||
NeUID: neInfo.NeUID,
|
||||
NeType: neInfo.NeType,
|
||||
CreateBy: neInfo.CreateBy,
|
||||
}
|
||||
if v, ok := serverState["sn"]; ok && v != nil {
|
||||
neLicense.SerialNum = fmt.Sprint(v)
|
||||
}
|
||||
if v, ok := serverState["expire"]; ok && v != nil {
|
||||
neLicense.ExpiryDate = fmt.Sprint(v)
|
||||
neLicense.Status = "1"
|
||||
}
|
||||
if v, ok := serverState["ueNumber"]; ok && v != nil {
|
||||
neLicense.UeNumber = parse.Number(v)
|
||||
}
|
||||
if v, ok := serverState["nbNumber"]; ok && v != nil {
|
||||
neLicense.NbNumber = parse.Number(v)
|
||||
}
|
||||
NewNeLicense.Insert(neLicense)
|
||||
|
||||
r.RefreshByCoreUidAndNeUid(neInfo.CoreUID, neInfo.NeUID) // 刷新缓存
|
||||
}
|
||||
return insertId
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r NeInfo) Update(neInfo model.NeInfo) int64 {
|
||||
// 获取网元状态是否正常
|
||||
serverState, err := neFetchlink.NeState(neInfo)
|
||||
if err != nil {
|
||||
neInfo.Status = 0
|
||||
} else {
|
||||
// 网元状态设置为在线
|
||||
neInfo.Status = 1
|
||||
if parse.Boolean(serverState["standby"]) {
|
||||
neInfo.Status = 3
|
||||
}
|
||||
// 下发网管配置信息给网元
|
||||
if _, err = neFetchlink.NeConfigOMC(neInfo); err != nil {
|
||||
neInfo.Status = 2
|
||||
}
|
||||
}
|
||||
|
||||
// 主机信息更新
|
||||
if neInfo.Hosts != nil {
|
||||
if neInfo.HostIDs != "" && len(neInfo.Hosts) > 0 {
|
||||
hostIDs := strings.Split(neInfo.HostIDs, ",")
|
||||
for index, id := range hostIDs {
|
||||
neInfo.Hosts[index].ID = parse.Number(id)
|
||||
}
|
||||
uuid := generate.Code(4)
|
||||
for _, host := range neInfo.Hosts {
|
||||
if host.ID != 0 {
|
||||
host.Title = fmt.Sprintf("%s_%d_%s", neInfo.NeName, host.Port, uuid)
|
||||
host.Title = fmt.Sprintf("%s_%d_%s", neInfo.NeType, host.Port, uuid)
|
||||
host.GroupID = "1"
|
||||
host.UpdateBy = neInfo.UpdateBy
|
||||
r.neHostService.Update(host)
|
||||
@@ -293,73 +359,99 @@ func (r NeInfo) Update(neInfo model.NeInfo) int64 {
|
||||
|
||||
num := r.neInfoRepository.Update(neInfo)
|
||||
if num > 0 {
|
||||
// 刷新缓存
|
||||
r.RefreshByNeTypeAndNeID(neInfo.NeType, neInfo.NeId)
|
||||
// 版本信息更新
|
||||
neVersion := NewNeVersion.FindByCoreUidAndNeUid(neInfo.CoreUID, neInfo.NeUID)
|
||||
if neVersion.ID != 0 {
|
||||
if neVersion.NeType != neInfo.NeType {
|
||||
neVersion.NeType = neInfo.NeType
|
||||
}
|
||||
if v, ok := serverState["version"]; ok && v != neVersion.Version {
|
||||
neVersion.Name = "-"
|
||||
neVersion.Path = "-"
|
||||
neVersion.Version = fmt.Sprint(v)
|
||||
}
|
||||
neVersion.UpdateBy = neInfo.UpdateBy
|
||||
NewNeVersion.Update(neVersion)
|
||||
}
|
||||
|
||||
// License信息更新
|
||||
neLicense := NewNeLicense.FindByCoreUidAndNeUid(neInfo.CoreUID, neInfo.NeUID)
|
||||
if neLicense.ID != 0 {
|
||||
if neLicense.NeType != neInfo.NeType {
|
||||
neLicense.NeType = neInfo.NeType
|
||||
}
|
||||
if v, ok := serverState["sn"]; ok && v != nil {
|
||||
neLicense.SerialNum = fmt.Sprint(v)
|
||||
}
|
||||
if v, ok := serverState["expire"]; ok && v != nil {
|
||||
neLicense.ExpiryDate = fmt.Sprint(v)
|
||||
neLicense.Status = "1"
|
||||
}
|
||||
if v, ok := serverState["ueNumber"]; ok && v != nil {
|
||||
neLicense.UeNumber = parse.Number(v)
|
||||
}
|
||||
if v, ok := serverState["nbNumber"]; ok && v != nil {
|
||||
neLicense.NbNumber = parse.Number(v)
|
||||
}
|
||||
neLicense.UpdateBy = neInfo.UpdateBy
|
||||
NewNeLicense.Update(neLicense)
|
||||
}
|
||||
|
||||
r.RefreshByCoreUidAndNeUid(neInfo.CoreUID, neInfo.NeUID) // 刷新缓存
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除信息
|
||||
func (r NeInfo) DeleteByIds(ids []int64) (int64, error) {
|
||||
func (r NeInfo) DeleteById(id int64, coreUid, neUid string) (int64, error) {
|
||||
// 检查是否存在
|
||||
infos := r.neInfoRepository.SelectByIds(ids)
|
||||
if len(infos) <= 0 {
|
||||
return 0, fmt.Errorf("neHostCmd.noData")
|
||||
arr := r.neInfoRepository.SelectByIds([]int64{id})
|
||||
if len(arr) != 1 {
|
||||
return 0, fmt.Errorf("not match id")
|
||||
}
|
||||
|
||||
if len(infos) == len(ids) {
|
||||
for _, v := range infos {
|
||||
// 主机信息删除
|
||||
if v.HostIDs != "" {
|
||||
hostIds := make([]int64, 0)
|
||||
arr := strings.Split(v.HostIDs, ",")
|
||||
for _, hostId := range arr {
|
||||
hostIds = append(hostIds, parse.Number(hostId))
|
||||
}
|
||||
r.neHostService.DeleteByIds(hostIds, false)
|
||||
}
|
||||
// 删除License
|
||||
neLicense := NewNeLicense.FindByNeTypeAndNeID(v.NeType, v.NeId)
|
||||
if neLicense.NeId == v.NeId {
|
||||
NewNeLicense.DeleteByIds([]int64{neLicense.ID})
|
||||
}
|
||||
// 删除Version
|
||||
neVersion := NewNeVersion.FindByNeTypeAndNeID(v.NeType, v.NeId)
|
||||
if neVersion.NeId == v.NeId {
|
||||
NewNeVersion.DeleteByIds([]int64{neVersion.ID})
|
||||
}
|
||||
// 缓存信息删除
|
||||
redis.Del("", fmt.Sprintf("%s:%s:%s", constants.CACHE_NE_INFO, v.NeType, v.NeId))
|
||||
for _, v := range arr {
|
||||
if v.CoreUID != coreUid || v.NeUID != neUid {
|
||||
return 0, fmt.Errorf("data not match, id: %d", v.ID)
|
||||
}
|
||||
rows := r.neInfoRepository.DeleteByIds(ids)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// CheckUniqueNeTypeAndNeId 校验同类型下标识是否唯一
|
||||
func (r NeInfo) CheckUniqueNeTypeAndNeId(neType, neId string, id int64) bool {
|
||||
uniqueId := r.neInfoRepository.CheckUniqueNeTypeAndNeId(model.NeInfo{
|
||||
NeType: neType,
|
||||
NeId: neId,
|
||||
})
|
||||
if uniqueId == id {
|
||||
return true
|
||||
for _, v := range arr {
|
||||
// 主机信息删除
|
||||
if v.HostIDs != "" {
|
||||
hostIds := make([]int64, 0)
|
||||
arr := strings.Split(v.HostIDs, ",")
|
||||
for _, hostId := range arr {
|
||||
hostIds = append(hostIds, parse.Number(hostId))
|
||||
}
|
||||
r.neHostService.DeleteByIds(hostIds, false)
|
||||
}
|
||||
// 删除License
|
||||
neLicense := NewNeLicense.FindByCoreUidAndNeUid(v.CoreUID, v.NeUID)
|
||||
if neLicense.CoreUID == v.CoreUID && neLicense.NeUID == v.NeUID {
|
||||
NewNeLicense.DeleteByIds([]int64{neLicense.ID})
|
||||
}
|
||||
// 删除Version
|
||||
neVersion := NewNeVersion.FindByCoreUidAndNeUid(v.CoreUID, v.NeUID)
|
||||
if neVersion.CoreUID == v.CoreUID && neVersion.NeUID == v.NeUID {
|
||||
NewNeVersion.DeleteByIds([]int64{neVersion.ID})
|
||||
}
|
||||
// 缓存信息删除
|
||||
redis.Del("", fmt.Sprintf("%s:%s:%s:%s", constants.CACHE_NE_INFO, v.CoreUID, v.NeType, v.NeUID))
|
||||
}
|
||||
return uniqueId == 0
|
||||
rows := r.neInfoRepository.DeleteByIds([]int64{id})
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
// NeRunSSHClient 网元主机的SSH客户端-为创建相关连接,注意结束后 Close()
|
||||
func (r NeInfo) NeRunSSHClient(neType, neId string) (*ssh.ConnSSH, error) {
|
||||
neInfo := r.FindByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId {
|
||||
logger.Errorf("NeRunSSHClient NeType:%s NeID:%s not found", neType, neId)
|
||||
func (r NeInfo) NeRunSSHClient(coreUid, neUid string) (*ssh.ConnSSH, error) {
|
||||
neInfo := r.FindByCoreUidAndNeUid(coreUid, neUid)
|
||||
if neInfo.CoreUID != coreUid || neInfo.NeUID != neUid {
|
||||
logger.Errorf("NeRunSSHClient CoreUID:%s or NeUID:%s not found", coreUid, neUid)
|
||||
return nil, fmt.Errorf("neinfo not found")
|
||||
}
|
||||
// 取主机信息
|
||||
if neInfo.HostIDs == "" {
|
||||
logger.Errorf("NeRunSSHClient NeType:%s NeID:%s hostId not found", neType, neId)
|
||||
logger.Errorf("NeRunSSHClient CoreUID:%s or NeUID:%s hostId not found", coreUid, neUid)
|
||||
return nil, fmt.Errorf("neinfo hostId not found")
|
||||
}
|
||||
hostIds := strings.Split(neInfo.HostIDs, ",")
|
||||
@@ -395,15 +487,15 @@ func (r NeInfo) NeRunSSHClient(neType, neId string) (*ssh.ConnSSH, error) {
|
||||
}
|
||||
|
||||
// NeRunSSHCmd 网元主机的SSH客户端发送cmd命令
|
||||
func (r NeInfo) NeRunSSHCmd(neType, neId, cmd string) (string, error) {
|
||||
sshClient, err := r.NeRunSSHClient(neType, neId)
|
||||
func (r NeInfo) NeRunSSHCmd(coreUid, neUid string, cmdStr string) (string, error) {
|
||||
sshClient, err := r.NeRunSSHClient(coreUid, neUid)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer sshClient.Close()
|
||||
|
||||
// 执行命令
|
||||
output, err := sshClient.RunCMD(cmd)
|
||||
output, err := sshClient.RunCMD(cmdStr)
|
||||
if err != nil {
|
||||
logger.Errorf("NeRunSSHCmd RunCMD %s err => %s", output, err.Error())
|
||||
return "", fmt.Errorf("neinfo ssh run cmd err")
|
||||
@@ -413,15 +505,15 @@ func (r NeInfo) NeRunSSHCmd(neType, neId, cmd string) (string, error) {
|
||||
|
||||
// NeRunTelnetClient 网元主机的Telnet客户端-为创建相关连接,注意结束后 Close()
|
||||
// num 是网元主机telnet 1:4100 2:5200(UPF标准版)
|
||||
func (r NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTelnet, error) {
|
||||
neInfo := r.FindByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId {
|
||||
logger.Errorf("NeRunTelnetClient NeType:%s NeID:%s not found", neType, neId)
|
||||
func (r NeInfo) NeRunTelnetClient(coreUid, neUid string, num int) (*telnet.ConnTelnet, error) {
|
||||
neInfo := r.FindByCoreUidAndNeUid(coreUid, neUid)
|
||||
if neInfo.CoreUID != coreUid || neInfo.NeUID != neUid {
|
||||
logger.Errorf("NeRunSSHClient CoreUID:%s or NeUID:%s not found", coreUid, neUid)
|
||||
return nil, fmt.Errorf("neinfo not found")
|
||||
}
|
||||
// 取主机信息
|
||||
if neInfo.HostIDs == "" {
|
||||
logger.Errorf("NeRunTelnetClient NeType:%s NeID:%s hostId not found", neType, neId)
|
||||
logger.Errorf("NeRunTelnetClient CoreUID:%s or NeUID:%s hostId not found", coreUid, neUid)
|
||||
return nil, fmt.Errorf("neinfo hostId not found")
|
||||
}
|
||||
hostIds := strings.Split(neInfo.HostIDs, ",")
|
||||
@@ -449,15 +541,15 @@ func (r NeInfo) NeRunTelnetClient(neType, neId string, num int) (*telnet.ConnTel
|
||||
|
||||
// NeRunRedisClient 网元主机的Redis客户端-为创建相关连接,注意结束后 Close()
|
||||
// 暂时只有UDM有Redis配置项
|
||||
func (r NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error) {
|
||||
neInfo := r.FindByNeTypeAndNeID(neType, neId)
|
||||
if neInfo.NeId != neId {
|
||||
logger.Errorf("NeRunRedisClient NeType:%s NeID:%s not found", neType, neId)
|
||||
func (r NeInfo) NeRunRedisClient(coreUid, neUid string) (*redis.ConnRedis, error) {
|
||||
neInfo := r.FindByCoreUidAndNeUid(coreUid, neUid)
|
||||
if neInfo.CoreUID != coreUid || neInfo.NeUID != neUid {
|
||||
logger.Errorf("NeRunRedisClient CoreUid:%s NeUid:%s not found", coreUid, neUid)
|
||||
return nil, fmt.Errorf("neinfo not found")
|
||||
}
|
||||
// 取主机信息
|
||||
if neInfo.HostIDs == "" {
|
||||
logger.Errorf("NeRunRedisClient NeType:%s NeID:%s hostId not found", neType, neId)
|
||||
logger.Errorf("NeRunRedisClient CoreUid:%s NeUid:%s hostId not found", coreUid, neUid)
|
||||
return nil, fmt.Errorf("neinfo hostId not found")
|
||||
}
|
||||
hostIds := strings.Split(neInfo.HostIDs, ",")
|
||||
@@ -484,8 +576,14 @@ func (r NeInfo) NeRunRedisClient(neType, neId string) (*redis.ConnRedis, error)
|
||||
}
|
||||
|
||||
// NeConfOAMReadSync 网元OAM配置文件读取
|
||||
func (r NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
|
||||
oamData, err := r.neConfOAMRead(neType, neId, true)
|
||||
func (r NeInfo) NeConfOAMReadSync(coreUid, neUid string) (map[string]any, error) {
|
||||
neInfo := r.FindByCoreUidAndNeUid(coreUid, neUid)
|
||||
if neInfo.CoreUID != coreUid || neInfo.NeUID != neUid {
|
||||
logger.Errorf("NeRunRedisClient CoreUid:%s NeUid:%s not found", coreUid, neUid)
|
||||
return nil, fmt.Errorf("neinfo not found")
|
||||
}
|
||||
|
||||
oamData, err := r.neConfOAMRead(neInfo, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -500,7 +598,7 @@ func (r NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
|
||||
}
|
||||
oamData["httpManageCfg"] = item
|
||||
delete(oamData, "httpmanagecfg")
|
||||
r.neConfOAMWirte(neType, neId, oamData, false)
|
||||
r.neConfOAMWirte(neInfo, oamData, false)
|
||||
}
|
||||
// 对网管HTTP配置
|
||||
if v, ok := oamData["oamconfig"]; ok && v != nil {
|
||||
@@ -515,7 +613,7 @@ func (r NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
|
||||
}
|
||||
oamData["oamConfig"] = item
|
||||
delete(oamData, "oamconfig")
|
||||
r.neConfOAMWirte(neType, neId, oamData, false)
|
||||
r.neConfOAMWirte(neInfo, oamData, false)
|
||||
}
|
||||
// 对网管SNMP配置
|
||||
if v, ok := oamData["snmpconfig"]; ok && v != nil {
|
||||
@@ -526,14 +624,14 @@ func (r NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
|
||||
}
|
||||
oamData["snmpConfig"] = item
|
||||
delete(oamData, "snmpconfig")
|
||||
r.neConfOAMWirte(neType, neId, oamData, false)
|
||||
r.neConfOAMWirte(neInfo, oamData, false)
|
||||
}
|
||||
// 对网管KPI上报配置
|
||||
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)
|
||||
r.neConfOAMWirte(neInfo, oamData, false)
|
||||
}
|
||||
|
||||
// NSSF和MME 配置KPIconfig名不一致时
|
||||
@@ -541,7 +639,7 @@ func (r NeInfo) NeConfOAMReadSync(neType, neId string) (map[string]any, error) {
|
||||
item := v.(map[string]any)
|
||||
oamData["kpiConfig"] = item
|
||||
delete(oamData, "KPIconfig")
|
||||
r.neConfOAMWirte(neType, neId, oamData, false)
|
||||
r.neConfOAMWirte(neInfo, oamData, false)
|
||||
}
|
||||
|
||||
return oamData, nil
|
||||
@@ -591,11 +689,11 @@ func (r NeInfo) neConfOAMData() map[string]any {
|
||||
}
|
||||
|
||||
// neConfOAMRead 网元OAM配置文件读取 sync从网元端同步到本地
|
||||
func (r NeInfo) neConfOAMRead(neType, neId string, sync bool) (map[string]any, error) {
|
||||
neTypeLower := strings.ToLower(neType)
|
||||
func (r NeInfo) neConfOAMRead(neInfo model.NeInfo, sync bool) (map[string]any, error) {
|
||||
neTypeLower := strings.ToLower(neInfo.NeType)
|
||||
fileName := "oam_manager.yaml"
|
||||
// 网管本地路径
|
||||
localFilePath := fmt.Sprintf("/usr/local/omc/backup/ne_config/%s/%s/%s", neTypeLower, neId, fileName)
|
||||
localFilePath := fmt.Sprintf("/usr/local/omc/backup/ne_config/%s/%s/%s", neTypeLower, neInfo.NeUID, fileName)
|
||||
if runtime.GOOS == "windows" {
|
||||
localFilePath = fmt.Sprintf("C:%s", localFilePath)
|
||||
}
|
||||
@@ -603,7 +701,7 @@ func (r NeInfo) neConfOAMRead(neType, neId string, sync bool) (map[string]any, e
|
||||
// 从网元端同步到本地
|
||||
if sync {
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := r.NeRunSSHClient(neType, neId)
|
||||
sshClient, err := r.NeRunSSHClient(neInfo.CoreUID, neInfo.NeUID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ne info ssh client err")
|
||||
}
|
||||
@@ -631,7 +729,7 @@ func (r NeInfo) neConfOAMRead(neType, neId string, sync bool) (map[string]any, e
|
||||
// return nil, fmt.Errorf("read file error")
|
||||
// 无保留文件时返回默认文件数据
|
||||
oamData := r.neConfOAMData()
|
||||
r.neConfOAMWirte(neType, neId, oamData, false)
|
||||
r.neConfOAMWirte(neInfo, oamData, false)
|
||||
return oamData, nil
|
||||
}
|
||||
content := string(bytes)
|
||||
@@ -646,15 +744,15 @@ func (r NeInfo) neConfOAMRead(neType, neId string, sync bool) (map[string]any, e
|
||||
}
|
||||
|
||||
// neConfOAMWirte 网元OAM配置文件写入 content内容 sync同步到网元端
|
||||
func (r NeInfo) neConfOAMWirte(neType, neId string, content any, sync bool) error {
|
||||
neTypeLower := strings.ToLower(neType)
|
||||
func (r NeInfo) neConfOAMWirte(neInfo model.NeInfo, content any, sync bool) error {
|
||||
neTypeLower := strings.ToLower(neInfo.NeType)
|
||||
fileName := "oam_manager.yaml"
|
||||
// 网管本地路径
|
||||
omcPath := "/usr/local/omc/backup/ne_config"
|
||||
if runtime.GOOS == "windows" {
|
||||
omcPath = fmt.Sprintf("C:%s", omcPath)
|
||||
}
|
||||
localFilePath := fmt.Sprintf("%s/%s/%s/%s", omcPath, neTypeLower, neId, fileName)
|
||||
localFilePath := fmt.Sprintf("%s/%s/%s/%s", omcPath, neTypeLower, neInfo.NeUID, fileName)
|
||||
|
||||
// 写入文件
|
||||
if err := parse.ConvertConfigToFile("yaml", localFilePath, content); err != nil {
|
||||
@@ -664,7 +762,7 @@ func (r NeInfo) neConfOAMWirte(neType, neId string, content any, sync bool) erro
|
||||
// 同步到网元端
|
||||
if sync {
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := r.NeRunSSHClient(neType, neId)
|
||||
sshClient, err := r.NeRunSSHClient(neInfo.CoreUID, neInfo.NeUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -692,7 +790,7 @@ func (r NeInfo) neConfOAMWirte(neType, neId string, content any, sync bool) erro
|
||||
|
||||
// NeConfOAMWirteSync 网元OAM配置文件生成并同步
|
||||
func (r NeInfo) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any, sync bool) error {
|
||||
oamData, err := r.neConfOAMRead(neInfo.NeType, neInfo.NeId, false)
|
||||
oamData, err := r.neConfOAMRead(neInfo, false)
|
||||
if oamData == nil || err != nil {
|
||||
return fmt.Errorf("error read OAM file info")
|
||||
}
|
||||
@@ -703,13 +801,13 @@ func (r NeInfo) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any,
|
||||
httpManageCfg = neConfOAMData["httpManageCfg"].(map[string]any)
|
||||
}
|
||||
httpManageCfg["port"] = neInfo.Port
|
||||
if strings.Contains(neInfo.IP, ":") {
|
||||
if strings.Contains(neInfo.IPAddr, ":") {
|
||||
httpManageCfg["ipType"] = "ipv6"
|
||||
httpManageCfg["ipv6"] = neInfo.IP
|
||||
httpManageCfg["ipv6"] = neInfo.IPAddr
|
||||
}
|
||||
if strings.Contains(neInfo.IP, ".") {
|
||||
if strings.Contains(neInfo.IPAddr, ".") {
|
||||
httpManageCfg["ipType"] = "ipv4"
|
||||
httpManageCfg["ipv4"] = neInfo.IP
|
||||
httpManageCfg["ipv4"] = neInfo.IPAddr
|
||||
}
|
||||
delete(httpManageCfg, "iptype")
|
||||
delete(oamData, "httpmanagecfg")
|
||||
@@ -723,8 +821,8 @@ func (r NeInfo) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any,
|
||||
}
|
||||
delete(oamConfig, "neconfig")
|
||||
oamConfig["neConfig"] = map[string]string{
|
||||
"neId": neInfo.NeId,
|
||||
"rmUid": neInfo.RmUID,
|
||||
"coreId": neInfo.CoreUID,
|
||||
"neUid": neInfo.NeUID,
|
||||
"neName": neInfo.NeName,
|
||||
"dn": neInfo.Dn,
|
||||
"vendorName": neInfo.VendorName,
|
||||
@@ -770,13 +868,13 @@ func (r NeInfo) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any,
|
||||
neConfOAMData := r.neConfOAMData()
|
||||
snmpConfig = neConfOAMData["snmpConfig"].(map[string]any)
|
||||
}
|
||||
if strings.Contains(neInfo.IP, ":") {
|
||||
if strings.Contains(neInfo.IPAddr, ":") {
|
||||
snmpConfig["ipType"] = "ipv6"
|
||||
snmpConfig["ipv6"] = neInfo.IP
|
||||
snmpConfig["ipv6"] = neInfo.IPAddr
|
||||
}
|
||||
if strings.Contains(neInfo.IP, ".") {
|
||||
if strings.Contains(neInfo.IPAddr, ".") {
|
||||
snmpConfig["ipType"] = "ipv4"
|
||||
snmpConfig["ipv4"] = neInfo.IP
|
||||
snmpConfig["ipv4"] = neInfo.IPAddr
|
||||
}
|
||||
delete(snmpConfig, "iptype")
|
||||
if snmpEnable, ok := content["snmpEnable"]; ok && snmpEnable != nil {
|
||||
@@ -808,7 +906,7 @@ func (r NeInfo) NeConfOAMWirteSync(neInfo model.NeInfo, content map[string]any,
|
||||
delete(oamData, "kpiconfig")
|
||||
oamData["kpiConfig"] = kpiConfig
|
||||
|
||||
if err := r.neConfOAMWirte(neInfo.NeType, neInfo.NeId, oamData, sync); err != nil {
|
||||
if err := r.neConfOAMWirte(neInfo, oamData, sync); err != nil {
|
||||
return fmt.Errorf("error wirte OAM file info")
|
||||
}
|
||||
return nil
|
||||
@@ -858,7 +956,7 @@ func (r *NeInfo) NeConfPara5GWirte(content map[string]any, syncNE []string) erro
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := r.NeRunSSHClient(ti[0], ti[1])
|
||||
if err != nil {
|
||||
errMsg = append(errMsg, fmt.Sprintf("%s : %s", ti, err.Error()))
|
||||
errMsg = append(errMsg, fmt.Sprintf("core_ne %s : %s", ti, err.Error()))
|
||||
continue
|
||||
}
|
||||
defer sshClient.Close()
|
||||
|
||||
Reference in New Issue
Block a user