fix(region): redis master zone empty fix

This commit is contained in:
TangBin
2020-12-07 14:54:11 +08:00
parent db20769cf2
commit 485cf8b3c8
2 changed files with 17 additions and 1 deletions
@@ -246,11 +246,13 @@ func (self *SElasticcache) GetVpcId() string {
}
func (self *SElasticcache) GetZoneId() string {
zone, err := self.region.getZoneById(transZoneIdToEcsZoneId(self.region, "redis", self.ZoneID))
zoneId := transZoneIdToEcsZoneId(self.region, "redis", self.ZoneID)
zone, err := self.region.getZoneById(fetchMasterZoneId(zoneId))
if err != nil {
log.Errorf("failed to find zone for elasticcache %s error: %v", self.GetId(), err)
return ""
}
return zone.GetGlobalId()
}
+14
View File
@@ -479,3 +479,17 @@ func transRegionIdFromEcsRegionId(region *SRegion, service string) string {
return region.GetId()
}
func fetchMasterZoneId(zoneId string) string {
// cn-shenzhen-finance-1MAZ2(d,e)
i := strings.Index(zoneId, "MAZ")
if i > 0 {
s := strings.Index(zoneId, "(")
e := strings.Index(zoneId, ",")
if s >= 0 && e >= 0 {
return zoneId[0:i] + zoneId[s+1:e]
}
}
return zoneId
}