mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
elasticips: NewEipForVMOnHost: make args a struct
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user