mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
feat(region): Add 'EipAutoDellocate' option when creating vm
This option specify whether the eip created with vm will be released when deleting vm.
This commit is contained in:
@@ -445,9 +445,10 @@ type ServerCreateInput struct {
|
||||
// 指定此参数后会创建新的弹性公网IP并绑定到新建的虚拟机
|
||||
// 私有云不支持此参数
|
||||
EipBw int `json:"eip_bw,omitzero"`
|
||||
|
||||
// 弹性公网IP计费类型
|
||||
EipChargeType string `json:"eip_charge_type,omitempty"`
|
||||
// 是否跟随主机删除而自动释放
|
||||
EipAutoDellocate bool `json:"eip_auto_dellocate,omitempty"`
|
||||
|
||||
// 弹性公网IP名称或ID
|
||||
// 绑定已有弹性公网IP, 此参数会限制虚拟机再谈下公网IP所在的区域创建
|
||||
|
||||
@@ -1206,7 +1206,8 @@ 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, pendingUsage quotas.IQuota) (*SElasticip, error) {
|
||||
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) {
|
||||
region := host.GetRegion()
|
||||
|
||||
if len(chargeType) == 0 {
|
||||
@@ -1221,6 +1222,7 @@ func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCre
|
||||
// eip.AutoDellocate = tristate.True
|
||||
eip.Bandwidth = bw
|
||||
eip.ChargeType = chargeType
|
||||
eip.AutoDellocate = tristate.NewFromBool(autoDellocate)
|
||||
eip.DomainId = vm.DomainId
|
||||
eip.ProjectId = vm.ProjectId
|
||||
eip.ProjectSrc = string(apis.OWNER_SOURCE_LOCAL)
|
||||
|
||||
@@ -2932,6 +2932,7 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke
|
||||
return nil, httperrors.NewMissingParameterError("bandwidth")
|
||||
}
|
||||
}
|
||||
autoDellocate, _ := data.Bool("auto_dellocate")
|
||||
|
||||
if len(self.ExternalId) == 0 {
|
||||
return nil, httperrors.NewInvalidStatusError("Not a managed VM")
|
||||
@@ -2967,7 +2968,7 @@ 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, eipPendingUsage)
|
||||
eip, err := ElasticipManager.NewEipForVMOnHost(ctx, userCred, self, host, int(bw), chargeType, autoDellocate, eipPendingUsage)
|
||||
if err != nil {
|
||||
quotas.CancelPendingUsage(ctx, userCred, eipPendingUsage, eipPendingUsage, false)
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
|
||||
@@ -178,7 +178,7 @@ 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, &pendingRegionUsage)
|
||||
eip, err := models.ElasticipManager.NewEipForVMOnHost(ctx, self.UserCred, guest, host, input.EipBw, input.EipChargeType, input.EipAutoDellocate, &pendingRegionUsage)
|
||||
self.SetPendingUsage(&pendingRegionUsage, 1)
|
||||
if err != nil {
|
||||
log.Errorf("guest.CreateElasticipOnHost failed: %s", err)
|
||||
|
||||
Reference in New Issue
Block a user