From a12a36bfc362a3dea81e63fa91150ff82389b740 Mon Sep 17 00:00:00 2001 From: tb365 Date: Tue, 19 Oct 2021 17:38:24 +0800 Subject: [PATCH] eip bind aws server fix --- pkg/compute/models/elasticips.go | 2 +- pkg/compute/models/guests.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index 606011aedc..ab0b20c591 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -996,7 +996,7 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient. // IMPORTANT: this serves as a guard against a guest to have multiple // associated elastic_ips seip, _ := server.GetEipOrPublicIp() - if seip != nil { + if seip != nil && (seip.Mode == api.EIP_MODE_STANDALONE_EIP || seip.GetProviderName() != api.CLOUD_PROVIDER_AWS) { return input, httperrors.NewInvalidStatusError("instance is already associated with eip") } diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 7cbca100cb..59250ed0e3 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -313,6 +313,7 @@ func (manager *SGuestManager) ListItemFilter( } } + var eipMode string usableServerForEipFilter := query.UsableServerForEip if len(usableServerForEipFilter) > 0 { eipObj, err := ElasticipManager.FetchByIdOrName(userCred, usableServerForEipFilter) @@ -324,6 +325,10 @@ func (manager *SGuestManager) ListItemFilter( } eip := eipObj.(*SElasticip) + if eip.GetProviderName() == api.CLOUD_PROVIDER_AWS { + eipMode = api.EIP_MODE_STANDALONE_EIP + } + if len(eip.NetworkId) > 0 { sq := GuestnetworkManager.Query("guest_id").Equals("network_id", eip.NetworkId).SubQuery() q = q.NotIn("id", sq) @@ -404,6 +409,9 @@ func (manager *SGuestManager) ListItemFilter( eips := ElasticipManager.Query().SubQuery() sq := eips.Query(eips.Field("associate_id")).Equals("associate_type", api.EIP_ASSOCIATE_TYPE_SERVER) sq = sq.IsNotNull("associate_id").IsNotEmpty("associate_id") + if len(eipMode) > 0 { + sq = sq.Equals("mode", eipMode) + } if withEip { q = q.In("id", sq)