mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-21 00:24:07 +08:00
Compare commits
14 Commits
v3.3.8
...
release/3.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
608c9f2a2b | ||
|
|
21328ceee2 | ||
|
|
aaaae7dc3d | ||
|
|
25368f1656 | ||
|
|
0c6d9547ce | ||
|
|
6767b62990 | ||
|
|
ebe40ece45 | ||
|
|
baf63d7ecb | ||
|
|
5faac3fd76 | ||
|
|
bd544585ec | ||
|
|
daa7c71108 | ||
|
|
664f03a428 | ||
|
|
7754064221 | ||
|
|
25737f1a91 |
@@ -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 (
|
||||
|
||||
@@ -41,6 +41,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
)
|
||||
@@ -788,7 +789,11 @@ func (self *STask) GetObjects() []db.IStandaloneModel {
|
||||
}
|
||||
|
||||
func (task *STask) GetTaskRequestHeader() http.Header {
|
||||
header := mcclient.GetTokenHeaders(task.GetUserCred())
|
||||
userCred := task.GetUserCred()
|
||||
if !userCred.IsValid() {
|
||||
userCred = auth.AdminCredential()
|
||||
}
|
||||
header := mcclient.GetTokenHeaders(userCred)
|
||||
header.Set(mcclient.TASK_ID, task.GetTaskId())
|
||||
return header
|
||||
}
|
||||
|
||||
@@ -799,14 +799,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}) {
|
||||
@@ -818,7 +821,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
|
||||
}
|
||||
@@ -1218,9 +1221,13 @@ func (self *SElasticip) getMoreDetails(out api.ElasticipDetails) api.ElasticipDe
|
||||
func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCred mcclient.TokenCredential, vm *SGuest,
|
||||
host *SHost, bw int, chargeType string, autoDellocate bool, pendingUsage quotas.IQuota) (*SElasticip, error) {
|
||||
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{}
|
||||
@@ -1238,7 +1245,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()
|
||||
|
||||
@@ -2939,10 +2939,18 @@ 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
|
||||
autoDellocate bool
|
||||
)
|
||||
chargeType, _ = data.GetString("charge_type")
|
||||
if chargeType == "" {
|
||||
chargeType = regionDriver.GetEipDefaultChargeType()
|
||||
}
|
||||
|
||||
bw, _ = data.Int("bandwidth")
|
||||
@@ -2951,24 +2959,7 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke
|
||||
return nil, httperrors.NewMissingParameterError("bandwidth")
|
||||
}
|
||||
}
|
||||
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???")
|
||||
}
|
||||
}
|
||||
autoDellocate, _ = data.Bool("auto_dellocate")
|
||||
|
||||
err := self.GetDriver().ValidateCreateEip(ctx, userCred, data)
|
||||
if err != nil {
|
||||
|
||||
@@ -87,6 +87,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
|
||||
|
||||
@@ -893,7 +893,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
|
||||
}
|
||||
if len(input.NetworkId) == 0 {
|
||||
return httperrors.NewMissingParameterError("network_id")
|
||||
}
|
||||
|
||||
@@ -1099,7 +1099,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
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TelegrafServer = "http://localhost:8087/write"
|
||||
TelegrafServer = "http://127.0.0.1:8087/write"
|
||||
MeasurementsPrefix = "vm_"
|
||||
)
|
||||
|
||||
|
||||
@@ -15,8 +15,13 @@
|
||||
package system_service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
)
|
||||
|
||||
type STelegraf struct {
|
||||
@@ -162,7 +167,7 @@ func (s *STelegraf) GetConfig(kwargs map[string]interface{}) string {
|
||||
conf += " collect_memstats = false\n"
|
||||
conf += "\n"
|
||||
conf += "[[inputs.http_listener]]\n"
|
||||
conf += " service_address = \"localhost:8087\"\n"
|
||||
conf += " service_address = \"127.0.0.1:8087\"\n"
|
||||
conf += "\n"
|
||||
return conf
|
||||
}
|
||||
@@ -180,5 +185,26 @@ func (s *STelegraf) BgReload(kwargs map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (s *STelegraf) BgReloadConf(kwargs map[string]interface{}) {
|
||||
go s.reloadConf(s.GetConfig(kwargs), s.GetConfigFile())
|
||||
go func() {
|
||||
reload, err := s.reloadConf(s.GetConfig(kwargs), s.GetConfigFile())
|
||||
if err != nil {
|
||||
log.Errorf("Failed reload conf: %s", err)
|
||||
}
|
||||
if reload {
|
||||
err := s.ReloadTelegraf()
|
||||
if err != nil {
|
||||
log.Errorf("failed reload telegraf: %s", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *STelegraf) ReloadTelegraf() error {
|
||||
log.Infof("Start reolad telegraf...")
|
||||
telegrafReoladUrl := "http://127.0.0.1:8087/reload"
|
||||
_, _, err := httputils.JSONRequest(
|
||||
httputils.GetDefaultClient(), context.Background(),
|
||||
"POST", telegrafReoladUrl, nil, nil, false,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package ovn
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/log"
|
||||
@@ -418,7 +419,7 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
|
||||
ocGnrDefaultRef = fmt.Sprintf("gnrDefault/%s/%s/%s", vpc.Id, guestnetwork.GuestId, guestnetwork.Ifname)
|
||||
ocAclRef = fmt.Sprintf("acl/%s/%s/%s", network.Id, guestnetwork.GuestId, guestnetwork.Ifname)
|
||||
ocQosRef = fmt.Sprintf("qos/%s/%s/%s", network.Id, guestnetwork.GuestId, guestnetwork.Ifname)
|
||||
ocQosEipRef = fmt.Sprintf("qos-eip/%s/%s/%s", vpc.Id, guestnetwork.GuestId, guestnetwork.Ifname)
|
||||
ocQosEipRef = fmt.Sprintf("qos-eip/%s/%s/%s/v2", vpc.Id, guestnetwork.GuestId, guestnetwork.Ifname)
|
||||
dhcpOpt string
|
||||
)
|
||||
|
||||
@@ -503,7 +504,9 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
|
||||
|
||||
var (
|
||||
gnrDefault *ovn_nb.LogicalRouterStaticRoute
|
||||
qosEip []*ovn_nb.QoS
|
||||
qosEipIn *ovn_nb.QoS
|
||||
qosEipOut *ovn_nb.QoS
|
||||
hasQoSEip bool
|
||||
)
|
||||
{
|
||||
gnrDefaultPolicy := "src-ip"
|
||||
@@ -523,30 +526,29 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
|
||||
kbur = int64(kbps * 2)
|
||||
eipgwVip = apis.VpcEipGatewayIP3().String()
|
||||
)
|
||||
qosEip = []*ovn_nb.QoS{
|
||||
&ovn_nb.QoS{
|
||||
Priority: 2000,
|
||||
Direction: "from-lport",
|
||||
Match: fmt.Sprintf("inport == %q && ip4 && ip4.dst == %s", vpcEipLspName(vpc.Id, eipgwVip), guestnetwork.IpAddr),
|
||||
Bandwidth: map[string]int64{
|
||||
"rate": kbps,
|
||||
"burst": kbur,
|
||||
},
|
||||
ExternalIds: map[string]string{
|
||||
externalKeyOcRef: ocQosEipRef,
|
||||
},
|
||||
hasQoSEip = true
|
||||
qosEipIn = &ovn_nb.QoS{
|
||||
Priority: 2000,
|
||||
Direction: "from-lport",
|
||||
Match: fmt.Sprintf("inport == %q && ip4 && ip4.dst == %s", vpcEipLspName(vpc.Id, eipgwVip), guestnetwork.IpAddr),
|
||||
Bandwidth: map[string]int64{
|
||||
"rate": kbps,
|
||||
"burst": kbur,
|
||||
},
|
||||
&ovn_nb.QoS{
|
||||
Priority: 3000,
|
||||
Direction: "from-lport",
|
||||
Match: fmt.Sprintf("inport == %q", lportName),
|
||||
Bandwidth: map[string]int64{
|
||||
"rate": kbps,
|
||||
"burst": kbur,
|
||||
},
|
||||
ExternalIds: map[string]string{
|
||||
externalKeyOcRef: ocQosEipRef,
|
||||
},
|
||||
ExternalIds: map[string]string{
|
||||
externalKeyOcRef: ocQosEipRef,
|
||||
},
|
||||
}
|
||||
qosEipOut = &ovn_nb.QoS{
|
||||
Priority: 3000,
|
||||
Direction: "from-lport",
|
||||
Match: fmt.Sprintf("inport == %q", lportName),
|
||||
Bandwidth: map[string]int64{
|
||||
"rate": kbps,
|
||||
"burst": kbur,
|
||||
},
|
||||
ExternalIds: map[string]string{
|
||||
externalKeyOcRef: ocQosEipRef,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -592,8 +594,8 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
|
||||
for _, qos := range qosVif {
|
||||
irows = append(irows, qos)
|
||||
}
|
||||
for _, qos := range qosEip {
|
||||
irows = append(irows, qos)
|
||||
if hasQoSEip {
|
||||
irows = append(irows, qosEipIn, qosEipOut)
|
||||
}
|
||||
allFound, args := cmp(&keeper.DB, ocVersion, irows...)
|
||||
if allFound {
|
||||
@@ -616,10 +618,11 @@ func (keeper *OVNNorthboundKeeper) ClaimGuestnetwork(ctx context.Context, guestn
|
||||
args = append(args, ovnCreateArgs(qos, ref)...)
|
||||
args = append(args, "--", "add", "Logical_Switch", netLsName(guestnetwork.NetworkId), "qos_rules", "@"+ref)
|
||||
}
|
||||
for i, qos := range qosEip {
|
||||
ref := fmt.Sprintf("qosEip%d", i)
|
||||
args = append(args, ovnCreateArgs(qos, ref)...)
|
||||
args = append(args, "--", "add", "Logical_Switch", vpcEipLsName(vpc.Id), "qos_rules", "@"+ref)
|
||||
if hasQoSEip {
|
||||
args = append(args, ovnCreateArgs(qosEipIn, "qosEipIn")...)
|
||||
args = append(args, "--", "add", "Logical_Switch", vpcEipLsName(vpc.Id), "qos_rules", "@qosEipIn")
|
||||
args = append(args, ovnCreateArgs(qosEipOut, "qosEipOut")...)
|
||||
args = append(args, "--", "add", "Logical_Switch", netLsName(guestnetwork.NetworkId), "qos_rules", "@qosEipOut")
|
||||
}
|
||||
return keeper.cli.Must(ctx, "ClaimGuestnetwork", args)
|
||||
}
|
||||
@@ -654,6 +657,7 @@ func (keeper *OVNNorthboundKeeper) ClaimVpcGuestDnsRecords(ctx context.Context,
|
||||
ocVersion = fmt.Sprintf("%s.%d", vpc.Id, vpc.UpdateVersion)
|
||||
)
|
||||
for name, addrs := range grs {
|
||||
sort.Strings(addrs)
|
||||
grs_[name] = strings.Join(addrs, " ")
|
||||
}
|
||||
dns := &ovn_nb.DNS{
|
||||
|
||||
@@ -121,7 +121,11 @@ func ruleToAcl(lport string, rule *agentmodels.SecurityGroupRule) (*ovn_nb.ACL,
|
||||
|
||||
matches = append(matches, l4proto)
|
||||
if len(portMatches) > 0 {
|
||||
matches = append(matches, strings.Join(portMatches, " || "))
|
||||
portMatch := strings.Join(portMatches, " || ")
|
||||
if len(portMatches) > 1 {
|
||||
portMatch = "( " + portMatch + " )"
|
||||
}
|
||||
matches = append(matches, portMatch)
|
||||
}
|
||||
}
|
||||
switch rule.Protocol {
|
||||
|
||||
Reference in New Issue
Block a user