Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,18 @@ func copyString(sPtr *string) *string {
return &t
}

// copyValue returns a pointer to a new value copied from the value
// at the given pointer.
func copyValue[T any](ptr *T) *T {
if ptr == nil {
return nil
}

t := *ptr

return &t
}

func copyTime(tPtr *time.Time) *time.Time {
if tPtr == nil {
return nil
Expand Down
22 changes: 22 additions & 0 deletions helpers_iterator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package linodego

import (
"iter"
"slices"
)

// mapIter returns a new iterator of the values in the given iterator transformed using the given transform function.
func mapIter[I, O any](values iter.Seq[I], transform func(I) O) iter.Seq[O] {
return func(yield func(O) bool) {
for value := range values {
if !yield(transform(value)) {
return
}
}
}
}

// mapSlice returns a new slice of the values in the given slice transformed using the given transform function.
func mapSlice[I, O any](values []I, transform func(I) O) []O {
return slices.Collect(mapIter(slices.Values(values), transform))
}
166 changes: 141 additions & 25 deletions instance_config_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@ import (

// InstanceConfigInterface contains information about a configuration's network interface
type InstanceConfigInterface struct {
ID int `json:"id"`
IPAMAddress string `json:"ipam_address"`
Label string `json:"label"`
Purpose ConfigInterfacePurpose `json:"purpose"`
Primary bool `json:"primary"`
Active bool `json:"active"`
VPCID *int `json:"vpc_id"`
SubnetID *int `json:"subnet_id"`
IPv4 *VPCIPv4 `json:"ipv4"`
IPRanges []string `json:"ip_ranges"`
ID int `json:"id"`
IPAMAddress string `json:"ipam_address"`
Label string `json:"label"`
Purpose ConfigInterfacePurpose `json:"purpose"`
Primary bool `json:"primary"`
Active bool `json:"active"`
VPCID *int `json:"vpc_id"`
SubnetID *int `json:"subnet_id"`
IPv4 *VPCIPv4 `json:"ipv4"`
IPv6 *InstanceConfigInterfaceIPv6 `json:"ipv6"`
IPRanges []string `json:"ip_ranges"`
}

// InstanceConfigInterfaceIPv6 represents the IPv6 configuration of a Linode interface.
type InstanceConfigInterfaceIPv6 struct {
SLAAC []InstanceConfigInterfaceIPv6SLAAC `json:"slaac"`
Ranges []InstanceConfigInterfaceIPv6Range `json:"ranges"`
IsPublic bool `json:"is_public"`
}

// InstanceConfigInterfaceIPv6SLAAC represents a single IPv6 SLAAC under
// a Linode interface.
type InstanceConfigInterfaceIPv6SLAAC struct {
Range string `json:"range"`
Address string `json:"address"`
}

// InstanceConfigInterfaceIPv6Range represents a single IPv6 range under a Linode interface.
type InstanceConfigInterfaceIPv6Range struct {
Range string `json:"range"`
}

type VPCIPv4 struct {
Expand All @@ -24,19 +44,61 @@ type VPCIPv4 struct {
}

type InstanceConfigInterfaceCreateOptions struct {
IPAMAddress string `json:"ipam_address,omitempty"`
Label string `json:"label,omitempty"`
Purpose ConfigInterfacePurpose `json:"purpose,omitempty"`
Primary bool `json:"primary,omitempty"`
SubnetID *int `json:"subnet_id,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
IPRanges []string `json:"ip_ranges,omitempty"`
IPAMAddress string `json:"ipam_address,omitempty"`
Label string `json:"label,omitempty"`
Purpose ConfigInterfacePurpose `json:"purpose,omitempty"`
Primary bool `json:"primary,omitempty"`
SubnetID *int `json:"subnet_id,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
IPv6 *InstanceConfigInterfaceCreateOptionsIPv6 `json:"ipv6,omitempty"`
IPRanges []string `json:"ip_ranges,omitempty"`
}

// InstanceConfigInterfaceCreateOptionsIPv6 represents the IPv6 configuration of a Linode interface
// specified during creation.
type InstanceConfigInterfaceCreateOptionsIPv6 struct {
SLAAC []InstanceConfigInterfaceCreateOptionsIPv6SLAAC `json:"slaac,omitempty"`
Ranges []InstanceConfigInterfaceCreateOptionsIPv6Range `json:"ranges,omitempty"`
IsPublic *bool `json:"is_public,omitempty"`
}

// InstanceConfigInterfaceCreateOptionsIPv6SLAAC represents a single IPv6 SLAAC of a Linode interface
// specified during creation.
type InstanceConfigInterfaceCreateOptionsIPv6SLAAC struct {
Range string `json:"range"`
}

// InstanceConfigInterfaceCreateOptionsIPv6Range represents a single IPv6 ranges of a Linode interface
// specified during creation.
type InstanceConfigInterfaceCreateOptionsIPv6Range struct {
Range *string `json:"range,omitempty"`
}

type InstanceConfigInterfaceUpdateOptions struct {
Primary bool `json:"primary,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
IPRanges *[]string `json:"ip_ranges,omitempty"`
Primary bool `json:"primary,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
IPv6 *InstanceConfigInterfaceUpdateOptionsIPv6 `json:"ipv6,omitempty"`
IPRanges *[]string `json:"ip_ranges,omitempty"`
}

// InstanceConfigInterfaceUpdateOptionsIPv6 represents the IPv6 configuration of a Linode interface
// specified during updates.
type InstanceConfigInterfaceUpdateOptionsIPv6 struct {
SLAAC *[]InstanceConfigInterfaceUpdateOptionsIPv6SLAAC `json:"slaac,omitempty"`
Ranges *[]InstanceConfigInterfaceUpdateOptionsIPv6Range `json:"ranges,omitempty"`
IsPublic *bool `json:"is_public,omitempty"`
}

// InstanceConfigInterfaceUpdateOptionsIPv6SLAAC represents a single IPv6 SLAAC of a Linode interface
// specified during updates.
type InstanceConfigInterfaceUpdateOptionsIPv6SLAAC struct {
Range *string `json:"range,omitempty"`
}

// InstanceConfigInterfaceUpdateOptionsIPv6Range represents a single IPv6 ranges of a Linode interface
// specified during updates.
type InstanceConfigInterfaceUpdateOptionsIPv6Range struct {
Range *string `json:"range,omitempty"`
}

type InstanceConfigInterfacesReorderOptions struct {
Expand Down Expand Up @@ -66,13 +128,37 @@ func (i InstanceConfigInterface) GetCreateOptions() InstanceConfigInterfaceCreat
opts.IPRanges = i.IPRanges
}

if i.Purpose == InterfacePurposeVPC && i.IPv4 != nil {
if i.IPv4 != nil {
opts.IPv4 = &VPCIPv4{
VPC: i.IPv4.VPC,
NAT1To1: i.IPv4.NAT1To1,
}
}

if i.IPv6 != nil {
ipv6 := *i.IPv6

opts.IPv6 = &InstanceConfigInterfaceCreateOptionsIPv6{
SLAAC: mapSlice(
ipv6.SLAAC,
func(i InstanceConfigInterfaceIPv6SLAAC) InstanceConfigInterfaceCreateOptionsIPv6SLAAC {
return InstanceConfigInterfaceCreateOptionsIPv6SLAAC{
Range: i.Range,
}
},
),
Ranges: mapSlice(
ipv6.Ranges,
func(i InstanceConfigInterfaceIPv6Range) InstanceConfigInterfaceCreateOptionsIPv6Range {
return InstanceConfigInterfaceCreateOptionsIPv6Range{
Range: copyValue(&i.Range),
}
},
),
IsPublic: copyValue(&ipv6.IsPublic),
}
}

opts.IPAMAddress = i.IPAMAddress

return opts
Expand All @@ -83,10 +169,40 @@ func (i InstanceConfigInterface) GetUpdateOptions() InstanceConfigInterfaceUpdat
Primary: i.Primary,
}

if i.Purpose == InterfacePurposeVPC && i.IPv4 != nil {
opts.IPv4 = &VPCIPv4{
VPC: i.IPv4.VPC,
NAT1To1: i.IPv4.NAT1To1,
if i.Purpose == InterfacePurposeVPC {
if i.IPv4 != nil {
opts.IPv4 = &VPCIPv4{
VPC: i.IPv4.VPC,
NAT1To1: i.IPv4.NAT1To1,
}
}

if i.IPv6 != nil {
ipv6 := *i.IPv6

newSLAAC := mapSlice(
ipv6.SLAAC,
func(i InstanceConfigInterfaceIPv6SLAAC) InstanceConfigInterfaceUpdateOptionsIPv6SLAAC {
return InstanceConfigInterfaceUpdateOptionsIPv6SLAAC{
Range: copyValue(&i.Range),
}
},
)

newRanges := mapSlice(
ipv6.Ranges,
func(i InstanceConfigInterfaceIPv6Range) InstanceConfigInterfaceUpdateOptionsIPv6Range {
return InstanceConfigInterfaceUpdateOptionsIPv6Range{
Range: copyValue(&i.Range),
}
},
)

opts.IPv6 = &InstanceConfigInterfaceUpdateOptionsIPv6{
SLAAC: &newSLAAC,
Ranges: &newRanges,
IsPublic: copyValue(&ipv6.IsPublic),
}
}
}

Expand Down
19 changes: 11 additions & 8 deletions instance_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,27 @@ func (i *InstanceConfig) UnmarshalJSON(b []byte) error {

// GetCreateOptions converts a InstanceConfig to InstanceConfigCreateOptions for use in CreateInstanceConfig
func (i InstanceConfig) GetCreateOptions() InstanceConfigCreateOptions {
initrd := 0
if i.InitRD != nil {
initrd = *i.InitRD
}

return InstanceConfigCreateOptions{
result := InstanceConfigCreateOptions{
Label: i.Label,
Comments: i.Comments,
Devices: *i.Devices,
Helpers: i.Helpers,
Interfaces: getInstanceConfigInterfacesCreateOptionsList(i.Interfaces),
MemoryLimit: i.MemoryLimit,
Kernel: i.Kernel,
InitRD: initrd,
RootDevice: copyString(&i.RootDevice),
RunLevel: i.RunLevel,
VirtMode: i.VirtMode,
}

if i.InitRD != nil {
result.InitRD = *i.InitRD
}

if i.Devices != nil {
result.Devices = *i.Devices
}

return result
}

// GetUpdateOptions converts a InstanceConfig to InstanceConfigUpdateOptions for use in UpdateInstanceConfig
Expand Down
32 changes: 20 additions & 12 deletions instance_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,31 @@ type InstanceIP struct {

// VPCIP represents a private IP address in a VPC subnet with additional networking details
type VPCIP struct {
Address *string `json:"address"`
AddressRange *string `json:"address_range"`
Gateway string `json:"gateway"`
SubnetMask string `json:"subnet_mask"`
Prefix int `json:"prefix"`
LinodeID int `json:"linode_id"`
Region string `json:"region"`
Active bool `json:"active"`
NAT1To1 *string `json:"nat_1_1"`
VPCID int `json:"vpc_id"`
SubnetID int `json:"subnet_id"`
InterfaceID int `json:"interface_id"`
Address *string `json:"address"`
AddressRange *string `json:"address_range"`
IPv6Range *string `json:"ipv6_range"`
IPv6IsPublic *bool `json:"ipv6_is_public"`
IPv6Addresses []VPCIPIPv6Address `json:"ipv6_addresses"`
Gateway string `json:"gateway"`
SubnetMask string `json:"subnet_mask"`
Prefix int `json:"prefix"`
LinodeID int `json:"linode_id"`
Region string `json:"region"`
Active bool `json:"active"`
NAT1To1 *string `json:"nat_1_1"`
VPCID int `json:"vpc_id"`
SubnetID int `json:"subnet_id"`
InterfaceID int `json:"interface_id"`

// The type of this field will be made a pointer in the next major release of linodego.
ConfigID int `json:"config_id"`
}

// VPCIPIPv6Address represents a single IPv6 address under a VPCIP.
type VPCIPIPv6Address struct {
SLAACAddress string `json:"slaac_address"`
}

// InstanceIPv6Response contains the IPv6 addresses and ranges for an Instance
type InstanceIPv6Response struct {
LinkLocal *InstanceIP `json:"link_local"`
Expand Down
31 changes: 31 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type VPCInterface struct {
VPCID int `json:"vpc_id"`
SubnetID int `json:"subnet_id"`
IPv4 VPCInterfaceIPv4 `json:"ipv4"`
IPv6 VPCInterfaceIPv6 `json:"ipv6"`
}

type VPCInterfaceIPv4 struct {
Expand All @@ -82,6 +83,21 @@ type VPCInterfaceIPv4Range struct {
Range string `json:"range"`
}

type VPCInterfaceIPv6 struct {
SLAAC []VPCInterfaceIPv6SLAAC `json:"slaac"`
Ranges []VPCInterfaceIPv6Range `json:"ranges"`
IsPublic bool `json:"is_public"`
}

type VPCInterfaceIPv6SLAAC struct {
Range string `json:"range"`
Address string `json:"address"`
}

type VPCInterfaceIPv6Range struct {
Range string `json:"range"`
}

type VLANInterface struct {
VLANLabel string `json:"vlan_label"`
IPAMAddress *string `json:"ipam_address,omitempty"`
Expand Down Expand Up @@ -127,6 +143,7 @@ type PublicInterfaceIPv6RangeCreateOptions struct {
type VPCInterfaceCreateOptions struct {
SubnetID int `json:"subnet_id"`
IPv4 *VPCInterfaceIPv4CreateOptions `json:"ipv4,omitempty"`
IPv6 *VPCInterfaceIPv6CreateOptions `json:"ipv6,omitempty"`
}

type VPCInterfaceIPv4CreateOptions struct {
Expand All @@ -144,6 +161,20 @@ type VPCInterfaceIPv4RangeCreateOptions struct {
Range string `json:"range"`
}

type VPCInterfaceIPv6CreateOptions struct {
SLAAC []VPCInterfaceIPv6SLAACCreateOptions `json:"slaac,omitempty"`
Ranges []VPCInterfaceIPv6RangeCreateOptions `json:"ranges,omitempty"`
IsPublic bool `json:"is_public"`
}

type VPCInterfaceIPv6SLAACCreateOptions struct {
Range string `json:"range"`
}

type VPCInterfaceIPv6RangeCreateOptions struct {
Range string `json:"range"`
}

type LinodeInterfacesUpgrade struct {
ConfigID int `json:"config_id"`
DryRun bool `json:"dry_run"`
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a stale fixture file that's not longer referenced in an integration test.

Empty file.
Loading