Skip to content

Commit

Permalink
Feature/qj ipv6 support (#19249)
Browse files Browse the repository at this point in the history
* feature: ipv6 support

* fix: ipv6 support more

* fix: update vendor for ipv6 support

* fix: allow enable ipv6 on existing guestnetwork

---------

Co-authored-by: Qiu Jian <[email protected]>
  • Loading branch information
swordqiu and Qiu Jian authored Jan 15, 2024
1 parent b78db4e commit c7d79f5
Show file tree
Hide file tree
Showing 71 changed files with 3,214 additions and 1,119 deletions.
72 changes: 14 additions & 58 deletions cmd/climc/shell/compute/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {

cmd := shell.NewResourceCmd(&modules.Networks).WithContextManager(&modules.Wires)
cmd.List(&compute_options.NetworkListOptions{})
cmd.Create(&compute_options.NetworkCreateOptions{})
cmd.Update(&compute_options.NetworkUpdateOptions{})
cmd.Show(&compute_options.NetworkIdOptions{})
cmd.Delete(&compute_options.NetworkIdOptions{})
Expand Down Expand Up @@ -62,65 +63,15 @@ func init() {
return nil
})

type NetworkCreateOptions struct {
WIRE string `help:"ID or Name of wire in which the network is created"`
NETWORK string `help:"Name of new network"`
STARTIP string `help:"Start of IPv4 address range"`
ENDIP string `help:"End of IPv4 address rnage"`
NETMASK int64 `help:"Length of network mask"`
Gateway string `help:"Default gateway"`
VlanId int64 `help:"Vlan ID" default:"1"`
IfnameHint string `help:"Hint for ifname generation"`
AllocPolicy string `help:"Address allocation policy" choices:"none|stepdown|stepup|random"`
ServerType string `help:"Server type" choices:"baremetal|container|eip|guest|ipmi|pxe"`
IsAutoAlloc *bool `help:"Auto allocation IP pool"`
BgpType string `help:"Internet service provider name" positional:"false"`
Desc string `help:"Description" metavar:"DESCRIPTION"`
}
R(&NetworkCreateOptions{}, "network-create", "Create a virtual network", func(s *mcclient.ClientSession, args *NetworkCreateOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.NETWORK), "name")
params.Add(jsonutils.NewString(args.STARTIP), "guest_ip_start")
params.Add(jsonutils.NewString(args.ENDIP), "guest_ip_end")
params.Add(jsonutils.NewInt(args.NETMASK), "guest_ip_mask")
if len(args.Gateway) > 0 {
params.Add(jsonutils.NewString(args.Gateway), "guest_gateway")
}
if args.VlanId > 0 {
params.Add(jsonutils.NewInt(args.VlanId), "vlan_id")
}
if len(args.ServerType) > 0 {
params.Add(jsonutils.NewString(args.ServerType), "server_type")
}
if len(args.IfnameHint) > 0 {
params.Add(jsonutils.NewString(args.IfnameHint), "ifname_hint")
}
if len(args.AllocPolicy) > 0 {
params.Add(jsonutils.NewString(args.AllocPolicy), "alloc_policy")
}
if len(args.Desc) > 0 {
params.Add(jsonutils.NewString(args.Desc), "description")
}
if len(args.BgpType) > 0 {
params.Add(jsonutils.NewString(args.BgpType), "bgp_type")
}
if args.IsAutoAlloc != nil {
params.Add(jsonutils.NewBool(*args.IsAutoAlloc), "is_auto_alloc")
}
net, e := modules.Networks.CreateInContext(s, params, &modules.Wires, args.WIRE)
if e != nil {
return e
}
printObject(net)
return nil
})

type NetworkCreateOptions2 struct {
Wire string `help:"ID or Name of wire in which the network is created"`
Vpc string `help:"ID or Name of vpc in which the network is created"`
Zone string `help:"ID or Name of zone in which the network is created"`
NAME string `help:"Name of new network"`
PREFIX string `help:"Start of IPv4 address range"`
Wire string `help:"ID or Name of wire in which the network is created"`
Vpc string `help:"ID or Name of vpc in which the network is created"`
Zone string `help:"ID or Name of zone in which the network is created"`
NAME string `help:"Name of new network"`
PREFIX string `help:"IPv4 prefix"`

Prefix6 string `help:"IPv6 prefix"`

BgpType string `help:"Internet service provider name" positional:"false"`
AssignPublicIp bool
Desc string `help:"Description" metavar:"DESCRIPTION"`
Expand All @@ -129,6 +80,11 @@ func init() {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.NAME), "name")
params.Add(jsonutils.NewString(args.PREFIX), "guest_ip_prefix")

if len(args.Prefix6) > 0 {
params.Add(jsonutils.NewString(args.Prefix6), "guest_ip6_prefix")
}

