diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index 7fdef99225..dbb40d644f 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -733,11 +733,11 @@ func (self *SElasticip) PostCreate(ctx context.Context, userCred mcclient.TokenC log.Errorf("SElasticip CancelPendingUsage error: %s", err) } - self.startEipAllocateTask(ctx, userCred, data.(*jsonutils.JSONDict)) + self.startEipAllocateTask(ctx, userCred, data.(*jsonutils.JSONDict), "") } -func (self *SElasticip) startEipAllocateTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict) error { - task, err := taskman.TaskManager.NewTask(ctx, "EipAllocateTask", self, userCred, params, "", "", nil) +func (self *SElasticip) startEipAllocateTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error { + task, err := taskman.TaskManager.NewTask(ctx, "EipAllocateTask", self, userCred, params, parentTaskId, "", nil) if err != nil { log.Errorf("newtask EipAllocateTask fail %s", err) return err @@ -1068,7 +1068,7 @@ func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCre return &eip, nil } -func (eip *SElasticip) AllocateAndAssociateVM(ctx context.Context, userCred mcclient.TokenCredential, vm *SGuest) error { +func (eip *SElasticip) AllocateAndAssociateVM(ctx context.Context, userCred mcclient.TokenCredential, vm *SGuest, parentTaskId string) error { params := jsonutils.NewDict() params.Add(jsonutils.NewString(vm.ExternalId), "instance_external_id") params.Add(jsonutils.NewString(vm.Id), "instance_id") @@ -1076,7 +1076,7 @@ func (eip *SElasticip) AllocateAndAssociateVM(ctx context.Context, userCred mccl vm.SetStatus(userCred, api.VM_ASSOCIATE_EIP, "allocate and associate EIP") - return eip.startEipAllocateTask(ctx, userCred, params) + return eip.startEipAllocateTask(ctx, userCred, params, parentTaskId) } func (self *SElasticip) AllowPerformChangeBandwidth(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 6c19549266..8e316bc3bc 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -2833,7 +2833,7 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke return nil, httperrors.NewGeneralError(err) } - err = eip.AllocateAndAssociateVM(ctx, userCred, self) + err = eip.AllocateAndAssociateVM(ctx, userCred, self, "") if err != nil { return nil, httperrors.NewGeneralError(err) } diff --git a/pkg/compute/tasks/eip_allocate_task.go b/pkg/compute/tasks/eip_allocate_task.go index e8aaec8f7d..b286013200 100644 --- a/pkg/compute/tasks/eip_allocate_task.go +++ b/pkg/compute/tasks/eip_allocate_task.go @@ -133,7 +133,7 @@ func (self *EipAllocateTask) OnInit(ctx context.Context, obj db.IStandaloneModel if self.Params != nil && self.Params.Contains("instance_id") { self.SetStage("on_eip_associate_complete", nil) - err = eip.StartEipAssociateTask(ctx, self.UserCred, self.Params, "") + err = eip.StartEipAssociateTask(ctx, self.UserCred, self.Params, self.GetId()) if err != nil { msg := fmt.Sprintf("start associate task fail %s", err) self.SetStageFailed(ctx, msg) diff --git a/pkg/compute/tasks/guest_create_task.go b/pkg/compute/tasks/guest_create_task.go index 6aba295c54..21941b4390 100644 --- a/pkg/compute/tasks/guest_create_task.go +++ b/pkg/compute/tasks/guest_create_task.go @@ -126,10 +126,10 @@ func (self *GuestCreateTask) OnDeployGuestDescComplete(ctx context.Context, obj eipBw, _ := self.Params.Int("eip_bw") if eipBw > 0 { // newly allocated eip, need allocation and associate - eip.AllocateAndAssociateVM(ctx, self.UserCred, guest) + eip.AllocateAndAssociateVM(ctx, self.UserCred, guest, self.GetId()) } else { // existing eip, association only - eip.StartEipAssociateInstanceTask(ctx, self.UserCred, guest, "") + eip.StartEipAssociateInstanceTask(ctx, self.UserCred, guest, self.GetId()) } return