mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #12469 from tb365/bugfix/tb-bugfix-101902
eip bind aws server fix
This commit is contained in:
@@ -1016,7 +1016,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")
|
||||
}
|
||||
|
||||
|
||||
@@ -314,6 +314,7 @@ func (manager *SGuestManager) ListItemFilter(
|
||||
}
|
||||
}
|
||||
|
||||
var eipMode string
|
||||
usableServerForEipFilter := query.UsableServerForEip
|
||||
if len(usableServerForEipFilter) > 0 {
|
||||
eipObj, err := ElasticipManager.FetchByIdOrName(userCred, usableServerForEipFilter)
|
||||
@@ -325,6 +326,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)
|
||||
@@ -405,6 +410,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)
|
||||
|
||||
Reference in New Issue
Block a user