params.Set("assign_public_ip", jsonutils.NewBool(args.AssignPublicIp))
if len(args.BgpType) > 0 {
params.Add(jsonutils.NewString(args.BgpType), "bgp_type")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ require (
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/pkg v1.0.1-0.20240114161232-64f11f704be8
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v1.1.3-0.20240103021517-2be4fb49bd3b
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 @@ -1216,8 +1216,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.0.1-0.20231101105448-abef64cdc142 h1:L6LqxfP08eWUx+A6yQdrL6VB3KILU1TbQllPtKZq7PM=
yunion.io/x/pkg v1.0.1-0.20231101105448-abef64cdc142/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
yunion.io/x/pkg v1.0.1-0.20240114161232-64f11f704be8 h1:+zOGiKwsEOfnxBOqDHBTl4SqSvCHIrC5gsF5dMgtnrs=
yunion.io/x/pkg v1.0.1-0.20240114161232-64f11f704be8/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.20240103021517-2be4fb49bd3b h1:W87Fe3H4wVm2CIrsVXNuypnO3yV7nhkiWozd2lDruKM=
Expand Down
11 changes: 9 additions & 2 deletions pkg/apis/compute/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ type NetworkConfig struct {

// 子网内的IPv6地址
// required: false
// swagger:ignore
Address6 string `json:"address6"`

// 如果是批量创建,指定每台主机子网内的IPv4地址
// required: false
Addresses6 []string `json:"addresses6"`

// 是否要求分配IPv6地址
// required: false
RequireIPv6 bool `json:"require_ipv6"`

// 驱动方式
// 若指定镜像的网络驱动方式,此参数会被覆盖
Driver string `json:"driver"`
Expand Down Expand Up @@ -120,9 +123,13 @@ type NetworkConfig struct {

type AttachNetworkInput struct {
// 添加的网卡的配置
// required: true
// required: false
Nets []*NetworkConfig `json:"nets"`

// 添加的网卡的配置
// required: false
NetDesc []string `json:"net_desc"`

// 添加后不立即同步配置
DisableSyncConfig *bool `json:"disable_sync_config"`
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/compute/dnsrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ func (record *SDnsRecord) ValidateDnsrecordValue() error {
}
return nil
}

type SDnsResolveResult struct {
DnsValue string `json:"dns_value"`
TTL int64 `json:"ttl"`
DnsName string `json:"dns_name"`
}
15 changes: 12 additions & 3 deletions pkg/apis/compute/groupnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ type GroupnetworkListInput struct {

// IP地址
IpAddr []string `json:"ip_addr"`

// IPv6地址
Ip6Addr []string `json:"ip6_addr"`
}

type GroupAttachNetworkInput struct {
// network id or name
NetworkId string `json:"network_id" help:"The network to attach, optional"`

// candidate IPaddr
IpAddr string `json:"ip_addr" help:"The ip address to use, optional"`
// candidate IPv4 addr
IpAddr string `json:"ip_addr" help:"The ipv4 address to use, optional"`

// candidate IPv6 addr
Ip6Addr string `json:"ip6_addr" help:"The ipv6 address to use, optional"`

// Allocation direction
AllocDir IPAllocationDirection `json:"alloc_dir" help:"ip allocation direction, optional"`
Expand All @@ -50,9 +56,12 @@ type GroupAttachNetworkInput struct {

// Required Designed IP
RequireDesignatedIp *bool `json:"require_designated_ip" help:"fail if the designed ip is not available"`

// allocate ipv6 address
RequireIPv6 bool `json:"require_ipv6" help:"fail if no ipv6 address allocated"`
}

type GroupDetachNetworkInput struct {
// candidate IPaddr
// candidate IPaddr, can be either IPv4 or IPv6 address
IpAddr string `json:"ip_addr" help:"Ip address to detach, empty if detach all networks"`
}
4 changes: 4 additions & 0 deletions pkg/apis/compute/guestnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ type GuestnetworkBaseDesc struct {
TxTrafficLimit int64 `json:"tx_traffic_limit"`
NicType compute.TNicType `json:"nic_type"`

Ip6 string `json:"ip6"`
Gateway6 string `json:"gateway6"`
Masklen6 uint8 `json:"masklen6"`

// 是否为缺省路由网关
IsDefault bool `json:"is_default"`

Expand Down
28 changes: 26 additions & 2 deletions pkg/apis/compute/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,8 @@ type ServerNicTrafficLimit struct {
}

type GuestAddSubIpsInput struct {
Mac string `json:"mac"`
IpAddr string `json:"ip_addr"`
ServerNetworkInfo

Count int `json:"count"`
SubIps []string `json:"sub_ips"`

Expand Down Expand Up @@ -1216,3 +1216,27 @@ type ServerSetOSInfoInput struct {
Version string `json:"version" help:"OS version, e.g.: 7.9, 22.04, 6.3"`
Arch string `json:"arch" help:"OS arch, e.g.: x86_64, aarch64"`
}

type ServerNetworkInfo struct {
Index int `json:"index"`
Mac string `json:"mac"`
IpAddr string `json:"ip_addr"`
Ip6Addr string `json:"ip6_addr"`
}

type ServerChangeIpaddrInput struct {
ServerNetworkInfo

NetDesc string `json:"net_desc"`
NetConf *NetworkConfig `json:"net_conf"`

Reserve *bool `json:"reserve"`

RestartNetwork *bool `json:"restart_network"`
}

type ServerChangeBandwidthInput struct {
ServerNetworkInfo

Bandwidth int `json:"bandwidth"`
}
Loading

0 comments on commit c7d79f5

Please sign in to comment.