mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix: fail to delete public_ip eip
This commit is contained in:
@@ -419,3 +419,16 @@ type ServerRemoteUpdateInput struct {
|
||||
// 是否覆盖替换所有标签
|
||||
ReplaceTags *bool `json:"replace_tags" help:"replace all remote tags"`
|
||||
}
|
||||
|
||||
type ServerAssociateEipInput struct {
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
Eip string `json:"eip" yunion-deprecated-by:"eip_id"`
|
||||
// 弹性公网IP的ID
|
||||
EipId string `json:"eip_id"`
|
||||
}
|
||||
|
||||
type ServerDissociateEipInput struct {
|
||||
// 是否自动释放
|
||||
AudoDelete *bool `json:"auto_delete"`
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func (self *SOpenStackGuestDriver) RemoteDeployGuestForRebuildRoot(ctx context.C
|
||||
}
|
||||
defer self.attachDisks(ctx, ihost, instanceId, detachDisks)
|
||||
|
||||
eip, err := guest.GetEip()
|
||||
eip, err := guest.GetElasticIp()
|
||||
if err == nil && eip != nil {
|
||||
ieip, err := eip.GetIEip()
|
||||
if err != nil {
|
||||
|
||||
@@ -970,7 +970,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.GetEip()
|
||||
seip, _ := server.GetEipOrPublicIp()
|
||||
if seip != nil {
|
||||
return nil, httperrors.NewInvalidStatusError("instance is already associated with eip")
|
||||
}
|
||||
|
||||
@@ -2624,7 +2624,7 @@ func (self *SGuest) RevokeAllSecgroups(ctx context.Context, userCred mcclient.To
|
||||
}
|
||||
|
||||
func (self *SGuest) DoPendingDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
eip, _ := self.GetEip()
|
||||
eip, _ := self.GetEipOrPublicIp()
|
||||
if eip != nil {
|
||||
eip.DoPendingDelete(ctx, userCred)
|
||||
}
|
||||
@@ -2666,6 +2666,11 @@ func (self *SGuest) PerformCancelDelete(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
|
||||
func (self *SGuest) DoCancelPendingDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
eip, _ := self.GetEipOrPublicIp()
|
||||
if eip != nil {
|
||||
eip.DoCancelPendingDelete(ctx, userCred)
|
||||
}
|
||||
|
||||
for _, guestdisk := range self.GetDisks() {
|
||||
disk := guestdisk.GetDisk()
|
||||
disk.DoCancelPendingDelete(ctx, userCred)
|
||||
@@ -2881,12 +2886,12 @@ func (self *SGuest) AllowPerformAssociateEip(ctx context.Context, userCred mccli
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "associate-eip")
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
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)
|
||||
}
|
||||
|
||||
eip, err := self.GetEip()
|
||||
eip, err := self.GetEipOrPublicIp()
|
||||
if err != nil {
|
||||
log.Errorf("Fail to get Eip %s", err)
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
@@ -2894,7 +2899,7 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T
|
||||
if eip != nil {
|
||||
return nil, httperrors.NewInvalidStatusError("already associate with eip")
|
||||
}
|
||||
eipStr := jsonutils.GetAnyString(data, []string{"eip", "eip_id"})
|
||||
eipStr := input.EipId
|
||||
if len(eipStr) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("eip_id")
|
||||
}
|
||||
@@ -2969,8 +2974,8 @@ func (self *SGuest) AllowPerformDissociateEip(ctx context.Context, userCred mccl
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "dissociate-eip")
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformDissociateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
eip, err := self.GetEip()
|
||||
func (self *SGuest) PerformDissociateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ServerDissociateEipInput) (jsonutils.JSONObject, error) {
|
||||
eip, err := self.GetElasticIp()
|
||||
if err != nil {
|
||||
log.Errorf("Fail to get Eip %s", err)
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
@@ -2986,7 +2991,7 @@ func (self *SGuest) PerformDissociateEip(ctx context.Context, userCred mcclient.
|
||||
|
||||
self.SetStatus(userCred, api.VM_DISSOCIATE_EIP, "associate eip")
|
||||
|
||||
autoDelete := jsonutils.QueryBoolean(data, "auto_delete", false)
|
||||
autoDelete := (input.AudoDelete != nil && *input.AudoDelete)
|
||||
|
||||
err = eip.StartEipDissociateTask(ctx, userCred, autoDelete, "")
|
||||
if err != nil {
|
||||
@@ -4330,7 +4335,7 @@ func (guest *SGuest) PerformChangeOwner(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
}
|
||||
|
||||
if eip, _ := guest.GetEip(); eip != nil {
|
||||
if eip, _ := guest.GetEipOrPublicIp(); eip != nil {
|
||||
_, err := eip.PerformChangeOwner(ctx, userCred, query, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -4718,8 +4718,12 @@ func (self *SGuest) isInReconcile(userCred mcclient.TokenCredential) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SGuest) GetEip() (*SElasticip, error) {
|
||||
return ElasticipManager.getEipForInstance(api.EIP_ASSOCIATE_TYPE_SERVER, self.Id)
|
||||
func (self *SGuest) GetEipOrPublicIp() (*SElasticip, error) {
|
||||
return ElasticipManager.getEip(api.EIP_ASSOCIATE_TYPE_SERVER, self.Id, "")
|
||||
}
|
||||
|
||||
func (self *SGuest) GetElasticIp() (*SElasticip, error) {
|
||||
return ElasticipManager.getEip(api.EIP_ASSOCIATE_TYPE_SERVER, self.Id, api.EIP_MODE_STANDALONE_EIP)
|
||||
}
|
||||
|
||||
func (self *SGuest) GetPublicIp() (*SElasticip, error) {
|
||||
@@ -4729,7 +4733,7 @@ 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.GetEip()
|
||||
eip, err := self.GetEipOrPublicIp()
|
||||
if err != nil {
|
||||
result.Error(fmt.Errorf("getEip error %s", err))
|
||||
return result
|
||||
@@ -4878,7 +4882,7 @@ func (self *SGuest) DetachScheduledTask(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
|
||||
func (self *SGuest) DeleteEip(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
eip, err := self.GetEip()
|
||||
eip, err := self.GetEipOrPublicIp()
|
||||
if err != nil {
|
||||
log.Errorf("Delete eip fail for get Eip %s", err)
|
||||
return err
|
||||
@@ -5180,7 +5184,7 @@ func (self *SGuest) toCreateInput() *api.ServerCreateInput {
|
||||
if host := self.GetHost(); host != nil {
|
||||
r.ResourceType = host.ResourceType
|
||||
}
|
||||
if eip, _ := self.GetEip(); eip != nil && eip.Mode == api.EIP_MODE_STANDALONE_EIP {
|
||||
if eip, _ := self.GetEipOrPublicIp(); eip != nil && eip.Mode == api.EIP_MODE_STANDALONE_EIP {
|
||||
r.EipBw = eip.Bandwidth
|
||||
r.EipChargeType = eip.ChargeType
|
||||
}
|
||||
@@ -5354,7 +5358,7 @@ func (self *SGuest) getGuestUsage(guestCount int) (SQuota, SRegionQuota, error)
|
||||
}
|
||||
regionUsage.Port = netCount
|
||||
// regionUsage.Bw = self.getBandwidth(false)
|
||||
eip, err := self.GetEip()
|
||||
eip, err := self.GetEipOrPublicIp()
|
||||
if err != nil && errors.Cause(err) != sql.ErrNoRows {
|
||||
return usage, regionUsage, err
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func (self *GuestDeleteTask) OnStartEipDissociate(ctx context.Context, guest *mo
|
||||
sourceGuest.StartSyncstatus(ctx, self.UserCred, "")
|
||||
}
|
||||
}
|
||||
eip, _ := guest.GetEip()
|
||||
eip, _ := guest.GetEipOrPublicIp()
|
||||
if eip != nil && eip.Mode != api.EIP_MODE_INSTANCE_PUBLICIP {
|
||||
// detach floating EIP only
|
||||
if jsonutils.QueryBoolean(self.Params, "purge", false) {
|
||||
|
||||
Reference in New Issue
Block a user