mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
avoid openstack zone externalid equals
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
@@ -239,6 +240,26 @@ func (self *SVpc) GetRegion() (*SCloudregion, error) {
|
||||
return region.(*SCloudregion), nil
|
||||
}
|
||||
|
||||
func (self *SVpc) getZoneByExternalId(externalId string) (*SZone, error) {
|
||||
region, err := self.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getZoneByExternalId.GetRegion")
|
||||
}
|
||||
zones := []SZone{}
|
||||
q := ZoneManager.Query().Equals("cloudregion_id", region.Id).Equals("external_id", externalId)
|
||||
err = db.FetchModelObjects(ZoneManager, q, &zones)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getZoneByExternalId.FetchModelObjects")
|
||||
}
|
||||
if len(zones) == 1 {
|
||||
return &zones[0], nil
|
||||
}
|
||||
if len(zones) == 0 {
|
||||
return nil, fmt.Errorf("failed to found zone by externalId %s in cloudregion %s(%s)", externalId, region.Name, region.Id)
|
||||
}
|
||||
return nil, fmt.Errorf("found %d duplicate zones by externalId %s in cloudregion %s(%s)", len(zones), externalId, region.Name, region.Id)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := self.SEnabledStatusStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
return self.getMoreDetails(extra)
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
@@ -313,13 +314,11 @@ func (manager *SWireManager) newFromCloudWire(ctx context.Context, userCred mccl
|
||||
wire.VpcId = vpc.Id
|
||||
izone := extWire.GetIZone()
|
||||
if izone != nil {
|
||||
zoneObj, err := db.FetchByExternalId(ZoneManager, izone.GetGlobalId())
|
||||
zone, err := vpc.getZoneByExternalId(izone.GetGlobalId())
|
||||
if err != nil {
|
||||
log.Errorf("cannot find zone for wire %s", err)
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "newFromCloudWire.getZoneByExternalId")
|
||||
}
|
||||
|
||||
wire.ZoneId = zoneObj.(*SZone).Id
|
||||
wire.ZoneId = zone.Id
|
||||
}
|
||||
|
||||
wire.IsEmulated = extWire.IsEmulated()
|
||||
|
||||
Reference in New Issue
Block a user