mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10490 from ioito/hotfix/qx-nas-fix
fix: nat delete and create fix
This commit is contained in:
@@ -207,6 +207,10 @@ func (man *SNatGatewayManager) ValidateCreateData(ctx context.Context, userCred
|
||||
// create new
|
||||
}
|
||||
}
|
||||
input.StatusInfrasResourceBaseCreateInput, err = man.SStatusInfrasResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.StatusInfrasResourceBaseCreateInput)
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
driver := region.GetDriver()
|
||||
return driver.ValidateCreateNatGateway(ctx, userCred, input)
|
||||
}
|
||||
|
||||
@@ -46,32 +46,10 @@ func (self *NatGatewayDeleteTask) taskFailed(ctx context.Context, nat *models.SN
|
||||
func (self *NatGatewayDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
|
||||
nat := obj.(*models.SNatGateway)
|
||||
|
||||
self.SetStage("OnEipDissociateComplete", nil)
|
||||
self.OnEipDissociateComplete(ctx, nat, nil)
|
||||
}
|
||||
|
||||
func (self *NatGatewayDeleteTask) OnEipDissociateComplete(ctx context.Context, nat *models.SNatGateway, data jsonutils.JSONObject) {
|
||||
eips, err := nat.GetEips()
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, nat, errors.Wrapf(err, "nat.GetEips"))
|
||||
return
|
||||
}
|
||||
if len(eips) > 0 {
|
||||
eips[0].StartEipDissociateTask(ctx, self.GetUserCred(), false, self.GetTaskId())
|
||||
return
|
||||
}
|
||||
self.doDeleteNatGateway(ctx, nat)
|
||||
}
|
||||
|
||||
func (self *NatGatewayDeleteTask) OnEipDissociateCompleteFailed(ctx context.Context, nat *models.SNatGateway, data jsonutils.JSONObject) {
|
||||
self.SetStageFailed(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *NatGatewayDeleteTask) doDeleteNatGateway(ctx context.Context, nat *models.SNatGateway) {
|
||||
iNat, err := nat.GetINatGateway()
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
self.taskComplete(ctx, nat)
|
||||
self.OnEipDissociateComplete(ctx, nat, nil)
|
||||
return
|
||||
}
|
||||
self.taskFailed(ctx, nat, errors.Wrapf(err, "nat.GetINatGateway"))
|
||||
@@ -105,6 +83,38 @@ func (self *NatGatewayDeleteTask) doDeleteNatGateway(ctx context.Context, nat *m
|
||||
cloudprovider.WaitDeleted(snat[i], time.Second*5, time.Minute)
|
||||
}
|
||||
|
||||
self.SetStage("OnEipDissociateComplete", nil)
|
||||
self.OnEipDissociateComplete(ctx, nat, nil)
|
||||
}
|
||||
|
||||
func (self *NatGatewayDeleteTask) OnEipDissociateComplete(ctx context.Context, nat *models.SNatGateway, data jsonutils.JSONObject) {
|
||||
eips, err := nat.GetEips()
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, nat, errors.Wrapf(err, "nat.GetEips"))
|
||||
return
|
||||
}
|
||||
if len(eips) > 0 {
|
||||
eips[0].StartEipDissociateTask(ctx, self.GetUserCred(), false, self.GetTaskId())
|
||||
return
|
||||
}
|
||||
self.doDeleteNatGateway(ctx, nat)
|
||||
}
|
||||
|
||||
func (self *NatGatewayDeleteTask) OnEipDissociateCompleteFailed(ctx context.Context, nat *models.SNatGateway, data jsonutils.JSONObject) {
|
||||
self.SetStageFailed(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *NatGatewayDeleteTask) doDeleteNatGateway(ctx context.Context, nat *models.SNatGateway) {
|
||||
iNat, err := nat.GetINatGateway()
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
self.taskComplete(ctx, nat)
|
||||
return
|
||||
}
|
||||
self.taskFailed(ctx, nat, errors.Wrapf(err, "nat.GetINatGateway"))
|
||||
return
|
||||
}
|
||||
|
||||
err = iNat.Delete()
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, nat, errors.Wrapf(err, "iNat.Delete"))
|
||||
|
||||
Reference in New Issue
Block a user