Skip to content

Commit

Permalink
fix: network address details compatible with dameng (#19686)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiu Jian <[email protected]>
  • Loading branch information
swordqiu and Qiu Jian authored Mar 9, 2024
1 parent 2920a15 commit 41f21ff
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ require (
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
yunion.io/x/pkg v1.10.1-0.20240303050651-73685b15a96e
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v1.1.3-0.20240309051602-9ab0cc051bcc
yunion.io/x/sqlchemy v1.1.3-0.20240309151155-b34f29f02c79
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ yunion.io/x/pkg v1.10.1-0.20240303050651-73685b15a96e h1:NuYu+z0dOT93aoNjg3W3PkL
yunion.io/x/pkg v1.10.1-0.20240303050651-73685b15a96e/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.20240309051602-9ab0cc051bcc h1:aoz/hVPigGxG/fGCpDmC3Wi57/yDbbGQO7T5SGj6l4c=
yunion.io/x/sqlchemy v1.1.3-0.20240309051602-9ab0cc051bcc/go.mod h1:5W8ghvJ4TNt/r2yDjjD3i4QsZgIiJX45dhRQBGWPHsQ=
yunion.io/x/sqlchemy v1.1.3-0.20240309151155-b34f29f02c79 h1:tY92xg+5hdsvVaqPpC1J/6LV9mDaeOBWbkxZkazwOLQ=
yunion.io/x/sqlchemy v1.1.3-0.20240309151155-b34f29f02c79/go.mod h1:5W8ghvJ4TNt/r2yDjjD3i4QsZgIiJX45dhRQBGWPHsQ=
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=
8 changes: 6 additions & 2 deletions pkg/compute/models/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,7 @@ func (network *SNetwork) PerformChangeOwner(ctx context.Context, userCred mcclie
}

func (network *SNetwork) getUsedAddressQuery(ctx context.Context, userCred mcclient.TokenCredential, owner mcclient.IIdentityProvider, scope rbacscope.TRbacScope, addrOnly bool) *sqlchemy.SQuery {
usedAddressQueryProviders := getUsedAddressQueryProviders()
var (
args = &usedAddressQueryArgs{
network: network,
Expand All @@ -3377,12 +3378,14 @@ func (network *SNetwork) getUsedAddressQuery(ctx context.Context, userCred mccli
)

for _, provider := range usedAddressQueryProviders {
queries = append(queries, provider.usedAddressQuery(ctx, args))
q := provider.usedAddressQuery(ctx, args)
queries = append(queries, q)
}
return sqlchemy.Union(queries...).Query()
}

func (network *SNetwork) getUsedAddressQuery6(ctx context.Context, userCred mcclient.TokenCredential, owner mcclient.IIdentityProvider, scope rbacscope.TRbacScope, addrOnly bool) *sqlchemy.SQuery {
usedAddress6QueryProviders := getUsedAddress6QueryProviders()
var (
args = &usedAddressQueryArgs{
network: network,
Expand All @@ -3396,7 +3399,8 @@ func (network *SNetwork) getUsedAddressQuery6(ctx context.Context, userCred mccl
)

for _, provider := range usedAddress6QueryProviders {
queries = append(queries, provider.usedAddressQuery(ctx, args))
q := provider.usedAddressQuery(ctx, args)
queries = append(queries, q)
}
return sqlchemy.Union(queries...).Query()
}
Expand Down
33 changes: 19 additions & 14 deletions pkg/compute/models/networks_used_addresses_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,29 @@ type usedAddressQueryArgs struct {
}

type usedAddressQueryProvider interface {
KeywordPlural() string
usedAddressQuery(ctx context.Context, args *usedAddressQueryArgs) *sqlchemy.SQuery
}

var usedAddressQueryProviders = []usedAddressQueryProvider{
GuestnetworkManager,
HostnetworkManager,
ReservedipManager,
GroupnetworkManager,
LoadbalancernetworkManager,
ElasticipManager,
NetworkinterfacenetworkManager,
DBInstanceManager,
NetworkAddressManager,
func getUsedAddressQueryProviders() []usedAddressQueryProvider {
return []usedAddressQueryProvider{
GuestnetworkManager,
HostnetworkManager,
ReservedipManager,
GroupnetworkManager,
LoadbalancernetworkManager,
ElasticipManager,
NetworkinterfacenetworkManager,
DBInstanceManager,
NetworkAddressManager,
}
}

var usedAddress6QueryProviders = []usedAddressQueryProvider{
GuestnetworkManager,
ReservedipManager,
func getUsedAddress6QueryProviders() []usedAddressQueryProvider {
return []usedAddressQueryProvider{
GuestnetworkManager,
ReservedipManager,
}
}

func (manager *SGuestnetworkManager) usedAddressQuery(ctx context.Context, args *usedAddressQueryArgs) *sqlchemy.SQuery {
Expand Down Expand Up @@ -143,7 +148,7 @@ func (manager *SReservedipManager) usedAddressQuery(ctx context.Context, args *u
fields = append(fields,
sqlchemy.NewStringField("").Label("mac_addr"),
sqlchemy.NewStringField(ReservedipManager.KeywordPlural()).Label("owner_type"),
baseq.Field("id").Label("owner_id"),
sqlchemy.CASTString(baseq.Field("id"), "owner_id"),
baseq.Field("status").Label("owner_status"),
baseq.Field("notes").Label("owner"),
sqlchemy.NewStringField("").Label("associate_id"),
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,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.20240309051602-9ab0cc051bcc
# yunion.io/x/sqlchemy v1.1.3-0.20240309151155-b34f29f02c79
## explicit; go 1.17
yunion.io/x/sqlchemy
yunion.io/x/sqlchemy/backends
Expand Down
10 changes: 9 additions & 1 deletion vendor/yunion.io/x/sqlchemy/backends.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/yunion.io/x/sqlchemy/backends/clickhouse/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/yunion.io/x/sqlchemy/backends/dameng/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/yunion.io/x/sqlchemy/backends/mysql/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/yunion.io/x/sqlchemy/backends/sqlite/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/yunion.io/x/sqlchemy/backends_base.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/yunion.io/x/sqlchemy/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 41f21ff

Please sign in to comment.