Skip to content

Commit 05f3a56

Browse files
progress
1 parent 5308e5a commit 05f3a56

5 files changed

Lines changed: 216 additions & 38 deletions

File tree

helpers_iterator.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package linodego
2+
3+
import (
4+
"iter"
5+
"slices"
6+
)
7+
8+
// Map returns a new iterator of the values in the given iterator transformed using the given transform function.
9+
func Map[I, O any](values iter.Seq[I], transform func(I) O) iter.Seq[O] {
10+
return func(yield func(O) bool) {
11+
for value := range values {
12+
if !yield(transform(value)) {
13+
return
14+
}
15+
}
16+
}
17+
}
18+
19+
// MapSlice returns a new slice of the values in the given slice transformed using the given transform function.
20+
func MapSlice[I, O any](values []I, transform func(I) O) []O {
21+
return slices.Collect(Map(slices.Values(values), transform))
22+
}

instance_config_interfaces.go

Lines changed: 142 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,36 @@ import (
66

77
// InstanceConfigInterface contains information about a configuration's network interface
88
type InstanceConfigInterface struct {
9-
ID int `json:"id"`
10-
IPAMAddress string `json:"ipam_address"`
11-
Label string `json:"label"`
12-
Purpose ConfigInterfacePurpose `json:"purpose"`
13-
Primary bool `json:"primary"`
14-
Active bool `json:"active"`
15-
VPCID *int `json:"vpc_id"`
16-
SubnetID *int `json:"subnet_id"`
17-
IPv4 *VPCIPv4 `json:"ipv4"`
18-
IPRanges []string `json:"ip_ranges"`
9+
ID int `json:"id"`
10+
IPAMAddress string `json:"ipam_address"`
11+
Label string `json:"label"`
12+
Purpose ConfigInterfacePurpose `json:"purpose"`
13+
Primary bool `json:"primary"`
14+
Active bool `json:"active"`
15+
VPCID *int `json:"vpc_id"`
16+
SubnetID *int `json:"subnet_id"`
17+
IPv4 *VPCIPv4 `json:"ipv4"`
18+
IPv6 *InstanceConfigInterfaceIPv6 `json:"ipv6"`
19+
IPRanges []string `json:"ip_ranges"`
20+
}
21+
22+
// InstanceConfigInterfaceIPv6 represents the IPv6 configuration of a Linode interface.
23+
type InstanceConfigInterfaceIPv6 struct {
24+
SLAAC []InstanceConfigInterfaceIPv6SLAAC `json:"slaac"`
25+
Ranges []InstanceConfigInterfaceIPv6Range `json:"ranges"`
26+
IsPublic bool `json:"is_public"`
27+
}
28+
29+
// InstanceConfigInterfaceIPv6SLAAC represents a single IPv6 SLAAC under
30+
// a Linode interface.
31+
type InstanceConfigInterfaceIPv6SLAAC struct {
32+
Range string `json:"range"`
33+
Address string `json:"address"`
34+
}
35+
36+
// InstanceConfigInterfaceIPv6Range represents a single IPv6 range under a Linode interface.
37+
type InstanceConfigInterfaceIPv6Range struct {
38+
Range string `json:"range"`
1939
}
2040

2141
type VPCIPv4 struct {
@@ -24,19 +44,61 @@ type VPCIPv4 struct {
2444
}
2545

2646
type InstanceConfigInterfaceCreateOptions struct {
27-
IPAMAddress string `json:"ipam_address,omitempty"`
28-
Label string `json:"label,omitempty"`
29-
Purpose ConfigInterfacePurpose `json:"purpose,omitempty"`
30-
Primary bool `json:"primary,omitempty"`
31-
SubnetID *int `json:"subnet_id,omitempty"`
32-
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
33-
IPRanges []string `json:"ip_ranges,omitempty"`
47+
IPAMAddress string `json:"ipam_address,omitempty"`
48+
Label string `json:"label,omitempty"`
49+
Purpose ConfigInterfacePurpose `json:"purpose,omitempty"`
50+
Primary bool `json:"primary,omitempty"`
51+
SubnetID *int `json:"subnet_id,omitempty"`
52+
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
53+
IPv6 *InstanceConfigInterfaceCreateOptionsIPv6 `json:"ipv6,omitempty"`
54+
IPRanges []string `json:"ip_ranges,omitempty"`
55+
}
56+
57+
// InstanceConfigInterfaceCreateOptionsIPv6 represents the IPv6 configuration of a Linode interface
58+
// specified during creation.
59+
type InstanceConfigInterfaceCreateOptionsIPv6 struct {
60+
SLAAC []InstanceConfigInterfaceCreateOptionsIPv6SLAAC `json:"slaac"`
61+
Ranges []InstanceConfigInterfaceCreateOptionsIPv6Range `json:"ranges"`
62+
IsPublic bool `json:"is_public"`
63+
}
64+
65+
// InstanceConfigInterfaceCreateOptionsIPv6SLAAC represents a single IPv6 SLAAC of a Linode interface
66+
// specified during creation.
67+
type InstanceConfigInterfaceCreateOptionsIPv6SLAAC struct {
68+
Range string `json:"range"`
69+
}
70+
71+
// InstanceConfigInterfaceCreateOptionsIPv6Range represents a single IPv6 ranges of a Linode interface
72+
// specified during creation.
73+
type InstanceConfigInterfaceCreateOptionsIPv6Range struct {
74+
Range string `json:"range"`
3475
}
3576

3677
type InstanceConfigInterfaceUpdateOptions struct {
37-
Primary bool `json:"primary,omitempty"`
38-
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
39-
IPRanges *[]string `json:"ip_ranges,omitempty"`
78+
Primary bool `json:"primary,omitempty"`
79+
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
80+
IPv6 *InstanceConfigInterfaceUpdateOptionsIPv6 `json:"ipv6,omitempty"`
81+
IPRanges *[]string `json:"ip_ranges,omitempty"`
82+
}
83+
84+
// InstanceConfigInterfaceUpdateOptionsIPv6 represents the IPv6 configuration of a Linode interface
85+
// specified during updates.
86+
type InstanceConfigInterfaceUpdateOptionsIPv6 struct {
87+
SLAAC []InstanceConfigInterfaceUpdateOptionsIPv6SLAAC `json:"slaac"`
88+
Ranges []InstanceConfigInterfaceUpdateOptionsIPv6Range `json:"ranges"`
89+
IsPublic bool `json:"is_public"`
90+
}
91+
92+
// InstanceConfigInterfaceUpdateOptionsIPv6SLAAC represents a single IPv6 SLAAC of a Linode interface
93+
// specified during updates.
94+
type InstanceConfigInterfaceUpdateOptionsIPv6SLAAC struct {
95+
Range string `json:"range"`
96+
}
97+
98+
// InstanceConfigInterfaceUpdateOptionsIPv6Range represents a single IPv6 ranges of a Linode interface
99+
// specified during updates.
100+
type InstanceConfigInterfaceUpdateOptionsIPv6Range struct {
101+
Range string `json:"range"`
40102
}
41103

42104
type InstanceConfigInterfacesReorderOptions struct {
@@ -65,10 +127,36 @@ func (i InstanceConfigInterface) GetCreateOptions() InstanceConfigInterfaceCreat
65127
opts.IPRanges = i.IPRanges
66128
}
67129

68-
if i.Purpose == InterfacePurposeVPC && i.IPv4 != nil {
69-
opts.IPv4 = &VPCIPv4{
70-
VPC: i.IPv4.VPC,
71-
NAT1To1: i.IPv4.NAT1To1,
130+
if i.Purpose == InterfacePurposeVPC {
131+
if i.IPv4 != nil {
132+
opts.IPv4 = &VPCIPv4{
133+
VPC: i.IPv4.VPC,
134+
NAT1To1: i.IPv4.NAT1To1,
135+
}
136+
}
137+
138+
if i.IPv6 != nil {
139+
ipv6 := *i.IPv6
140+
141+
opts.IPv6 = &InstanceConfigInterfaceCreateOptionsIPv6{
142+
SLAAC: MapSlice(
143+
ipv6.SLAAC,
144+
func(i InstanceConfigInterfaceIPv6SLAAC) InstanceConfigInterfaceCreateOptionsIPv6SLAAC {
145+
return InstanceConfigInterfaceCreateOptionsIPv6SLAAC{
146+
Range: i.Range,
147+
}
148+
},
149+
),
150+
Ranges: MapSlice(
151+
ipv6.Ranges,
152+
func(i InstanceConfigInterfaceIPv6Range) InstanceConfigInterfaceCreateOptionsIPv6Range {
153+
return InstanceConfigInterfaceCreateOptionsIPv6Range{
154+
Range: i.Range,
155+
}
156+
},
157+
),
158+
IsPublic: ipv6.IsPublic,
159+
}
72160
}
73161
}
74162

@@ -82,10 +170,36 @@ func (i InstanceConfigInterface) GetUpdateOptions() InstanceConfigInterfaceUpdat
82170
Primary: i.Primary,
83171
}
84172

85-
if i.Purpose == InterfacePurposeVPC && i.IPv4 != nil {
86-
opts.IPv4 = &VPCIPv4{
87-
VPC: i.IPv4.VPC,
88-
NAT1To1: i.IPv4.NAT1To1,
173+
if i.Purpose == InterfacePurposeVPC {
174+
if i.IPv4 != nil {
175+
opts.IPv4 = &VPCIPv4{
176+
VPC: i.IPv4.VPC,
177+
NAT1To1: i.IPv4.NAT1To1,
178+
}
179+
}
180+
181+
if i.IPv6 != nil {
182+
ipv6 := *i.IPv6
183+
184+
opts.IPv6 = &InstanceConfigInterfaceUpdateOptionsIPv6{
185+
SLAAC: MapSlice(
186+
ipv6.SLAAC,
187+
func(i InstanceConfigInterfaceIPv6SLAAC) InstanceConfigInterfaceUpdateOptionsIPv6SLAAC {
188+
return InstanceConfigInterfaceUpdateOptionsIPv6SLAAC{
189+
Range: i.Range,
190+
}
191+
},
192+
),
193+
Ranges: MapSlice(
194+
ipv6.Ranges,
195+
func(i InstanceConfigInterfaceIPv6Range) InstanceConfigInterfaceUpdateOptionsIPv6Range {
196+
return InstanceConfigInterfaceUpdateOptionsIPv6Range{
197+
Range: i.Range,
198+
}
199+
},
200+
),
201+
IsPublic: ipv6.IsPublic,
202+
}
89203
}
90204
}
91205

instance_ips.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ type InstanceIP struct {
3434
Reserved bool `json:"reserved"`
3535
}
3636

37+
// VPCIPv6Address represents a single IPv6 address under a VPCIP.
38+
type VPCIPv6Address struct {
39+
SLAACAddress string `json:"slaac_address"`
40+
}
41+
3742
// VPCIP represents a private IP address in a VPC subnet with additional networking details
3843
type VPCIP struct {
3944
Address *string `json:"address"`
4045
AddressRange *string `json:"address_range"`
46+
IPv6Range *string `json:"ipv6_range"`
47+
IPv6IsPublic *bool `json:"ipv6_is_public"`
4148
Gateway string `json:"gateway"`
4249
SubnetMask string `json:"subnet_mask"`
4350
Prefix int `json:"prefix"`

vpc.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,36 @@ import (
99
)
1010

1111
type VPC struct {
12-
ID int `json:"id"`
13-
Label string `json:"label"`
14-
Description string `json:"description"`
15-
Region string `json:"region"`
16-
Subnets []VPCSubnet `json:"subnets"`
17-
Created *time.Time `json:"-"`
18-
Updated *time.Time `json:"-"`
12+
ID int `json:"id"`
13+
Label string `json:"label"`
14+
Description string `json:"description"`
15+
Region string `json:"region"`
16+
IPv6 []VPCIPv6Range `json:"ipv6"`
17+
Subnets []VPCSubnet `json:"subnets"`
18+
Created *time.Time `json:"-"`
19+
Updated *time.Time `json:"-"`
20+
}
21+
22+
// VPCIPv6Range represents a single IPv6 range assigned to a VPC.
23+
type VPCIPv6Range struct {
24+
Range string `json:"range"`
1925
}
2026

2127
type VPCCreateOptions struct {
2228
Label string `json:"label"`
2329
Description string `json:"description,omitempty"`
2430
Region string `json:"region"`
31+
IPv6 []VPCCreateOptionsIPv6 `json:"ipv6,omitempty"`
2532
Subnets []VPCSubnetCreateOptions `json:"subnets,omitempty"`
2633
}
2734

35+
// VPCCreateOptionsIPv6 represents a single IPv6 range assigned to a VPC
36+
// which is specified during a VPC's creation.
37+
type VPCCreateOptionsIPv6 struct {
38+
Range string `json:"range"`
39+
AllocationClass string `json:"allocation_class"`
40+
}
41+
2842
type VPCUpdateOptions struct {
2943
Label string `json:"label,omitempty"`
3044
Description string `json:"description,omitempty"`
@@ -41,6 +55,11 @@ func (v VPC) GetCreateOptions() VPCCreateOptions {
4155
Description: v.Description,
4256
Region: v.Region,
4357
Subnets: subnetCreations,
58+
IPv6: MapSlice(v.IPv6, func(i VPCIPv6Range) VPCCreateOptionsIPv6 {
59+
return VPCCreateOptionsIPv6{
60+
Range: i.Range,
61+
}
62+
}),
4463
}
4564
}
4665

vpc_subnet.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@ type VPCSubnet struct {
2525
ID int `json:"id"`
2626
Label string `json:"label"`
2727
IPv4 string `json:"ipv4"`
28+
IPv6 *VPCIPv6Range `json:"ipv6"`
2829
Linodes []VPCSubnetLinode `json:"linodes"`
2930
Created *time.Time `json:"-"`
3031
Updated *time.Time `json:"-"`
3132
}
3233

3334
type VPCSubnetCreateOptions struct {
34-
Label string `json:"label"`
35-
IPv4 string `json:"ipv4"`
35+
Label string `json:"label"`
36+
IPv4 string `json:"ipv4"`
37+
IPv6 *VPCSubnetCreateOptionsIPv6 `json:"ipv6,omitempty"`
38+
}
39+
40+
// VPCSubnetCreateOptionsIPv6 represents a single IPv6 range assigned to a VPC
41+
// which is specified during a VPC subnet's creation.
42+
type VPCSubnetCreateOptionsIPv6 struct {
43+
Range string `json:"range"`
3644
}
3745

3846
type VPCSubnetUpdateOptions struct {
@@ -59,10 +67,18 @@ func (v *VPCSubnet) UnmarshalJSON(b []byte) error {
5967
}
6068

6169
func (v VPCSubnet) GetCreateOptions() VPCSubnetCreateOptions {
62-
return VPCSubnetCreateOptions{
70+
result := VPCSubnetCreateOptions{
6371
Label: v.Label,
6472
IPv4: v.IPv4,
6573
}
74+
75+
if v.IPv6 != nil {
76+
result.IPv6 = &VPCSubnetCreateOptionsIPv6{
77+
Range: v.IPv6.Range,
78+
}
79+
}
80+
81+
return result
6682
}
6783

6884
func (v VPCSubnet) GetUpdateOptions() VPCSubnetUpdateOptions {

0 commit comments

Comments
 (0)