Compare commits

...

14 Commits

Author SHA1 Message Date
Zexi Li
608c9f2a2b Merge pull request #10755 from yousong/automated-cherry-pick-of-#10750-upstream-release-3.3
Automated cherry pick of #10750: vpcagent: ovn: fix port match condition formation
2021-04-16 10:07:25 +08:00
Yousong Zhou
21328ceee2 vpcagent: ovn: fix port match condition formation 2021-04-15 16:11:13 +08:00
Zexi Li
aaaae7dc3d Merge pull request #10504 from yousong/automated-cherry-pick-of-#10499-upstream-release-3.3
Automated cherry pick of #10499: vpcagent: ovn: fix qos for eip upload
2021-03-26 15:18:30 +08:00
Yousong Zhou
25368f1656 vpcagent: ovn: fix qos for eip upload 2021-03-26 10:29:28 +08:00
Zexi Li
0c6d9547ce Merge pull request #9533 from swordqiu/automated-cherry-pick-of-#9529-upstream-release-3.3
Automated cherry pick of #9529: fix(taskman): use admin token if task userCred token expired
2020-12-20 02:06:27 +08:00
Qiu Jian
6767b62990 fix(taskman): use admin token if task userCred token expired
Use admin credential token if task cached userCred token expired
2020-12-20 01:23:10 +08:00
Zexi Li
ebe40ece45 Merge pull request #9520 from swordqiu/automated-cherry-pick-of-#9515-upstream-release-3.3
Automated cherry pick of #9515: fix(host): telegraf listen on local ipv4 address explicitly
2020-12-19 18:12:02 +08:00
Qiu Jian
baf63d7ecb fix(host): telegraf listen on local ipv4 address explicitly
Ensure telegraf listen on local IPv4 address explicityly and host send
metrics to telegraf local IPv4 address explicityly.
2020-12-19 15:42:56 +08:00
Zexi Li
5faac3fd76 Merge pull request #9430 from yousong/automated-cherry-pick-of-#9426-upstream-release-3.3
Automated cherry pick of #9426: fix(vpcagent): ovn: stable dns A record value
2020-12-15 11:45:34 +08:00
Yousong Zhou
bd544585ec fix(vpcagent): ovn: stable dns A record value 2020-12-15 11:11:08 +08:00
Zexi Li
daa7c71108 Merge pull request #9312 from yousong/automated-cherry-pick-of-#9311-upstream-release-3.3
Automated cherry pick of #9311: Automated cherry pick of #9308: Bugfix/yousong eip chargetype
2020-12-09 20:35:33 +08:00
Yousong Zhou
664f03a428 refactor(apis): compute: remove EIP_CHARGE_TYPE_DEFAULT
The default is now cloud provider specific
2020-12-09 12:28:27 +08:00
Yousong Zhou
7754064221 fix(region): sanitize eip charge type on all callsites 2020-12-09 12:28:27 +08:00
Yousong Zhou
25737f1a91 feat(region): regiondriver: add methods on eip charge type 2020-12-09 12:28:27 +08:00
11 changed files with 125 additions and 66 deletions

View File

@@ -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 (

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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 {

View File

@@ -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

View File

@@ -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")
}

View File

@@ -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
}

View File

@@ -38,7 +38,7 @@ import (
)
const (
TelegrafServer = "http://localhost:8087/write"
TelegrafServer = "http://127.0.0.1:8087/write"
MeasurementsPrefix = "vm_"
)

View File

@@ -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
}

View File

@@ -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{

View File

@@ -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 {