mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 22:32:15 +08:00
fix: server associate eip check (#14339)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -2974,16 +2974,7 @@ func (self *SGuest) SendMonitorCommand(ctx context.Context, userCred mcclient.To
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ServerAssociateEipInput) (jsonutils.JSONObject, error) {
|
||||
if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING}) {
|
||||
return nil, httperrors.NewInvalidStatusError("cannot associate eip in status %s", self.Status)
|
||||
}
|
||||
|
||||
err := ValidateAssociateEip(self)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = self.IsEipAssociable()
|
||||
err := self.IsEipAssociable()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
@@ -3103,9 +3094,9 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke
|
||||
autoDellocate = (input.AutoDellocate != nil && *input.AutoDellocate)
|
||||
)
|
||||
|
||||
err := ValidateAssociateEip(self)
|
||||
err := self.IsEipAssociable()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
|
||||
if chargeType == "" {
|
||||
|
||||
@@ -5027,8 +5027,16 @@ func (self *SGuest) isInReconcile(userCred mcclient.TokenCredential) bool {
|
||||
}
|
||||
|
||||
func (self *SGuest) IsEipAssociable() error {
|
||||
if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING}) {
|
||||
return errors.Wrapf(httperrors.ErrInvalidStatus, "cannot associate eip in status %s", self.Status)
|
||||
}
|
||||
|
||||
err := ValidateAssociateEip(self)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ValidateAssociateEip")
|
||||
}
|
||||
|
||||
var eip *SElasticip
|
||||
var err error
|
||||
switch self.Hypervisor {
|
||||
case api.HYPERVISOR_AWS:
|
||||
eip, err = self.GetElasticIp()
|
||||
|
||||
Reference in New Issue
Block a user