Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support server change ipv6 address #22014

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ 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.20250108102615-91c94132ea67
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250113015525-b483c92621d7
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256
yunion.io/x/jsonutils v1.0.1-0.20240930100528-1671a2d0d22f
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
yunion.io/x/pkg v1.10.3
yunion.io/x/pkg v1.10.4-0.20250123070256-9247ce856f07
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1
yunion.io/x/sqlchemy v1.1.3-0.20240926163039-d41512b264e1
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,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.20250108102615-91c94132ea67 h1:qwsHylZfRz4l/9GxE57nYalsnQ/U7hRiDy00gsaYLds=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250108102615-91c94132ea67/go.mod h1:KQ/jWx7bZlmjCE711KEWuvHW/dzpdr/UTlBjjutkj0Y=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250113015525-b483c92621d7 h1:f3j4AHOANU1rDyHmXpPdmVklpL1NFODhcYXDXtt5gOE=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250113015525-b483c92621d7/go.mod h1:KQ/jWx7bZlmjCE711KEWuvHW/dzpdr/UTlBjjutkj0Y=
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256 h1:kLKQ6zbgPDQflRwoHFAjxNChcbhXIFgsUVLkJwiXu/8=
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
Expand All @@ -1289,8 +1289,8 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v1.10.3 h1:oaJAtMSIwASgF6jB/0W37iOQBLh6ICswfPL3ISnRZC4=
yunion.io/x/pkg v1.10.3/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
yunion.io/x/pkg v1.10.4-0.20250123070256-9247ce856f07 h1:XZsL8+YpgVBHMcRwdpZ4cOfSZCc+KsgUCTdV3KeK8FI=
yunion.io/x/pkg v1.10.4-0.20250123070256-9247ce856f07/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1 h1:1KJ3YYinydPHpDEQRXdr/T8SYcKZ5Er+m489H+PnaQ4=
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v1.1.3-0.20240926163039-d41512b264e1 h1:HWPqY1I5JSmM6Sks6FyK9hnq/MjL7FDghM6M8DXHob0=
Expand Down
38 changes: 27 additions & 11 deletions pkg/cloudcommon/cmdline/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,27 @@ func ParseNetworkConfigByJSON(desc jsonutils.JSONObject, idx int) (*compute.Netw
return conf, err
}

func isQuoteChar(ch byte) (bool, string) {
switch ch {
case '[':
return true, "]"
default:
return false, ""
}
}

func splitConfig(confStr string) ([]string, error) {
return utils.FindWords2([]byte(confStr), 0, ":", isQuoteChar)
}

func ParseNetworkConfig(desc string, idx int) (*compute.NetworkConfig, error) {
if len(desc) == 0 {
return nil, ErrorEmptyDesc
}
parts := strings.Split(desc, ":")
parts, err := splitConfig(desc)
if err != nil {
return nil, errors.Wrap(err, "splitConfig")
}
netConfig := new(compute.NetworkConfig)
netConfig.Index = idx
for _, p := range parts {
Expand Down Expand Up @@ -283,23 +299,23 @@ func ParseNetworkConfig(desc string, idx int) (*compute.NetworkConfig, error) {
}
netConfig.Addresses6[i] = addr6.String()
}
} else if p == "[require_designated_ip]" {
} else if p == "require_designated_ip" {
netConfig.RequireDesignatedIP = true
} else if p == "[random_exit]" {
} else if p == "random_exit" {
netConfig.Exit = true
} else if p == "[random]" {
} else if p == "random" {
netConfig.Exit = false
} else if p == "[private]" {
} else if p == "private" {
netConfig.Private = true
} else if p == "[reserved]" {
} else if p == "reserved" {
netConfig.Reserved = true
} else if p == "[teaming]" {
} else if p == "teaming" {
netConfig.RequireTeaming = true
} else if p == "[try-teaming]" {
} else if p == "try-teaming" {
netConfig.TryTeaming = true
} else if p == "[defaultgw]" {
} else if p == "defaultgw" {
netConfig.IsDefault = true
} else if p == "[ipv6]" {
} else if p == "ipv6" {
netConfig.RequireIPv6 = true
} else if strings.HasPrefix(p, "standby-port=") {
netConfig.StandbyPortCount, _ = strconv.Atoi(p[len("standby-port="):])
Expand All @@ -315,7 +331,7 @@ func ParseNetworkConfig(desc string, idx int) (*compute.NetworkConfig, error) {
return nil, err
}
netConfig.BwLimit = bw
} else if p == "[vip]" {
} else if p == "vip" {
netConfig.Vip = true
} else if strings.HasPrefix(p, "sriov-nic-id=") {
netConfig.SriovDevice = &compute.IsolatedDeviceConfig{
Expand Down
65 changes: 65 additions & 0 deletions pkg/cloudcommon/cmdline/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,68 @@ func TestParseBaremetalRootDiskMatcher(t *testing.T) {
})
}
}

