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

Update govultr and add support for reserved IP label updates #272

Merged
merged 5 commits into from
Jun 14, 2022
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
170 changes: 149 additions & 21 deletions cmd/reservedIP.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,97 @@ import (
"github.com/vultr/vultr-cli/v2/cmd/printer"
)

var (
reservedIPLong = `Get all available commands for reserved IPs`
reservedIPExample = `
# Full example
vultr-cli reserved-ip

# Shortened with aliased commands
vultr-cli rip
`

reservedIPCreateLong = `Create a reserved IP on your Vultr account`
reservedIPCreateExample = `
# Full Example
vultr-cli reserved-ip create --region="yto" --type="v4" --label="new IP"

# Shortened with alias commands
vultr-cli rip c -r="yto" -t="v4" -l="new IP"
`

reservedIPGetLong = `Get info for a reserved IP on your Vultr account`
reservedIPGetExample = `
# Full example
vultr-cli reserved-ip get 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5

# Shortened with alias commands
vultr-cli rip g 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5
`

reservedIPListLong = `List all reserved IPs on your Vultr account`
reservedIPListExample = `
# Full example
vultr-cli reserved-ip list

# Shortened with alias commands
vultr-cli rip l
`

reservedIPAttachLong = `Attach a reserved IP to an instance on your Vultr account`
reservedIPAttachExample = `
# Full example
vultr-cli reserved-ip attach 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5 --instance-id="2b9bf5fb-1644-4e0a-b706-1116ab64d783"

# Shortened with alias commands
vultr-cli rip a 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5 -i="2b9bf5fb-1644-4e0a-b706-1116ab64d783"
`

reservedIPDetachLong = `Detach a reserved IP from an instance on your Vultr account`
reservedIPDetachExample = `
# Full example
vultr-cli reserved-ip detach 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5

# Shortened with alias commands
vultr-cli rip d 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5
`

reservedIPConvertLong = `Convert an instance IP to a reserved IP on your Vultr account`
reservedIPConvertExample = `
# Full example
vultr-cli reserved-ip convert --ip="192.0.2.123" --label="new label converted"

# Shortened with alias commands
vultr-cli rip v -i="192.0.2.123" -l="new label converted"
`

reservedIPUpdateLong = `Update a reserved IP on your Vultr account`
reservedIPUpdateExample = `
# Full example
vultr-cli reserved-ip update 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5 --label="new label"

# Shortened with alias commands
vultr-cli rip u 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5 -l="new label"
`

reservedIPDeleteLong = `Delete a reserved IP from your Vultr account`
reservedIPDeleteExample = `
# Full example
vultr-cli reserved-ip delete 6a31648d-ebfa-4d43-9a00-9c9f0e5048f5
`
)

