mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix: vm nic charge type support (#23703)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -121,6 +121,8 @@ type NetworkConfig struct {
|
||||
|
||||
PortMappings GuestPortMappings `json:"port_mappings"`
|
||||
|
||||
ChargeType string `json:"charge_type"`
|
||||
|
||||
// swagger:ignore
|
||||
Project string `json:"project_id"`
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@ type GuestnetworkShortDesc struct {
|
||||
// IP地址
|
||||
IpAddr string `json:"ip_addr"`
|
||||
// 是否为外网网卡
|
||||
// Deprecated
|
||||
IsExit bool `json:"is_exit"`
|
||||
// IPv6地址
|
||||
Ip6Addr string `json:"ip6_addr"`
|
||||
@@ -66,8 +65,14 @@ type GuestnetworkShortDesc struct {
|
||||
SubIps string `json:"sub_ips"`
|
||||
// 端口映射
|
||||
PortMappings GuestPortMappings `json:"port_mappings"`
|
||||
|
||||
// Bandwidth
|
||||
BwLimitMbps int `json:"bw_limit_mbps"`
|
||||
// 网卡名称
|
||||
Ifname string `json:"ifname"`
|
||||
// 是否为缺省路由网关
|
||||
IsDefault bool `json:"is_default"`
|
||||
// 计费模式
|
||||
ChargeType string `json:"charge_type"`
|
||||
}
|
||||
|
||||
type GuestnetworkListInput struct {
|
||||
@@ -97,8 +102,11 @@ type GuestnetworkUpdateInput struct {
|
||||
|
||||
Index *int8 `json:"index"`
|
||||
|
||||
IsDefault *bool `json:"is_default"`
|
||||
IsDefault *bool `json:"is_default"`
|
||||
|
||||
PortMappings GuestPortMappings `json:"port_mappings"`
|
||||
|
||||
ChargeType string `json:"charge_type"`
|
||||
}
|
||||
|
||||
type GuestnetworkBaseDesc struct {
|
||||
|
||||
@@ -357,6 +357,8 @@ func ParseNetworkConfig(desc string, idx int) (*compute.NetworkConfig, error) {
|
||||
netConfig.Driver = p
|
||||
} else if strings.HasPrefix(p, "num-queues=") {
|
||||
netConfig.NumQueues, _ = strconv.Atoi(p[len("num-queues="):])
|
||||
} else if strings.HasPrefix(p, "charge-type=") {
|
||||
netConfig.ChargeType = p[len("charge-type="):]
|
||||
} else if regutils.MatchSize(p) {
|
||||
bw, err := fileutils.GetSizeMb(p, 'M', 1000)
|
||||
if err != nil {
|
||||
|
||||
@@ -273,6 +273,8 @@ func (self *SBaremetalGuestDriver) Attach2RandomNetwork(guest *models.SGuest, ct
|
||||
NicConfs: nicConfs,
|
||||
|
||||
IsDefault: netConfig.IsDefault,
|
||||
|
||||
ChargeType: netConfig.ChargeType,
|
||||
})
|
||||
}
|
||||
return nil, fmt.Errorf("No appropriate host virtual network...")
|
||||
|
||||
@@ -273,6 +273,8 @@ func (self *SCloudpodsBaremetalGuestDriver) Attach2RandomNetwork(guest *models.S
|
||||
NicConfs: nicConfs,
|
||||
|
||||
IsDefault: netConfig.IsDefault,
|
||||
|
||||
ChargeType: netConfig.ChargeType,
|
||||
})
|
||||
}
|
||||
return nil, fmt.Errorf("No appropriate host virtual network...")
|
||||
|
||||
@@ -213,6 +213,8 @@ func (self *SVirtualizedGuestDriver) Attach2RandomNetwork(guest *models.SGuest,
|
||||
NicConfs: nicConfs,
|
||||
|
||||
IsDefault: netConfig.IsDefault,
|
||||
|
||||
ChargeType: netConfig.ChargeType,
|
||||
})
|
||||
return gn, err
|
||||
}
|
||||
|
||||
@@ -123,6 +123,10 @@ type SGuestnetwork struct {
|
||||
|
||||
// 端口映射
|
||||
PortMappings api.GuestPortMappings `length:"long" list:"user" update:"user"`
|
||||
|
||||
// 计费类型: 流量、带宽
|
||||
// example: bandwidth
|
||||
ChargeType string `width:"64" name:"charge_type" default:"bandwidth" list:"user" create:"optional"`
|
||||
}
|
||||
|
||||
func (gn SGuestnetwork) GetIP() string {
|
||||
@@ -275,6 +279,8 @@ type newGuestNetworkArgs struct {
|
||||
|
||||
virtual bool
|
||||
portMappings api.GuestPortMappings
|
||||
|
||||
chargeType string
|
||||
}
|
||||
|
||||
func (manager *SGuestnetworkManager) newGuestNetwork(
|
||||
@@ -323,6 +329,7 @@ func (manager *SGuestnetworkManager) newGuestNetwork(
|
||||
gn.BwLimit = bwLimit
|
||||
}
|
||||
gn.PortMappings = args.portMappings
|
||||
gn.ChargeType = args.chargeType
|
||||
|
||||
lockman.LockObject(ctx, network)
|
||||
defer lockman.ReleaseObject(ctx, network)
|
||||
@@ -978,7 +985,7 @@ func (gn *SGuestnetwork) LogDetachEvent(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
network = netTmp.(*SNetwork)
|
||||
}
|
||||
db.OpsLog.LogDetachEvent(ctx, guest, network, userCred, nil)
|
||||
db.OpsLog.LogDetachEvent(ctx, guest, network, userCred, gn.GetShortDesc(ctx))
|
||||
}
|
||||
|
||||
func (gn *SGuestnetwork) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
@@ -1276,6 +1283,10 @@ func (gn *SGuestnetwork) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
||||
if len(gn.TeamWith) > 0 {
|
||||
desc.TeamWith = gn.TeamWith
|
||||
}
|
||||
desc.BwLimitMbps = gn.getBandwidth()
|
||||
desc.Ifname = gn.Ifname
|
||||
desc.IsDefault = gn.IsDefault
|
||||
desc.ChargeType = gn.ChargeType
|
||||
return jsonutils.Marshal(desc).(*jsonutils.JSONDict)
|
||||
}
|
||||
|
||||
|
||||
@@ -3620,6 +3620,8 @@ type Attach2NetworkArgs struct {
|
||||
IsDefault bool
|
||||
PortMappings api.GuestPortMappings
|
||||
|
||||
ChargeType string
|
||||
|
||||
PendingUsage quotas.IQuota
|
||||
}
|
||||
|
||||
@@ -3652,6 +3654,8 @@ func (args *Attach2NetworkArgs) onceArgs(i int) attach2NetworkOnceArgs {
|
||||
|
||||
pendingUsage: args.PendingUsage,
|
||||
portMappings: args.PortMappings,
|
||||
|
||||
chargeType: args.ChargeType,
|
||||
}
|
||||
if i > 0 {
|
||||
r.ipAddr = ""
|
||||
@@ -3696,6 +3700,8 @@ type attach2NetworkOnceArgs struct {
|
||||
|
||||
pendingUsage quotas.IQuota
|
||||
portMappings api.GuestPortMappings
|
||||
|
||||
chargeType string
|
||||
}
|
||||
|
||||
func (self *SGuest) Attach2Network(
|
||||
@@ -3774,6 +3780,8 @@ func (self *SGuest) attach2NetworkOnce(
|
||||
|
||||
isDefault: args.isDefault,
|
||||
portMappings: args.portMappings,
|
||||
|
||||
chargeType: args.chargeType,
|
||||
}
|
||||
lockman.LockClass(ctx, QuotaManager, self.ProjectId)
|
||||
defer lockman.ReleaseClass(ctx, QuotaManager, self.ProjectId)
|
||||
@@ -3808,18 +3816,6 @@ func (self *SGuest) attach2NetworkOnce(
|
||||
return guestnic, nil
|
||||
}
|
||||
|
||||
type sRemoveGuestnic struct {
|
||||
nic *SGuestnetwork
|
||||
reserve bool
|
||||
}
|
||||
|
||||
type sAddGuestnic struct {
|
||||
index int
|
||||
nic cloudprovider.ICloudNic
|
||||
net *SNetwork
|
||||
reserve bool
|
||||
}
|
||||
|
||||
func getCloudNicNetwork(ctx context.Context, vnic cloudprovider.ICloudNic, host *SHost, ipList []string, index int) (*SNetwork, error) {
|
||||
vnetId := vnic.GetINetworkId()
|
||||
if len(vnetId) == 0 {
|
||||
@@ -4563,6 +4559,8 @@ func (self *SGuest) attach2NamedNetworkDesc(ctx context.Context, userCred mcclie
|
||||
|
||||
IsDefault: netConfig.IsDefault,
|
||||
PortMappings: netConfig.PortMappings,
|
||||
|
||||
ChargeType: netConfig.ChargeType,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Attach2Network fail")
|
||||
|
||||
Reference in New Issue
Block a user