mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
networks: add field BgpType
This commit is contained in:
@@ -193,6 +193,9 @@ type NetworkCreateInput struct {
|
||||
|
||||
// deprecated
|
||||
Vlan *int `json:"vlan" yunion-deprecated-by:"vlan_id"`
|
||||
|
||||
// 线路类型
|
||||
BgpType string `json:"bgp_type"`
|
||||
}
|
||||
|
||||
type NetworkDetails struct {
|
||||
@@ -329,3 +332,12 @@ type GetNetworkAddressesOutput struct {
|
||||
// IP子网地址记录
|
||||
Addresses []SNetworkAddress `json:"addresses"`
|
||||
}
|
||||
|
||||
type NetworkSetBgpTypeInput struct {
|
||||
apis.Meta
|
||||
|
||||
// description: new BgpType name
|
||||
// required: true
|
||||
// example: ChinaTelecom, BGP, etc.
|
||||
BgpType string `json:"bgp_type"`
|
||||
}
|
||||
|
||||
@@ -98,8 +98,8 @@ type SElasticip struct {
|
||||
// 计费类型: 流量、带宽
|
||||
// example: bandwidth
|
||||
ChargeType string `name:"charge_type" list:"user" create:"required"`
|
||||
// 目前只有华为云此字段是必需填写的
|
||||
BgpType string `list:"user" create:"optional"`
|
||||
// 线路类型
|
||||
BgpType string `width:"64" charset:"utf8" nullable:"false" get:"user" list:"user" create:"optional"`
|
||||
|
||||
// 是否跟随主机删除而自动释放
|
||||
AutoDellocate tristate.TriState `default:"false" get:"user" create:"optional" update:"user"`
|
||||
|
||||
@@ -119,6 +119,9 @@ type SNetwork struct {
|
||||
// 该网段是否用于自动分配IP地址,如果为false,则用户需要明确选择该网段,才会使用该网段分配IP,
|
||||
// 如果为true,则用户不指定网段时,则自动从该值为true的网络中选择一个分配地址
|
||||
IsAutoAlloc tristate.TriState `nullable:"true" list:"user" get:"user" update:"user" create:"optional"`
|
||||
|
||||
// 线路类型
|
||||
BgpType string `width:"64" charset:"utf8" nullable:"false" get:"user" update:"user" create:"optional"`
|
||||
}
|
||||
|
||||
func (manager *SNetworkManager) GetContextManagers() [][]db.IModelManager {
|
||||
@@ -1456,6 +1459,9 @@ func (manager *SNetworkManager) ValidateCreateData(ctx context.Context, userCred
|
||||
if input.ServerType == api.NETWORK_TYPE_EIP && vpc.Id != api.DEFAULT_VPC_ID {
|
||||
return input, httperrors.NewInputParameterError("eip network can only exist in default vpc, got %s(%s)", vpc.Name, vpc.Id)
|
||||
}
|
||||
if input.ServerType != api.NETWORK_TYPE_EIP {
|
||||
input.BgpType = ""
|
||||
}
|
||||
|
||||
var (
|
||||
ipStart = ipRange.StartIp()
|
||||
@@ -2871,3 +2877,47 @@ func (manager *SNetworkManager) AllowScope(userCred mcclient.TokenCredential) rb
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SNetwork) AllowPerformSetBgpType(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "set-isp")
|
||||
}
|
||||
|
||||
func (self *SNetwork) PerformSetBgpType(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.NetworkSetBgpTypeInput) (jsonutils.JSONObject, error) {
|
||||
if self.BgpType == input.BgpType {
|
||||
return nil, nil
|
||||
}
|
||||
if self.ServerType != api.NETWORK_TYPE_EIP {
|
||||
return nil, httperrors.NewInputParameterError("BgpType attribute is only useful for eip network")
|
||||
}
|
||||
{
|
||||
var eips []SElasticip
|
||||
q := ElasticipManager.Query().
|
||||
Equals("network_id", self.Id).
|
||||
NotEquals("bgp_type", input.BgpType)
|
||||
if err := db.FetchModelObjects(ElasticipManager, q, &eips); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range eips {
|
||||
eip := &eips[i]
|
||||
if diff, err := db.UpdateWithLock(ctx, eip, func() error {
|
||||
eip.BgpType = input.BgpType
|
||||
return nil
|
||||
}); err != nil {
|
||||
// no need to retry/restore here. return error
|
||||
// and retry after user resolves the error
|
||||
return nil, err
|
||||
} else {
|
||||
db.OpsLog.LogEvent(eip, db.ACT_UPDATE, diff, userCred)
|
||||
}
|
||||
}
|
||||
}
|
||||
if diff, err := db.Update(self, func() error {
|
||||
self.BgpType = input.BgpType
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
db.OpsLog.LogEvent(self, db.ACT_UPDATE, diff, userCred)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ func (self *EipAllocateTask) OnInit(ctx context.Context, obj db.IStandaloneModel
|
||||
}
|
||||
_, err = db.Update(eip, func() error {
|
||||
eip.IpAddr = ipAddr
|
||||
eip.BgpType = network.BgpType
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user