// ReservedIP represents the reservedip command
func ReservedIP() *cobra.Command {
reservedIPCmd := &cobra.Command{
Use: "reserved-ip",
Aliases: []string{"rip"},
Short: "reserved-ip lets you interact with reserved-ip ",
Long: ``,
Long: reservedIPLong,
Example: reservedIPExample,
}

reservedIPCmd.AddCommand(reservedIPGet, reservedIPList, reservedIPDelete, reservedIPAttach, reservedIPDetach, reservedIPConvert, reservedIPCreate)
reservedIPCmd.AddCommand(reservedIPGet, reservedIPList, reservedIPDelete, reservedIPAttach, reservedIPDetach, reservedIPConvert, reservedIPCreate, reservedIPUpdate)

// List
reservedIPList.Flags().StringP("cursor", "c", "", "(optional) Cursor for paging.")
Expand All @@ -56,13 +137,19 @@ func ReservedIP() *cobra.Command {
reservedIPCreate.MarkFlagRequired("type")
reservedIPCreate.Flags().StringP("label", "l", "", "label")

// Update
reservedIPUpdate.Flags().StringP("label", "l", "", "label")
reservedIPUpdate.MarkFlagRequired("label")

return reservedIPCmd
}

var reservedIPGet = &cobra.Command{
Use: "get <reservedIPID",
Short: "get a reserved IP",
Long: ``,
Use: "get <reservedIPID>",
Short: "get a reserved IP",
Long: reservedIPGetLong,
Example: reservedIPGetExample,
Aliases: []string{"g"},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("please provide a reservedIP ID")
Expand All @@ -82,9 +169,11 @@ var reservedIPGet = &cobra.Command{
}

var reservedIPList = &cobra.Command{
Use: "list",
Short: "list all reserved IPs",
Long: ``,
Use: "list",
Short: "list all reserved IPs",
Long: reservedIPListLong,
Example: reservedIPListExample,
Aliases: []string{"l"},
Run: func(cmd *cobra.Command, args []string) {
options := getPaging(cmd)
rip, meta, err := client.ReservedIP.List(context.Background(), options)
Expand All @@ -100,8 +189,9 @@ var reservedIPList = &cobra.Command{
var reservedIPDelete = &cobra.Command{
Use: "delete <reservedIPID>",
Short: "delete a reserved ip",
Long: reservedIPDeleteLong,
Example: reservedIPDeleteExample,
Aliases: []string{"destroy"},
Long: ``,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("please provide a reservedIP ID")
Expand All @@ -120,9 +210,11 @@ var reservedIPDelete = &cobra.Command{
}

var reservedIPAttach = &cobra.Command{
Use: "attach <reservedIPID>",
Short: "attach a reservedIP to an instance",
Long: ``,
Use: "attach <reservedIPID>",
Short: "attach a reservedIP to an instance",
Long: reservedIPAttachLong,
Example: reservedIPAttachExample,
Aliases: []string{"a"},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("please provide a reservedIP ID")
Expand All @@ -142,9 +234,11 @@ var reservedIPAttach = &cobra.Command{
}

var reservedIPDetach = &cobra.Command{
Use: "detach <reservedIPID>",
Short: "detach a reservedIP to an instance",
Long: ``,
Use: "detach <reservedIPID>",
Short: "detach a reservedIP to an instance",
Long: reservedIPDetachLong,
Example: reservedIPDetachExample,
Aliases: []string{"d"},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("please provide a reservedIP ID")
Expand All @@ -163,9 +257,11 @@ var reservedIPDetach = &cobra.Command{
}

var reservedIPConvert = &cobra.Command{
Use: "convert ",
Short: "convert IP address to reservedIP",
Long: ``,
Use: "convert ",
Short: "convert IP address to reservedIP",
Long: reservedIPConvertLong,
Example: reservedIPConvertExample,
Aliases: []string{"v"},
Run: func(cmd *cobra.Command, args []string) {
ip, _ := cmd.Flags().GetString("ip")
label, _ := cmd.Flags().GetString("label")
Expand All @@ -185,9 +281,11 @@ var reservedIPConvert = &cobra.Command{
}

var reservedIPCreate = &cobra.Command{
Use: "create ",
Short: "create reservedIP",
Long: ``,
Use: "create ",
Short: "create reservedIP",
Long: reservedIPCreateLong,
Example: reservedIPCreateExample,
Aliases: []string{"c"},
Run: func(cmd *cobra.Command, args []string) {
region, _ := cmd.Flags().GetString("region")
ipType, _ := cmd.Flags().GetString("type")
Expand All @@ -208,3 +306,33 @@ var reservedIPCreate = &cobra.Command{
printer.ReservedIP(r)
},
}

var reservedIPUpdate = &cobra.Command{
Use: "update <reservedIPID>",
Short: "update reservedIP",
Long: reservedIPUpdateLong,
Example: reservedIPUpdateExample,
Aliases: []string{"u"},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("please provide a reserved IP ID")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
label, _ := cmd.Flags().GetString("label")
ip := args[0]

options := &govultr.ReservedIPUpdateReq{
Label: govultr.StringToStringPtr(label),
}

r, err := client.ReservedIP.Update(context.Background(), ip, options)
if err != nil {
fmt.Printf("error updating reserved IPs : %v\n", err)
os.Exit(1)
}

printer.ReservedIP(r)
},
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
require (
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.12.0
github.com/vultr/govultr/v2 v2.17.1
github.com/vultr/govultr/v2 v2.17.2
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/subosito/gotenv v1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI=
github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/vultr/govultr/v2 v2.17.1 h1:UBmotwA0mkGtyJMakUF9jhLH/W3mN5wfGRn543i/BCA=
github.com/vultr/govultr/v2 v2.17.1/go.mod h1:ZFOKGWmgjytfyjeyAdhQlSWwTjh2ig+X49cAp50dzXI=
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/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
5 changes: 5 additions & 0 deletions vendor/github.com/vultr/govultr/v2/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/vultr/govultr/v2/govultr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/vultr/govultr/v2/reserved_ip.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ github.com/spf13/viper/internal/encoding/yaml
# github.com/subosito/gotenv v1.3.0
## explicit; go 1.18
github.com/subosito/gotenv
# github.com/vultr/govultr/v2 v2.17.1
# github.com/vultr/govultr/v2 v2.17.2
## explicit; go 1.17
github.com/vultr/govultr/v2
# golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2
Expand Down