func TestParseNetworkConfig(t *testing.T) {
tests := []struct {
args string
want *compute.NetworkConfig
}{
{
args: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
want: &compute.NetworkConfig{Network: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94"},
},
{
args: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94:172.22.121.12",
want: &compute.NetworkConfig{
Network: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
Address: "172.22.121.12",
},
},
{
args: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94:172.22.121.12:[fd:3ffe:3200:90::2]",
want: &compute.NetworkConfig{
Network: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
Address: "172.22.121.12",
Address6: "fd:3ffe:3200:90::2",
},
},
{
args: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94:172.22.121.12:[fd:3ffe:3200:90::2]:[teaming]",
want: &compute.NetworkConfig{
Network: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
Address: "172.22.121.12",
Address6: "fd:3ffe:3200:90::2",
RequireTeaming: true,
},
},
{
args: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94:172.22.121.12:[fd:3ffe:3200:90::2]:wire=77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
want: &compute.NetworkConfig{
Network: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
Address: "172.22.121.12",
Address6: "fd:3ffe:3200:90::2",
Wire: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
},
},
{
args: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94:172.22.121.12:[fd:3ffe:3200:90::2]:wire=77a7d3a7-022d-4b48-8bb6-e37ea3a20c94:[try-teaming]",
want: &compute.NetworkConfig{
Network: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
Address: "172.22.121.12",
Address6: "fd:3ffe:3200:90::2",
Wire: "77a7d3a7-022d-4b48-8bb6-e37ea3a20c94",
TryTeaming: true,
},
},
}
for _, tt := range tests {
t.Run(tt.args, func(t *testing.T) {
got, err := ParseNetworkConfig(tt.args, 0)
if err != nil {
t.Errorf("ParseNetworkConfig %s fail %s", tt.args, err)
} else if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseNetworkConfig() got = %v, want %v", got, tt.want)
}
})
}
}
6 changes: 5 additions & 1 deletion pkg/compute/models/guest_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,11 @@ func (self *SGuest) PerformChangeIpaddr(
if input.NetConf != nil {
conf = input.NetConf
} else if len(input.NetDesc) > 0 {
netConf, err := cmdline.ParseNetworkConfigByJSON(jsonutils.NewString(input.NetDesc), -1)
netDescJson, err := jsonutils.ParseString(input.NetDesc)
if err != nil {
netDescJson = jsonutils.NewString(input.NetDesc)
}
netConf, err := cmdline.ParseNetworkConfigByJSON(netDescJson, -1)
if err != nil {
return nil, httperrors.NewInputParameterError("fail to parse net_desc %s: %s", input.NetDesc, err)
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,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.20250108102615-91c94132ea67
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250113015525-b483c92621d7
## explicit; go 1.21
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
Expand Down Expand Up @@ -1671,7 +1671,7 @@ yunion.io/x/log/hooks
yunion.io/x/ovsdb/cli_util
yunion.io/x/ovsdb/schema/ovn_nb
yunion.io/x/ovsdb/types
# yunion.io/x/pkg v1.10.3
# yunion.io/x/pkg v1.10.4-0.20250123070256-9247ce856f07
## explicit; go 1.18
yunion.io/x/pkg/appctx
yunion.io/x/pkg/errors
Expand Down
30 changes: 19 additions & 11 deletions vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/instances.go

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

22 changes: 22 additions & 0 deletions vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/region.go

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

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

Loading
Loading