Skip to content

Commit

Permalink
Vultr reserved ip (#1505)
Browse files Browse the repository at this point in the history
* reserved ip for vultr

* .
  • Loading branch information
eyberg authored Aug 4, 2023
1 parent ed093d9 commit 3a12f5f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ require (
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -105,6 +105,7 @@ require (
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/vultr/govultr/v3 v3.2.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iP
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA=
github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
Expand Down Expand Up @@ -558,6 +560,8 @@ github.com/vmware/govmomi v0.22.2/go.mod h1:Y+Wq4lst78L85Ge/F8+ORXIWiKYqaro1vhAu
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728/go.mod h1:x9oS4Wk2s2u4tS29nEaDLdzvuHdB19CvSGJjPgkZJNk=
github.com/vultr/govultr/v2 v2.17.2 h1:gej/rwr91Puc/tgh+j33p/BLR16UrIPnSr+AIwYWZQs=
github.com/vultr/govultr/v2 v2.17.2/go.mod h1:ZFOKGWmgjytfyjeyAdhQlSWwTjh2ig+X49cAp50dzXI=
github.com/vultr/govultr/v3 v3.2.0 h1:gvplbfQOXYKUbYH/yG+8PJ7IAwRER/qqreh9EI2NlD0=
github.com/vultr/govultr/v3 v3.2.0/go.mod h1:7NjuHeQv5vgUWR2H1sPc9D+xffrT5ql+kNi6R3yuwzo=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
2 changes: 1 addition & 1 deletion provider/vultr/vultr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/nanovms/ops/lepton"
"github.com/nanovms/ops/types"
"github.com/vultr/govultr/v2"
"github.com/vultr/govultr/v3"
"golang.org/x/oauth2"
)

Expand Down
8 changes: 4 additions & 4 deletions provider/vultr/vultr_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/nanovms/ops/log"
"github.com/nanovms/ops/types"
"github.com/olekukonko/tablewriter"
"github.com/vultr/govultr/v2"
"github.com/vultr/govultr/v3"
)

// BuildImage to be upload on v
Expand Down Expand Up @@ -42,7 +42,7 @@ func (v *Vultr) createImage(key string, bucket string, region string) {

objURL := v.Storage.getSignedURL(key, bucket, region)

snap, err := v.Client.Snapshot.CreateFromURL(context.TODO(), &govultr.SnapshotURLReq{
snap, _, err := v.Client.Snapshot.CreateFromURL(context.TODO(), &govultr.SnapshotURLReq{
URL: objURL,
})
if err != nil {
Expand Down Expand Up @@ -78,7 +78,7 @@ func (v *Vultr) CreateImage(ctx *lepton.Context, imagePath string) error {

// GetImages return all images on Vultr
func (v *Vultr) GetImages(ctx *lepton.Context) ([]lepton.CloudImage, error) {
snaps, _, err := v.Client.Snapshot.List(context.TODO(), &govultr.ListOptions{
snaps, _, _, err := v.Client.Snapshot.List(context.TODO(), &govultr.ListOptions{
PerPage: 100,
Cursor: "",
})
Expand Down Expand Up @@ -106,7 +106,7 @@ func (v *Vultr) GetImages(ctx *lepton.Context) ([]lepton.CloudImage, error) {
// ListImages lists images on Vultr
func (v *Vultr) ListImages(ctx *lepton.Context) error {

snaps, _, err := v.Client.Snapshot.List(context.TODO(), &govultr.ListOptions{
snaps, _, _, err := v.Client.Snapshot.List(context.TODO(), &govultr.ListOptions{
PerPage: 100,
Cursor: "",
})
Expand Down
36 changes: 30 additions & 6 deletions provider/vultr/vultr_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/nanovms/ops/lepton"
"github.com/nanovms/ops/log"
"github.com/olekukonko/tablewriter"
"github.com/vultr/govultr/v2"
"github.com/vultr/govultr/v3"
)

// CreateInstance - Creates instance on Digital Ocean Platform
Expand All @@ -30,13 +30,37 @@ func (v *Vultr) CreateInstance(ctx *lepton.Context) error {

zone := stripZone(c.CloudConfig.Zone)

instance, err := v.Client.Instance.Create(context.TODO(), &govultr.InstanceCreateReq{
ig := &govultr.InstanceCreateReq{
Region: zone,
Plan: flavor,
SnapshotID: c.CloudConfig.ImageName,
Tags: []string{"created-by-ops"},
})
}

cloudConfig := ctx.Config().CloudConfig
if cloudConfig.StaticIP != "" {
ips, _, _, err := v.Client.ReservedIP.List(context.TODO(), nil)
if err != nil {
fmt.Println(err)
}

ipUUID := ""
for i := 0; i < len(ips); i++ {
if ips[i].Subnet == cloudConfig.StaticIP {
ipUUID = ips[i].ID
}
}

if ipUUID != "" {
ig.ReservedIPv4 = ipUUID
} else {
return fmt.Errorf("can't find the specified reserved ip")
}
}

instance, res, err := v.Client.Instance.Create(context.TODO(), ig)
if err != nil {
fmt.Println(res)
return err
}

Expand All @@ -47,7 +71,7 @@ func (v *Vultr) CreateInstance(ctx *lepton.Context) error {

// GetInstanceByName returns instance with given name
func (v *Vultr) GetInstanceByName(ctx *lepton.Context, name string) (*lepton.CloudInstance, error) {
instance, err := v.Client.Instance.Get(context.TODO(), name)
instance, _, err := v.Client.Instance.Get(context.TODO(), name)
if err != nil {
return nil, err
}
Expand All @@ -64,7 +88,7 @@ func (v *Vultr) GetInstanceByName(ctx *lepton.Context, name string) (*lepton.Clo

// GetInstances return all instances on Vultr
func (v *Vultr) GetInstances(ctx *lepton.Context) ([]lepton.CloudInstance, error) {
instances, _, err := v.Client.Instance.List(context.TODO(), &govultr.ListOptions{
instances, _, _, err := v.Client.Instance.List(context.TODO(), &govultr.ListOptions{
PerPage: 100,
Cursor: "",
Tag: "created-by-ops",
Expand Down Expand Up @@ -92,7 +116,7 @@ func (v *Vultr) GetInstances(ctx *lepton.Context) ([]lepton.CloudInstance, error
// ListInstances lists instances on v
func (v *Vultr) ListInstances(ctx *lepton.Context) error {

instances, _, err := v.Client.Instance.List(context.TODO(), &govultr.ListOptions{
instances, _, _, err := v.Client.Instance.List(context.TODO(), &govultr.ListOptions{
PerPage: 100,
Cursor: "",
Tag: "created-by-ops",
Expand Down
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

export VERSION="0.1.37"
export VERSION="0.1.38"
plat="$(uname -s | awk '{print tolower($0)}')"

# x86-linux
Expand Down

0 comments on commit 3a12f5f

Please sign in to comment.