fix(region): avoid duplicate rule name for gcp (#18990)

This commit is contained in:
屈轩
2023-12-14 11:23:38 +08:00
committed by GitHub
parent 1f25fc17b8
commit ef5fee6c8b
9 changed files with 90 additions and 15 deletions
+2 -2
View File
@@ -88,14 +88,14 @@ require (
k8s.io/client-go v0.19.3
k8s.io/cluster-bootstrap v0.19.3
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231212091947-a835acfcd49b
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231214030214-0b69ef4c4315
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
yunion.io/x/pkg v1.0.1-0.20231101105448-abef64cdc142
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v1.1.3-0.20231204175132-1eb294922a51
yunion.io/x/sqlchemy v1.1.3-0.20231214015103-7a6c11418079
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
)
+4 -4
View File
@@ -1201,8 +1201,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231212091947-a835acfcd49b h1:NWaS4Av+8SDSCS5BnoNXQSKUv97mMvQlmj8DBEFdQh4=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231212091947-a835acfcd49b/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231214030214-0b69ef4c4315 h1:t0Et8SHWCT3FRC1TvGFK52t7ChsbfLySqXiqJj1z1I8=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231214030214-0b69ef4c4315/go.mod h1:aj1gR9PPb6eqqKOwvANe26CoZFY8ydmXy0fuvgKYXH0=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
@@ -1220,7 +1220,7 @@ yunion.io/x/pkg v1.0.1-0.20231101105448-abef64cdc142 h1:L6LqxfP08eWUx+A6yQdrL6VB
yunion.io/x/pkg v1.0.1-0.20231101105448-abef64cdc142/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v1.1.3-0.20231204175132-1eb294922a51 h1:FkfxuLB7KNhme9s+hoVa4TYhGFKSMUhBwHbCi4L4NQw=
yunion.io/x/sqlchemy v1.1.3-0.20231204175132-1eb294922a51/go.mod h1:uuPVZEyEq3sWd5vf9VjGSy6lZzof22X87OEHw9sddJQ=
yunion.io/x/sqlchemy v1.1.3-0.20231214015103-7a6c11418079 h1:NuDsQqqX13BjYkjZnPqZM32eQmjhtksM1H6b+g5TR2Y=
yunion.io/x/sqlchemy v1.1.3-0.20231214015103-7a6c11418079/go.mod h1:uuPVZEyEq3sWd5vf9VjGSy6lZzof22X87OEHw9sddJQ=
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c h1:QuLab2kSRECZRxo4Lo2KcYn6XjQFDGaZ1+x0pYDVVwQ=
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
+2 -2
View File
@@ -1465,7 +1465,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231212091947-a835acfcd49b
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231214030214-0b69ef4c4315
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
@@ -1623,7 +1623,7 @@ yunion.io/x/pkg/utils
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
## explicit; go 1.12
yunion.io/x/s3cli
# yunion.io/x/sqlchemy v1.1.3-0.20231204175132-1eb294922a51
# yunion.io/x/sqlchemy v1.1.3-0.20231214015103-7a6c11418079
## explicit; go 1.17
yunion.io/x/sqlchemy
yunion.io/x/sqlchemy/backends
+6
View File
@@ -144,6 +144,7 @@ const (
// 阿拉伯联合酋长国
CITY_DUBAI = "Dubai" //迪拜
CITY_DAMMAN = "Damman" //达曼
CITY_ABU_DHABI = "Abu Dhabi" // 阿布扎比
// 德国
@@ -213,10 +214,14 @@ const (
// 意大利
CITY_MILAN = "Milan" // 米兰
CITY_TURIN = "Turin" // 都灵
// 西班牙
CITY_MADRID = "Madrid" // 马德里
// 卡塔尔
CITY_DOHA = "Doha" // 多哈
COUNTRY_CODE_CN = "CN" //中国
COUNTRY_CODE_JP = "JP" //日本
COUNTRY_CODE_SG = "SG" //新加坡
@@ -251,4 +256,5 @@ const (
COUNTRY_CODE_IL = "IL" //以色列
COUNTRY_CODE_IT = "IT" //意大利
COUNTRY_CODE_ES = "ES" //西班牙
COUNTRY_CODE_QA = "QA" //卡塔尔
)
+18
View File
@@ -494,6 +494,12 @@ var (
City: CITY_PARIS,
CountryCode: COUNTRY_CODE_FR,
}
RegionTurin = cloudprovider.SGeographicInfo{
Latitude: 45.07,
Longitude: 7.63,
City: CITY_TURIN,
CountryCode: COUNTRY_CODE_IT,
}
RegionAllier = cloudprovider.SGeographicInfo{
Latitude: 46.518,
Longitude: 3.359,
@@ -701,6 +707,18 @@ var (
City: CITY_TEL_AVIV,
CountryCode: COUNTRY_CODE_IL,
}
RegionDamman = cloudprovider.SGeographicInfo{
Latitude: 26.36,
Longitude: 49.91,
City: CITY_DAMMAN,
CountryCode: COUNTRY_CODE_AE,
}
RegionDoha = cloudprovider.SGeographicInfo{
Latitude: 25.28,
Longitude: 51.43,
City: CITY_DOHA,
CountryCode: COUNTRY_CODE_QA,
}
RegionNorthCalifornia = cloudprovider.SGeographicInfo{
Latitude: 38.838,
Longitude: -120.896,
@@ -42,6 +42,8 @@ var LatitudeAndLongitude = map[string]cloudprovider.SGeographicInfo{
"europe-west9": api.RegionParis,
"europe-central2": api.RegionWarsaw,
"europe-southwest1": api.RegionMadrid,
"europe-west10": api.RegionDublin,
"europe-west12": api.RegionTurin,
"northamerica-northeast1": api.RegionMontreal,
"northamerica-northeast2": api.RegionToronto,
@@ -57,7 +59,9 @@ var LatitudeAndLongitude = map[string]cloudprovider.SGeographicInfo{
"us-south1": api.RegionDallas,
"southamerica-west1": api.RegionSantiago,
"me-west1": api.RegionColumbus,
"me-west1": api.RegionColumbus,
"me-central1": api.RegionDoha,
"me-central2": api.RegionDamman,
}
var RegionNames = map[string]string{
@@ -81,6 +85,8 @@ var RegionNames = map[string]string{
"europe-west6": "苏黎世",
"europe-west8": "米兰",
"europe-west9": "巴黎",
"europe-west10": "柏林",
"europe-west12": "都灵",
"europe-central2": "华沙",
"europe-southwest1": "马德里",
@@ -98,7 +104,9 @@ var RegionNames = map[string]string{
"us-west4": "拉斯维加斯",
"us-south1": "达拉斯",
"me-west1": "特拉维夫",
"me-west1": "特拉维夫",
"me-central1": "多哈",
"me-central2": "达曼",
// Multi-region
"us": "美国的多区域",
+2 -1
View File
@@ -17,6 +17,7 @@ package google
import (
"fmt"
"strings"
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
@@ -121,7 +122,7 @@ func (self *SSecurityGroup) GetRules() ([]cloudprovider.ISecurityGroupRule, erro
}
func (self *SGoogleClient) CreateSecurityGroupRule(globalnetworkId, tag string, opts *cloudprovider.SecurityGroupRuleCreateOptions) (*SFirewall, error) {
name := fmt.Sprintf("%s-%d", opts.String(), opts.Priority)
name := fmt.Sprintf("%s-%d-auto-%d", opts.String(), opts.Priority, time.Now().Unix())
body := map[string]interface{}{
"name": strings.ToLower(name),
"description": opts.Desc,
+36
View File
@@ -21,6 +21,26 @@ import (
"yunion.io/x/pkg/util/reflectutils"
)
type sNoop struct{}
var noop = &sNoop{}
func (s sNoop) WhereClause() string {
return ""
}
func (s sNoop) Variables() []interface{} {
return nil
}
func (s sNoop) database() *SDatabase {
return nil
}
func Noop() ICondition {
return noop
}
// ICondition is the interface representing a condition for SQL query
// e.g. WHERE a1 = b1 is a condition of equal
// the condition support nested condition, with AND, OR and NOT boolean operators
@@ -104,6 +124,9 @@ func (c *SOrConditions) WhereClause() string {
func AND(cond ...ICondition) ICondition {
conds := make([]ICondition, 0)
for _, c := range cond {
if c == nil || c == noop {
continue
}
andCond, ok := c.(*SAndConditions)
if ok {
conds = append(conds, andCond.conditions...)
@@ -119,6 +142,10 @@ func AND(cond ...ICondition) ICondition {
func OR(cond ...ICondition) ICondition {
conds := make([]ICondition, 0)
for _, c := range cond {
if c == nil || c == noop {
conds = conds[0:0]
break
}
orCond, ok := c.(*SOrConditions)
if ok {
conds = append(conds, orCond.conditions...)
@@ -137,16 +164,25 @@ type SNotCondition struct {
// WhereClause implementationq of SNotCondition for ICondition
func (c *SNotCondition) WhereClause() string {
if c.condition == nil || c.condition == noop {
return "1!=1"
}
return fmt.Sprintf("%s (%s)", SQL_OP_NOT, c.condition.WhereClause())
}
// Variables implementation of SNotCondition for ICondition
func (c *SNotCondition) Variables() []interface{} {
if c.condition == nil {
return nil
}
return c.condition.Variables()
}
// database implementation of SNotCondition for ICondition
func (c *SNotCondition) database() *SDatabase {
if c.condition == nil {
return nil
}
return c.condition.database()
}
+10 -4
View File
@@ -129,12 +129,18 @@ func queryString(tq *SQuery, tmpFields ...IQueryField) string {
buf.WriteString(string(join.jointype))
buf.WriteByte(' ')
buf.WriteString(fmt.Sprintf("%s AS `%s`", join.from.Expression(), join.from.Alias()))
buf.WriteString(" ON ")
buf.WriteString(join.condition.WhereClause())
whereCls := join.condition.WhereClause()
if len(whereCls) > 0 {
buf.WriteString(" ON ")
buf.WriteString(whereCls)
}
}
if tq.where != nil {
buf.WriteString(" WHERE ")
buf.WriteString(tq.where.WhereClause())
whereCls := tq.where.WhereClause()
if len(whereCls) > 0 {
buf.WriteString(" WHERE ")
buf.WriteString(whereCls)
}
}
if tq.groupBy != nil && len(tq.groupBy) > 0 {
buf.WriteString(" GROUP BY ")