Skip to content
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
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))
}
152 changes: 143 additions & 9 deletions instance_config_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,33 @@ type InstanceConfigInterface struct {
VPCID *int `json:"vpc_id"`
SubnetID *int `json:"subnet_id"`
IPv4 *VPCIPv4 `json:"ipv4"`
IPRanges []string `json:"ip_ranges"`

// NOTE: IPv6 interfaces may not currently be available to all users.
IPv6 *InstanceConfigInterfaceIPv6 `json:"ipv6"`

IPRanges []string `json:"ip_ranges"`
}

// InstanceConfigInterfaceIPv6 represents the IPv6 configuration of a Linode interface.
// NOTE: IPv6 interfaces may not currently be available to all users.
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.
// NOTE: IPv6 interfaces may not currently be available to all users.
type InstanceConfigInterfaceIPv6SLAAC struct {
Range string `json:"range"`
Address string `json:"address"`
}

// InstanceConfigInterfaceIPv6Range represents a single IPv6 range under a Linode interface.
// NOTE: IPv6 interfaces may not currently be available to all users.
type InstanceConfigInterfaceIPv6Range struct {
Range string `json:"range"`
}

type VPCIPv4 struct {
Expand All @@ -30,15 +56,69 @@ type InstanceConfigInterfaceCreateOptions struct {
Primary bool `json:"primary,omitempty"`
SubnetID *int `json:"subnet_id,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
IPRanges []string `json:"ip_ranges,omitempty"`

// NOTE: IPv6 interfaces may not currently be available to all users.
IPv6 *InstanceConfigInterfaceCreateOptionsIPv6 `json:"ipv6,omitempty"`

IPRanges []string `json:"ip_ranges,omitempty"`
}

// InstanceConfigInterfaceCreateOptionsIPv6 represents the IPv6 configuration of a Linode interface
// specified during creation.
// NOTE: IPv6 interfaces may not currently be available to all users.
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.
// NOTE: IPv6 interfaces may not currently be available to all users.
type InstanceConfigInterfaceCreateOptionsIPv6SLAAC struct {
Range string `json:"range"`
}

// InstanceConfigInterfaceCreateOptionsIPv6Range represents a single IPv6 ranges of a Linode interface
// specified during creation.
// NOTE: IPv6 interfaces may not currently be available to all users.
type InstanceConfigInterfaceCreateOptionsIPv6Range struct {
Range *string `json:"range,omitempty"`
}

type InstanceConfigInterfaceUpdateOptions struct {
Primary bool `json:"primary,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`
Primary bool `json:"primary,omitempty"`
IPv4 *VPCIPv4 `json:"ipv4,omitempty"`

// NOTE: IPv6 interfaces may not currently be available to all users.
IPv6 *InstanceConfigInterfaceUpdateOptionsIPv6 `json:"ipv6,omitempty"`

IPRanges *[]string `json:"ip_ranges,omitempty"`
}

// InstanceConfigInterfaceUpdateOptionsIPv6 represents the IPv6 configuration of a Linode interface
// specified during updates.
// NOTE: IPv6 interfaces may not currently be available to all users.
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.
// NOTE: IPv6 interfaces may not currently be available to all users.
type InstanceConfigInterfaceUpdateOptionsIPv6SLAAC struct {
Range *string `json:"range,omitempty"`
}

// InstanceConfigInterfaceUpdateOptionsIPv6Range represents a single IPv6 ranges of a Linode interface
// specified during updates.
// NOTE: IPv6 interfaces may not currently be available to all users.
type InstanceConfigInterfaceUpdateOptionsIPv6Range struct {
Range *string `json:"range,omitempty"`
}

type InstanceConfigInterfacesReorderOptions struct {
IDs []int `json:"ids"`
}
Expand Down Expand Up @@ -66,13 +146,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 +187,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
11 changes: 11 additions & 0 deletions instance_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,21 @@ type VPCIP struct {
SubnetID int `json:"subnet_id"`
InterfaceID int `json:"interface_id"`

// NOTE: IPv6 VPCs may not currently be available to all users.
IPv6Range *string `json:"ipv6_range"`
IPv6IsPublic *bool `json:"ipv6_is_public"`
IPv6Addresses []VPCIPIPv6Address `json:"ipv6_addresses"`

// 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.
// NOTE: IPv6 VPCs may not currently be available to all users.
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
45 changes: 45 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ type VPCInterface struct {
VPCID int `json:"vpc_id"`
SubnetID int `json:"subnet_id"`
IPv4 VPCInterfaceIPv4 `json:"ipv4"`

// NOTE: IPv6 VPC interfaces may not currently be available to all users.
IPv6 VPCInterfaceIPv6 `json:"ipv6"`
}

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

// VPCInterfaceIPv6 contains the IPv6 configuration for a VPC.
// NOTE: IPv6 VPC interfaces may not currently be available to all users.
type VPCInterfaceIPv6 struct {
SLAAC []VPCInterfaceIPv6SLAAC `json:"slaac"`
Ranges []VPCInterfaceIPv6Range `json:"ranges"`
IsPublic bool `json:"is_public"`
}

// VPCInterfaceIPv6SLAAC contains the information for a single IPv6 SLAAC under a VPC.
// NOTE: IPv6 VPC interfaces may not currently be available to all users.
type VPCInterfaceIPv6SLAAC struct {
Range string `json:"range"`
Address string `json:"address"`
}

// VPCInterfaceIPv6Range contains the information for a single IPv6 range under a VPC.
// NOTE: IPv6 VPC interfaces may not currently be available to all users.
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 +151,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 +169,26 @@ type VPCInterfaceIPv4RangeCreateOptions struct {
Range string `json:"range"`
}

// VPCInterfaceIPv6CreateOptions specifies IPv6 configuration parameters for VPC creation.
// NOTE: IPv6 interfaces may not currently be available to all users.
type VPCInterfaceIPv6CreateOptions struct {
SLAAC []VPCInterfaceIPv6SLAACCreateOptions `json:"slaac,omitempty"`
Ranges []VPCInterfaceIPv6RangeCreateOptions `json:"ranges,omitempty"`
IsPublic bool `json:"is_public"`
}

// VPCInterfaceIPv6SLAACCreateOptions defines the IPv6 SLAAC configuration parameters for VPC creation.
// NOTE: IPv6 interfaces may not currently be available to all users.
type VPCInterfaceIPv6SLAACCreateOptions struct {
Range string `json:"range"`
}

// VPCInterfaceIPv6RangeCreateOptions defines the IPv6 range configuration parameters for VPC creation.
// NOTE: IPv6 interfaces may not currently be available to all users.
type VPCInterfaceIPv6RangeCreateOptions struct {
Range string `json:"range"`
}

type LinodeInterfacesUpgrade struct {
ConfigID int `json:"config_id"`
DryRun bool `json:"dry_run"`
Expand Down
Empty file.
Loading