From 6bbf0904947a0919ebddebebb0f9a07415a4cd67 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Thu, 29 Oct 2020 16:59:56 +0800 Subject: [PATCH] guests: add bgp_type arg when create guest --- pkg/apis/compute/api.go | 3 ++- pkg/compute/models/elasticips.go | 3 +++ pkg/compute/models/guest_actions.go | 2 ++ pkg/compute/tasks/guest_batch_create_task.go | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/apis/compute/api.go b/pkg/apis/compute/api.go index c3a91b7b8f..1fb38c1b49 100644 --- a/pkg/apis/compute/api.go +++ b/pkg/apis/compute/api.go @@ -452,8 +452,9 @@ type ServerCreateInput struct { // 弹性公网IP带宽 // 指定此参数后会创建新的弹性公网IP并绑定到新建的虚拟机 // 此参数优先级低于public_ip - // 私有云不支持此参数 EipBw int `json:"eip_bw,omitzero"` + // 弹性公网IP线路类型 + EipBgpType string `json:"eip_bgp_type,omitzero"` // 弹性公网IP计费类型 EipChargeType string `json:"eip_charge_type,omitempty"` // 是否跟随主机删除而自动释放 diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index d2f2efc059..c195bbca09 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -1217,6 +1217,7 @@ func (self *SElasticip) getMoreDetails(out api.ElasticipDetails) api.ElasticipDe type NewEipForVMOnHostArgs struct { Bandwidth int + BgpType string ChargeType string AutoDellocate bool @@ -1228,6 +1229,7 @@ type NewEipForVMOnHostArgs struct { func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCred mcclient.TokenCredential, args *NewEipForVMOnHostArgs) (*SElasticip, error) { var ( bw = args.Bandwidth + bgpType = args.BgpType chargeType = args.ChargeType autoDellocate = args.AutoDellocate vm = args.Guest @@ -1266,6 +1268,7 @@ func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCre q = q.Join(hostwireq, sqlchemy.Equals(hostwireq.Field("wire_id"), wireq.Field("id"))) q = q.Join(hostq, sqlchemy.Equals(hostq.Field("id"), host.Id)) q = q.Equals("server_type", api.NETWORK_TYPE_EIP) + q = q.Equals("bgp_type", bgpType) var nets []SNetwork if err := db.FetchModelObjects(NetworkManager, q, &nets); err != nil { return nil, errors.Wrapf(err, "fetch eip networks usable in host %s(%s)", diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 5c5cdad34a..7d70da4591 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -3018,6 +3018,7 @@ 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() @@ -3055,6 +3056,7 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke eip, err := ElasticipManager.NewEipForVMOnHost(ctx, userCred, &NewEipForVMOnHostArgs{ Bandwidth: int(bw), + BgpType: bgpType, ChargeType: chargeType, AutoDellocate: autoDellocate, diff --git a/pkg/compute/tasks/guest_batch_create_task.go b/pkg/compute/tasks/guest_batch_create_task.go index c94c306b3e..ddf6d448a2 100644 --- a/pkg/compute/tasks/guest_batch_create_task.go +++ b/pkg/compute/tasks/guest_batch_create_task.go @@ -184,6 +184,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest if input.EipBw > 0 { eip, err := models.ElasticipManager.NewEipForVMOnHost(ctx, self.UserCred, &models.NewEipForVMOnHostArgs{ Bandwidth: input.EipBw, + BgpType: input.EipBgpType, ChargeType: input.EipChargeType, AutoDellocate: input.EipAutoDellocate,