From f51495048092796abb915da9ad3ca3739d7bedab Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Thu, 29 Oct 2020 16:45:20 +0800 Subject: [PATCH] elasticips: NewEipForVMOnHost: make args a struct --- pkg/compute/models/elasticips.go | 21 ++++++++++++++++++-- pkg/compute/models/guest_actions.go | 10 +++++++++- pkg/compute/tasks/guest_batch_create_task.go | 10 +++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index 25b5a99848..d2f2efc059 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -1215,8 +1215,25 @@ func (self *SElasticip) getMoreDetails(out api.ElasticipDetails) api.ElasticipDe return out } -func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCred mcclient.TokenCredential, vm *SGuest, - host *SHost, bw int, chargeType string, autoDellocate bool, pendingUsage quotas.IQuota) (*SElasticip, error) { +type NewEipForVMOnHostArgs struct { + Bandwidth int + ChargeType string + AutoDellocate bool + + Guest *SGuest + Host *SHost + PendingUsage quotas.IQuota +} + +func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCred mcclient.TokenCredential, args *NewEipForVMOnHostArgs) (*SElasticip, error) { + var ( + bw = args.Bandwidth + chargeType = args.ChargeType + autoDellocate = args.AutoDellocate + vm = args.Guest + host = args.Host + pendingUsage = args.PendingUsage + ) region := host.GetRegion() if len(chargeType) == 0 { diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 9e4c43406c..5c5cdad34a 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -3053,7 +3053,15 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke return nil, httperrors.NewOutOfQuotaError("Out of eip quota: %s", err) } - eip, err := ElasticipManager.NewEipForVMOnHost(ctx, userCred, self, host, int(bw), chargeType, autoDellocate, eipPendingUsage) + eip, err := ElasticipManager.NewEipForVMOnHost(ctx, userCred, &NewEipForVMOnHostArgs{ + Bandwidth: int(bw), + ChargeType: chargeType, + AutoDellocate: autoDellocate, + + Guest: self, + Host: host, + PendingUsage: eipPendingUsage, + }) if err != nil { quotas.CancelPendingUsage(ctx, userCred, eipPendingUsage, eipPendingUsage, false) return nil, httperrors.NewGeneralError(err) diff --git a/pkg/compute/tasks/guest_batch_create_task.go b/pkg/compute/tasks/guest_batch_create_task.go index 80604d2fbe..c94c306b3e 100644 --- a/pkg/compute/tasks/guest_batch_create_task.go +++ b/pkg/compute/tasks/guest_batch_create_task.go @@ -182,7 +182,15 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest // allocate eips if input.EipBw > 0 { - eip, err := models.ElasticipManager.NewEipForVMOnHost(ctx, self.UserCred, guest, host, input.EipBw, input.EipChargeType, input.EipAutoDellocate, &pendingRegionUsage) + eip, err := models.ElasticipManager.NewEipForVMOnHost(ctx, self.UserCred, &models.NewEipForVMOnHostArgs{ + Bandwidth: input.EipBw, + ChargeType: input.EipChargeType, + AutoDellocate: input.EipAutoDellocate, + + Guest: guest, + Host: host, + PendingUsage: &pendingRegionUsage, + }) self.SetPendingUsage(&pendingRegionUsage, 1) if err != nil { log.Errorf("guest.CreateElasticipOnHost failed: %s", err)