elasticips: NewEipForVMOnHost: make args a struct

This commit is contained in:
Yousong Zhou
2020-10-29 17:12:57 +08:00
parent 774cfcbfaf
commit f514950480
3 changed files with 37 additions and 4 deletions
+19 -2
View File
@@ -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 {
+9 -1
View File
@@ -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)
+9 -1
View File
@@ -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)