vm create bugfix

This commit is contained in:
TangBin
2019-11-20 19:20:45 +08:00
parent 5f02bed97e
commit 7eb16f042c
4 changed files with 9 additions and 9 deletions
+5 -5
View File
@@ -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 {
+1 -1
View File
@@ -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)
}
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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