Skip to content

Commit

Permalink
Merge pull request #191 from LBGarber/vlans-fix
Browse files Browse the repository at this point in the history
Update VLAN API
  • Loading branch information
LBGarber authored Apr 21, 2021
2 parents 525ac88 + 9e5b08c commit b2e02da
Show file tree
Hide file tree
Showing 10 changed files with 491 additions and 865 deletions.
74 changes: 47 additions & 27 deletions instance_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ import (

// InstanceConfig represents all of the settings that control the boot and run configuration of a Linode Instance
type InstanceConfig struct {
ID int `json:"id"`
Label string `json:"label"`
Comments string `json:"comments"`
Devices *InstanceConfigDeviceMap `json:"devices"`
Helpers *InstanceConfigHelpers `json:"helpers"`
MemoryLimit int `json:"memory_limit"`
Kernel string `json:"kernel"`
InitRD *int `json:"init_rd"`
RootDevice string `json:"root_device"`
RunLevel string `json:"run_level"`
VirtMode string `json:"virt_mode"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
ID int `json:"id"`
Label string `json:"label"`
Comments string `json:"comments"`
Devices *InstanceConfigDeviceMap `json:"devices"`
Helpers *InstanceConfigHelpers `json:"helpers"`
Interfaces []InstanceConfigInterface `json:"interfaces"`
MemoryLimit int `json:"memory_limit"`
Kernel string `json:"kernel"`
InitRD *int `json:"init_rd"`
RootDevice string `json:"root_device"`
RunLevel string `json:"run_level"`
VirtMode string `json:"virt_mode"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
}

// InstanceConfigDevice contains either the DiskID or VolumeID assigned to a Config Device
Expand Down Expand Up @@ -53,6 +54,21 @@ type InstanceConfigHelpers struct {
DevTmpFsAutomount bool `json:"devtmpfs_automount"`
}

// ConfigInterfacePurpose options start with InterfacePurpose and include all known interface purpose types
type ConfigInterfacePurpose string

const (
InterfacePurposePublic ConfigInterfacePurpose = "public"
InterfacePurposeVLAN ConfigInterfacePurpose = "vlan"
)

// InstanceConfigInterface contains information about a configuration's network interface
type InstanceConfigInterface struct {
IPAMAddress string `json:"ipam_address"`
Label string `json:"label"`
Purpose ConfigInterfacePurpose `json:"purpose"`
}

// InstanceConfigsPagedResponse represents a paginated InstanceConfig API response
type InstanceConfigsPagedResponse struct {
*PageOptions
Expand All @@ -61,24 +77,26 @@ type InstanceConfigsPagedResponse struct {

// InstanceConfigCreateOptions are InstanceConfig settings that can be used at creation
type InstanceConfigCreateOptions struct {
Label string `json:"label,omitempty"`
Comments string `json:"comments,omitempty"`
Devices InstanceConfigDeviceMap `json:"devices"`
Helpers *InstanceConfigHelpers `json:"helpers,omitempty"`
MemoryLimit int `json:"memory_limit,omitempty"`
Kernel string `json:"kernel,omitempty"`
InitRD int `json:"init_rd,omitempty"`
RootDevice *string `json:"root_device,omitempty"`
RunLevel string `json:"run_level,omitempty"`
VirtMode string `json:"virt_mode,omitempty"`
Label string `json:"label,omitempty"`
Comments string `json:"comments,omitempty"`
Devices InstanceConfigDeviceMap `json:"devices"`
Helpers *InstanceConfigHelpers `json:"helpers,omitempty"`
Interfaces []InstanceConfigInterface `json:"interfaces,omitempty"`
MemoryLimit int `json:"memory_limit,omitempty"`
Kernel string `json:"kernel,omitempty"`
InitRD int `json:"init_rd,omitempty"`
RootDevice *string `json:"root_device,omitempty"`
RunLevel string `json:"run_level,omitempty"`
VirtMode string `json:"virt_mode,omitempty"`
}

// InstanceConfigUpdateOptions are InstanceConfig settings that can be used in updates
type InstanceConfigUpdateOptions struct {
Label string `json:"label,omitempty"`
Comments string `json:"comments"`
Devices *InstanceConfigDeviceMap `json:"devices,omitempty"`
Helpers *InstanceConfigHelpers `json:"helpers,omitempty"`
Label string `json:"label,omitempty"`
Comments string `json:"comments"`
Devices *InstanceConfigDeviceMap `json:"devices,omitempty"`
Helpers *InstanceConfigHelpers `json:"helpers,omitempty"`
Interfaces []InstanceConfigInterface `json:"interfaces,omitempty"`
// MemoryLimit 0 means unlimitted, this is not omitted
MemoryLimit int `json:"memory_limit"`
Kernel string `json:"kernel,omitempty"`
Expand Down Expand Up @@ -122,6 +140,7 @@ func (i InstanceConfig) GetCreateOptions() InstanceConfigCreateOptions {
Comments: i.Comments,
Devices: *i.Devices,
Helpers: i.Helpers,
Interfaces: i.Interfaces,
MemoryLimit: i.MemoryLimit,
Kernel: i.Kernel,
InitRD: initrd,
Expand All @@ -138,6 +157,7 @@ func (i InstanceConfig) GetUpdateOptions() InstanceConfigUpdateOptions {
Comments: i.Comments,
Devices: i.Devices,
Helpers: i.Helpers,
Interfaces: i.Interfaces,
MemoryLimit: i.MemoryLimit,
Kernel: i.Kernel,
InitRD: copyInt(i.InitRD),
Expand Down
29 changes: 15 additions & 14 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,21 @@ type InstanceTransfer struct {

// InstanceCreateOptions require only Region and Type
type InstanceCreateOptions struct {
Region string `json:"region"`
Type string `json:"type"`
Label string `json:"label,omitempty"`
Group string `json:"group,omitempty"`
RootPass string `json:"root_pass,omitempty"`
AuthorizedKeys []string `json:"authorized_keys,omitempty"`
AuthorizedUsers []string `json:"authorized_users,omitempty"`
StackScriptID int `json:"stackscript_id,omitempty"`
StackScriptData map[string]string `json:"stackscript_data,omitempty"`
BackupID int `json:"backup_id,omitempty"`
Image string `json:"image,omitempty"`
BackupsEnabled bool `json:"backups_enabled,omitempty"`
PrivateIP bool `json:"private_ip,omitempty"`
Tags []string `json:"tags,omitempty"`
Region string `json:"region"`
Type string `json:"type"`
Label string `json:"label,omitempty"`
Group string `json:"group,omitempty"`
RootPass string `json:"root_pass,omitempty"`
AuthorizedKeys []string `json:"authorized_keys,omitempty"`
AuthorizedUsers []string `json:"authorized_users,omitempty"`
StackScriptID int `json:"stackscript_id,omitempty"`
StackScriptData map[string]string `json:"stackscript_data,omitempty"`
BackupID int `json:"backup_id,omitempty"`
Image string `json:"image,omitempty"`
Interfaces []InstanceConfigInterface `json:"interfaces,omitempty"`
BackupsEnabled bool `json:"backups_enabled,omitempty"`
PrivateIP bool `json:"private_ip,omitempty"`
Tags []string `json:"tags,omitempty"`

// Creation fields that need to be set explicitly false, "", or 0 use pointers
SwapSize *int `json:"swap_size,omitempty"`
Expand Down
32 changes: 16 additions & 16 deletions test/integration/fixtures/TestDeleteInstanceIPAddress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interactions:
url: https://api.linode.com/v4beta/linode/instances
method: POST
response:
body: '{"id": 24281807, "label": "linodego-test-instance-wo-disk", "group": "", "status": "provisioning", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "type": "g6-nanode-1", "ipv4": ["50.116.4.219"], "ipv6": "1234::5678/64", "image": null, "region": "us-west", "specs": {"disk": 25600, "memory": 1024, "vcpus": 1, "gpus": 0, "transfer": 1000}, "alerts": {"cpu": 90, "network_in": 10, "network_out": 10, "transfer_quota": 80, "io": 10000}, "backups": {"enabled": false, "schedule": {"day": null, "window": null}, "last_successful": null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": []}'
body: '{"id": 26154111, "label": "linodego-test-instance-wo-disk", "group": "", "status": "provisioning", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "type": "g6-nanode-1", "ipv4": ["173.255.247.42"], "ipv6": "1234::5678/128", "image": null, "region": "us-west", "specs": {"disk": 25600, "memory": 1024, "vcpus": 1, "gpus": 0, "transfer": 1000}, "alerts": {"cpu": 90, "network_in": 10, "network_out": 10, "transfer_quota": 80, "io": 10000}, "backups": {"enabled": false, "schedule": {"day": null, "window": null}, "last_successful": null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -29,7 +29,7 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "632"
- "635"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand Down Expand Up @@ -66,10 +66,10 @@ interactions:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/24281807/configs
url: https://api.linode.com/v4beta/linode/instances/26154111/configs
method: POST
response:
body: '{"id": 26055648, "label": "linodego-test-config", "helpers": {"updatedb_disabled": true, "distro": true, "modules_dep": true, "network": true, "devtmpfs_automount": true}, "kernel": "linode/latest-64bit", "comments": "", "memory_limit": 0, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "root_device": "/dev/sda", "devices": {"sda": null, "sdb": null, "sdc": null, "sdd": null, "sde": null, "sdf": null, "sdg": null, "sdh": null}, "interfaces": {"eth0": {"id": 1187520}}, "initrd": null, "run_level": "default", "virt_mode": "paravirt"}'
body: '{"id": 28118609, "label": "linodego-test-config", "helpers": {"updatedb_disabled": true, "distro": true, "modules_dep": true, "network": true, "devtmpfs_automount": true}, "kernel": "linode/latest-64bit", "comments": "", "memory_limit": 0, "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "root_device": "/dev/sda", "devices": {"sda": null, "sdb": null, "sdc": null, "sdd": null, "sde": null, "sdf": null, "sdg": null, "sdh": null}, "initrd": null, "run_level": "default", "virt_mode": "paravirt", "interfaces": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -84,7 +84,7 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "557"
- "534"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand Down Expand Up @@ -121,10 +121,10 @@ interactions:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/24281807/ips
url: https://api.linode.com/v4beta/linode/instances/26154111/ips
method: POST
response:
body: '{"address": "173.255.240.72", "gateway": "173.255.240.1", "subnet_mask": "255.255.255.0", "prefix": 24, "type": "ipv4", "public": true, "rdns": "li250-72.members.linode.com", "linode_id": 24281807, "region": "us-west"}'
body: '{"address": "45.79.82.225", "gateway": "45.79.82.1", "subnet_mask": "255.255.255.0", "prefix": 24, "type": "ipv4", "public": true, "rdns": "li1181-225.members.linode.com", "linode_id": 26154111, "region": "us-west"}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -139,7 +139,7 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "218"
- "215"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand Down Expand Up @@ -176,10 +176,10 @@ interactions:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/24281807/ips
url: https://api.linode.com/v4beta/linode/instances/26154111/ips
method: GET
response:
body: '{"ipv4": {"public": [{"address": "50.116.4.219", "gateway": "50.116.4.1", "subnet_mask": "255.255.255.0", "prefix": 24, "type": "ipv4", "public": true, "rdns": "li430-219.members.linode.com", "linode_id": 24281807, "region": "us-west"}, {"address": "173.255.240.72", "gateway": "173.255.240.1", "subnet_mask": "255.255.255.0", "prefix": 24, "type": "ipv4", "public": true, "rdns": "li250-72.members.linode.com", "linode_id": 24281807, "region": "us-west"}], "private": [], "shared": [], "reserved": []}, "ipv6": {"slaac": {"address": "1234::5678", "gateway": "1234::5678", "subnet_mask": "1234::5678", "prefix": 64, "type": "ipv6", "rdns": null, "linode_id": 24281807, "region": "us-west", "public": true}, "link_local": {"address": "1234::5678", "gateway": "1234::5678", "subnet_mask": "1234::5678", "prefix": 64, "type": "ipv6", "rdns": null, "linode_id": 24281807, "region": "us-west", "public": false}, "global": []}}'
body: '{"ipv4": {"public": [{"address": "45.79.82.225", "gateway": "45.79.82.1", "subnet_mask": "255.255.255.0", "prefix": 24, "type": "ipv4", "public": true, "rdns": "li1181-225.members.linode.com", "linode_id": 26154111, "region": "us-west"}, {"address": "173.255.247.42", "gateway": "173.255.247.1", "subnet_mask": "255.255.255.0", "prefix": 24, "type": "ipv4", "public": true, "rdns": "li257-42.members.linode.com", "linode_id": 26154111, "region": "us-west"}], "private": [], "shared": [], "reserved": []}, "ipv6": {"slaac": {"address": "1234::5678", "gateway": "1234::5678", "subnet_mask": "1234::5678", "prefix": 64, "type": "ipv6", "rdns": null, "linode_id": 26154111, "region": "us-west", "public": true}, "link_local": {"address": "1234::5678", "gateway": "1234::5678", "subnet_mask": "1234::5678", "prefix": 64, "type": "ipv6", "rdns": null, "linode_id": 26154111, "region": "us-west", "public": false}, "global": []}}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -195,7 +195,7 @@ interactions:
- private, max-age=0, s-maxage=0, no-cache, no-store
- private, max-age=60, s-maxage=60
Content-Length:
- "972"
- "973"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand Down Expand Up @@ -233,7 +233,7 @@ interactions:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/24281807/ips/173.255.240.72
url: https://api.linode.com/v4beta/linode/instances/26154111/ips/45.79.82.225
method: DELETE
response:
body: '{}'
Expand Down Expand Up @@ -288,10 +288,10 @@ interactions:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/24281807/ips
url: https://api.linode.com/v4beta/linode/instances/26154111/ips
method: GET
response:
body: '{"ipv4": {"public": [{"address": "50.116.4.219", "gateway": "50.116.4.1", "subnet_mask": "255.255.255.0", "prefix": 24, "type": "ipv4", "public": true, "rdns": "li430-219.members.linode.com", "linode_id": 24281807, "region": "us-west"}], "private": [], "shared": [], "reserved": []}, "ipv6": {"slaac": {"address": "1234::5678", "gateway": "1234::5678", "subnet_mask": "1234::5678", "prefix": 64, "type": "ipv6", "rdns": null, "linode_id": 24281807, "region": "us-west", "public": true}, "link_local": {"address": "1234::5678", "gateway": "1234::5678", "subnet_mask": "1234::5678", "prefix": 64, "type": "ipv6", "rdns": null, "linode_id": 24281807, "region": "us-west", "public": false}, "global": []}}'
body: '{"ipv4": {"public": [{"address": "173.255.247.42", "gateway": "173.255.247.1", "subnet_mask": "255.255.255.0", "prefix": 24, "type": "ipv4", "public": true, "rdns": "li257-42.members.linode.com", "linode_id": 26154111, "region": "us-west"}], "private": [], "shared": [], "reserved": []}, "ipv6": {"slaac": {"address": "1234::5678", "gateway": "1234::5678", "subnet_mask": "1234::5678", "prefix": 64, "type": "ipv6", "rdns": null, "linode_id": 26154111, "region": "us-west", "public": true}, "link_local": {"address": "1234::5678", "gateway": "1234::5678", "subnet_mask": "1234::5678", "prefix": 64, "type": "ipv6", "rdns": null, "linode_id": 26154111, "region": "us-west", "public": false}, "global": []}}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -307,7 +307,7 @@ interactions:
- private, max-age=0, s-maxage=0, no-cache, no-store
- private, max-age=60, s-maxage=60
Content-Length:
- "752"
- "756"
Content-Security-Policy:
- default-src 'none'
Content-Type:
Expand Down Expand Up @@ -345,7 +345,7 @@ interactions:
- application/json
User-Agent:
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/linode/instances/24281807
url: https://api.linode.com/v4beta/linode/instances/26154111
method: DELETE
response:
body: '{}'
Expand Down
Loading

0 comments on commit b2e02da

Please sign in to comment.