mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10637 from tb365/bugfix/tb-bugfix-040601
fix(region): guest associate eip checking fix
This commit is contained in:
@@ -2942,14 +2942,11 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T
|
||||
return nil, err
|
||||
}
|
||||
|
||||
eip, err := self.GetEipOrPublicIp()
|
||||
err = self.IsEipAssociable()
|
||||
if err != nil {
|
||||
log.Errorf("Fail to get Eip %s", err)
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
if eip != nil {
|
||||
return nil, httperrors.NewInvalidStatusError("already associate with eip")
|
||||
}
|
||||
|
||||
eipStr := input.EipId
|
||||
if len(eipStr) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("eip_id")
|
||||
@@ -2963,7 +2960,7 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
}
|
||||
|
||||
eip = eipObj.(*SElasticip)
|
||||
eip := eipObj.(*SElasticip)
|
||||
eipRegion, err := eip.GetRegion()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(errors.Wrapf(err, "eip.GetRegion"))
|
||||
|
||||
@@ -4882,6 +4882,28 @@ func (self *SGuest) isInReconcile(userCred mcclient.TokenCredential) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SGuest) IsEipAssociable() error {
|
||||
var eip *SElasticip
|
||||
var err error
|
||||
switch self.Hypervisor {
|
||||
case api.HYPERVISOR_AWS:
|
||||
eip, err = self.GetElasticIp()
|
||||
default:
|
||||
eip, err = self.GetEipOrPublicIp()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("Fail to get Eip %s", err)
|
||||
return errors.Wrap(err, "IsEipAssociable")
|
||||
}
|
||||
|
||||
if eip != nil {
|
||||
return httperrors.NewInvalidStatusError("already associate with eip")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGuest) GetEipOrPublicIp() (*SElasticip, error) {
|
||||
return ElasticipManager.getEip(api.EIP_ASSOCIATE_TYPE_SERVER, self.Id, "")
|
||||
}
|
||||
@@ -4897,10 +4919,16 @@ func (self *SGuest) GetPublicIp() (*SElasticip, error) {
|
||||
func (self *SGuest) SyncVMEip(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, extEip cloudprovider.ICloudEIP, syncOwnerId mcclient.IIdentityProvider) compare.SyncResult {
|
||||
result := compare.SyncResult{}
|
||||
|
||||
eip, err := self.GetEipOrPublicIp()
|
||||
eip, err := self.GetPublicIp()
|
||||
if err != nil {
|
||||
result.Error(fmt.Errorf("getEip error %s", err))
|
||||
result.Error(fmt.Errorf("getPublicIp error %s", err))
|
||||
return result
|
||||
} else if eip == nil {
|
||||
eip, err = self.GetElasticIp()
|
||||
if err != nil {
|
||||
result.Error(fmt.Errorf("getEip error %s", err))
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
if eip == nil && extEip == nil {
|
||||
|
||||
Reference in New Issue
Block a user