Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Add VPC to InstanceIPv4Response #465

Merged
merged 3 commits into from
Mar 13, 2024

Conversation

zliang-akamai
Copy link
Member

📝 Description

The API has been updated, and the VPC IPs of an instance is now being returned in the Networking Info List API.

✔️ How to Test

make ARGS="-run TestIPAddresses" fixtures
import (
	"context"
	"fmt"
	"github.com/linode/linodego"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	client := linodego.NewClient(nil)
	client.SetToken(os.Getenv("LINODE_TOKEN"))

	vpc, err := client.CreateVPC(ctx, linodego.VPCCreateOptions{
		Label:  "test-vpc",
		Region: "us-mia",
		Subnets: []linodego.VPCSubnetCreateOptions{
			{
				Label: "test-subnet",
				IPv4:  "10.0.0.0/24",
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		client.DeleteVPC(ctx, vpc.ID)
	}()

	inst, err := client.CreateInstance(
		ctx,
		linodego.InstanceCreateOptions{
			Region: "us-mia",
			Label:  "test-inst",
			Type:   "g6-nanode-1",
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		client.DeleteInstance(ctx, inst.ID)
	}()

	_, err = client.CreateInstanceConfig(
		ctx,
		inst.ID,
		linodego.InstanceConfigCreateOptions{
			Label:   "test-config",
			Devices: linodego.InstanceConfigDeviceMap{},
			Interfaces: []linodego.InstanceConfigInterfaceCreateOptions{
				{
					Purpose:  linodego.InterfacePurposeVPC,
					SubnetID: &vpc.Subnets[0].ID,
				},
			},
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	i, err := client.GetInstanceIPAddresses(context.Background(), inst.ID)
	fmt.Println("VPC IP: ", *i.IPv4.VPC[0].Address)
}

@zliang-akamai zliang-akamai requested a review from a team as a code owner March 4, 2024 22:15
@zliang-akamai zliang-akamai requested review from jriddle-linode and ykim-akamai and removed request for a team March 4, 2024 22:15
@zliang-akamai zliang-akamai force-pushed the zhiwei/instance-vpc-ips-list branch from 8d1a98d to f5477fe Compare March 4, 2024 23:03
@zliang-akamai zliang-akamai changed the title Add VPC to InstanceIPv4Response new: Add VPC to InstanceIPv4Response Mar 7, 2024
Copy link
Collaborator

@jriddle-linode jriddle-linode left a comment

Choose a reason for hiding this comment

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

LGTM passes locally.

Copy link
Contributor

@ykim-akamai ykim-akamai left a comment

Choose a reason for hiding this comment

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

LGTM

@zliang-akamai zliang-akamai merged commit 9db9207 into linode:main Mar 13, 2024
4 checks passed
@zliang-akamai zliang-akamai deleted the zhiwei/instance-vpc-ips-list branch March 13, 2024 04:19
@zliang-akamai zliang-akamai added the new-feature for new features in the changelog. label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature for new features in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants