guests: add bgp_type arg when create guest

This commit is contained in:
Yousong Zhou
2020-10-29 17:12:57 +08:00
parent f514950480
commit 6bbf090494
4 changed files with 8 additions and 1 deletions
+2 -1
View File
@@ -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"`
// 是否跟随主机删除而自动释放
+3
View File
@@ -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)",
+2
View File
@@ -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,
@@ -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,