mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Merge pull request #9308 from yousong/bugfix/yousong-eip-chargetype
Bugfix/yousong eip chargetype
This commit is contained in:
@@ -42,7 +42,6 @@ const (
|
||||
|
||||
EIP_CHARGE_TYPE_BY_TRAFFIC = "traffic"
|
||||
EIP_CHARGE_TYPE_BY_BANDWIDTH = "bandwidth"
|
||||
EIP_CHARGE_TYPE_DEFAULT = EIP_CHARGE_TYPE_BY_TRAFFIC
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -800,14 +800,17 @@ func (manager *SElasticipManager) ValidateCreateData(ctx context.Context, userCr
|
||||
}
|
||||
return input, httperrors.NewResourceNotFoundError2("cloudregion", input.CloudregionId)
|
||||
}
|
||||
region := obj.(*SCloudregion)
|
||||
var (
|
||||
region = obj.(*SCloudregion)
|
||||
regionDriver = region.GetDriver()
|
||||
)
|
||||
input.CloudregionId = region.GetId()
|
||||
|
||||
// publicIp cannot be created standalone
|
||||
input.Mode = api.EIP_MODE_STANDALONE_EIP
|
||||
|
||||
if len(input.ChargeType) == 0 {
|
||||
input.ChargeType = api.EIP_CHARGE_TYPE_DEFAULT
|
||||
if input.ChargeType == "" {
|
||||
input.ChargeType = regionDriver.GetEipDefaultChargeType()
|
||||
}
|
||||
|
||||
if !utils.IsInStringArray(input.ChargeType, []string{api.EIP_CHARGE_TYPE_BY_BANDWIDTH, api.EIP_CHARGE_TYPE_BY_TRAFFIC}) {
|
||||
@@ -819,7 +822,7 @@ func (manager *SElasticipManager) ValidateCreateData(ctx context.Context, userCr
|
||||
return input, err
|
||||
}
|
||||
|
||||
err = region.GetDriver().ValidateCreateEipData(ctx, userCred, &input)
|
||||
err = regionDriver.ValidateCreateEipData(ctx, userCred, &input)
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
@@ -1237,10 +1240,16 @@ func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCre
|
||||
host = args.Host
|
||||
pendingUsage = args.PendingUsage
|
||||
)
|
||||
region := host.GetRegion()
|
||||
var (
|
||||
region = host.GetRegion()
|
||||
regionDriver = region.GetDriver()
|
||||
)
|
||||
|
||||
if len(chargeType) == 0 {
|
||||
chargeType = api.EIP_CHARGE_TYPE_BY_TRAFFIC
|
||||
if chargeType == "" {
|
||||
chargeType = regionDriver.GetEipDefaultChargeType()
|
||||
}
|
||||
if err := regionDriver.ValidateEipChargeType(chargeType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
eip := &SElasticip{}
|
||||
@@ -1258,7 +1267,9 @@ func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCre
|
||||
eip.ManagerId = host.ManagerId
|
||||
eip.CloudregionId = region.Id
|
||||
eip.Name = fmt.Sprintf("eip-for-%s", vm.GetName())
|
||||
|
||||
if host.ManagerId == "" {
|
||||
|
||||
hostq := HostManager.Query().SubQuery()
|
||||
wireq := WireManager.Query().SubQuery()
|
||||
hostwireq := HostwireManager.Query().SubQuery()
|
||||
|
||||
@@ -3013,10 +3013,19 @@ func (self *SGuest) AllowPerformCreateEip(ctx context.Context, userCred mcclient
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
var bw int64
|
||||
chargeType, _ := data.GetString("charge_type")
|
||||
if len(chargeType) == 0 {
|
||||
chargeType = api.EIP_CHARGE_TYPE_DEFAULT
|
||||
var (
|
||||
host = self.GetHost()
|
||||
region = host.GetRegion()
|
||||
regionDriver = region.GetDriver()
|
||||
|
||||
bw int64
|
||||
chargeType string
|
||||
bgpType string
|
||||
autoDellocate bool
|
||||
)
|
||||
chargeType, _ = data.GetString("charge_type")
|
||||
if chargeType == "" {
|
||||
chargeType = regionDriver.GetEipDefaultChargeType()
|
||||
}
|
||||
|
||||
bw, _ = data.Int("bandwidth")
|
||||
@@ -3025,25 +3034,8 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke
|
||||
return nil, httperrors.NewMissingParameterError("bandwidth")
|
||||
}
|
||||
}
|
||||
bgpType, _ := data.GetString("bgp_type")
|
||||
autoDellocate, _ := data.Bool("auto_dellocate")
|
||||
|
||||
host := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInvalidStatusError("No host???")
|
||||
}
|
||||
{
|
||||
if self.ExternalId != "" {
|
||||
_, err := host.GetDriver()
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInvalidStatusError("No valid cloud provider")
|
||||
}
|
||||
}
|
||||
region := host.GetRegion()
|
||||
if region == nil {
|
||||
return nil, httperrors.NewInvalidStatusError("No cloudregion???")
|
||||
}
|
||||
}
|
||||
bgpType, _ = data.GetString("bgp_type")
|
||||
autoDellocate, _ = data.Bool("auto_dellocate")
|
||||
|
||||
err := self.GetDriver().ValidateCreateEip(ctx, userCred, data)
|
||||
if err != nil {
|
||||
|
||||
@@ -91,6 +91,8 @@ type IRegionDriver interface {
|
||||
|
||||
ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error)
|
||||
IsVpcCreateNeedInputCidr() bool
|
||||
GetEipDefaultChargeType() string
|
||||
ValidateEipChargeType(chargeType string) error
|
||||
ValidateCreateEipData(ctx context.Context, userCred mcclient.TokenCredential, input *api.SElasticipCreateInput) error
|
||||
RequestCreateVpc(ctx context.Context, userCred mcclient.TokenCredential, region *SCloudregion, vpc *SVpc, task taskman.ITask) error
|
||||
RequestDeleteVpc(ctx context.Context, userCred mcclient.TokenCredential, region *SCloudregion, vpc *SVpc, task taskman.ITask) error
|
||||
|
||||
@@ -899,7 +899,21 @@ func (self *SKVMRegionDriver) RequestDeleteVpc(ctx context.Context, userCred mcc
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) GetEipDefaultChargeType() string {
|
||||
return api.EIP_CHARGE_TYPE_BY_BANDWIDTH
|
||||
}
|
||||
func (self *SKVMRegionDriver) ValidateEipChargeType(chargeType string) error {
|
||||
if chargeType != api.EIP_CHARGE_TYPE_BY_BANDWIDTH {
|
||||
return httperrors.NewInputParameterError("%s only supports eip charge type %q",
|
||||
self.GetProvider(), api.EIP_CHARGE_TYPE_BY_BANDWIDTH)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) ValidateCreateEipData(ctx context.Context, userCred mcclient.TokenCredential, input *api.SElasticipCreateInput) error {
|
||||
if err := self.ValidateEipChargeType(input.ChargeType); err != nil {
|
||||
return err
|
||||
}
|
||||
var network *models.SNetwork
|
||||
if input.NetworkId != "" {
|
||||
_network, err := models.NetworkManager.FetchByIdOrName(userCred, input.NetworkId)
|
||||
|
||||
@@ -1187,7 +1187,12 @@ func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancerListene
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateCreateVpcData(ctx context.Context, userCred mcclient.TokenCredential, input api.VpcCreateInput) (api.VpcCreateInput, error) {
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) GetEipDefaultChargeType() string {
|
||||
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
|
||||
}
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateEipChargeType(chargeType string) error {
|
||||
return nil
|
||||
}
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateCreateEipData(ctx context.Context, userCred mcclient.TokenCredential, input *api.SElasticipCreateInput) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user