diff --git a/cmd/reservedIP.go b/cmd/reservedIP.go index 543c3e56..011e318b 100644 --- a/cmd/reservedIP.go +++ b/cmd/reservedIP.go @@ -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.") @@ -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 ", + 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") @@ -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) @@ -100,8 +189,9 @@ var reservedIPList = &cobra.Command{ var reservedIPDelete = &cobra.Command{ Use: "delete ", 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") @@ -120,9 +210,11 @@ var reservedIPDelete = &cobra.Command{ } var reservedIPAttach = &cobra.Command{ - Use: "attach ", - Short: "attach a reservedIP to an instance", - Long: ``, + Use: "attach ", + 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") @@ -142,9 +234,11 @@ var reservedIPAttach = &cobra.Command{ } var reservedIPDetach = &cobra.Command{ - Use: "detach ", - Short: "detach a reservedIP to an instance", - Long: ``, + Use: "detach ", + 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") @@ -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") @@ -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") @@ -208,3 +306,33 @@ var reservedIPCreate = &cobra.Command{ printer.ReservedIP(r) }, } + +var reservedIPUpdate = &cobra.Command{ + Use: "update ", + 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) + }, +} diff --git a/go.mod b/go.mod index 3111761d..f4d27d79 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 5046dfae..9e7d952b 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/vendor/github.com/vultr/govultr/v2/CHANGELOG.md b/vendor/github.com/vultr/govultr/v2/CHANGELOG.md index cb483763..f38c8813 100644 --- a/vendor/github.com/vultr/govultr/v2/CHANGELOG.md +++ b/vendor/github.com/vultr/govultr/v2/CHANGELOG.md @@ -2,6 +2,11 @@ ## GoVultr v1 changelog is located [here](https://github.com/vultr/govultr/blob/v1/CHANGELOG.md) +## [v2.17.2](https://github.com/vultr/govultr/compare/v2.17.1...v2.17.2) (2022-06-13) + +### Enhancement +* Reserved IP: Add support for updating label [227](https://github.com/vultr/govultr/pull/227) + ## [v2.17.1](https://github.com/vultr/govultr/compare/v2.17.0...v2.17.1) (2022-06-02) * Plans: Add GPU specific fields to plan struct [224](https://github.com/vultr/govultr/pull/224) diff --git a/vendor/github.com/vultr/govultr/v2/govultr.go b/vendor/github.com/vultr/govultr/v2/govultr.go index 847cd7ef..f9896434 100644 --- a/vendor/github.com/vultr/govultr/v2/govultr.go +++ b/vendor/github.com/vultr/govultr/v2/govultr.go @@ -16,7 +16,7 @@ import ( ) const ( - version = "2.17.1" + version = "2.17.2" defaultBase = "https://api.vultr.com" userAgent = "govultr/" + version rateLimit = 500 * time.Millisecond diff --git a/vendor/github.com/vultr/govultr/v2/reserved_ip.go b/vendor/github.com/vultr/govultr/v2/reserved_ip.go index 18c43bab..8cdc07ec 100644 --- a/vendor/github.com/vultr/govultr/v2/reserved_ip.go +++ b/vendor/github.com/vultr/govultr/v2/reserved_ip.go @@ -14,6 +14,7 @@ const ripPath = "/v2/reserved-ips" // Link : https://www.vultr.com/api/#tag/reserved-ip type ReservedIPService interface { Create(ctx context.Context, ripCreate *ReservedIPReq) (*ReservedIP, error) + Update(ctx context.Context, id string, ripUpdate *ReservedIPUpdateReq) (*ReservedIP, error) Get(ctx context.Context, id string) (*ReservedIP, error) Delete(ctx context.Context, id string) error List(ctx context.Context, options *ListOptions) ([]ReservedIP, *Meta, error) @@ -48,6 +49,11 @@ type ReservedIPReq struct { InstanceID string `json:"instance_id,omitempty"` } +// ReservedIPUpdateReq represents the parameters for updating a Reserved IP on Vultr +type ReservedIPUpdateReq struct { + Label *string `json:"label"` +} + type reservedIPsBase struct { ReservedIPs []ReservedIP `json:"reserved_ips"` Meta *Meta `json:"meta"` @@ -78,6 +84,22 @@ func (r *ReservedIPServiceHandler) Create(ctx context.Context, ripCreate *Reserv return rip.ReservedIP, nil } +// Update updates label on the Reserved IP +func (r *ReservedIPServiceHandler) Update(ctx context.Context, id string, ripUpdate *ReservedIPUpdateReq) (*ReservedIP, error) { + uri := fmt.Sprintf("%s/%s", ripPath, id) + req, err := r.client.NewRequest(ctx, http.MethodPatch, uri, ripUpdate) + if err != nil { + return nil, err + } + + rip := new(reservedIPBase) + if err = r.client.DoWithContext(ctx, req, rip); err != nil { + return nil, err + } + + return rip.ReservedIP, nil +} + // Get gets the reserved IP associated with provided ID func (r *ReservedIPServiceHandler) Get(ctx context.Context, id string) (*ReservedIP, error) { uri := fmt.Sprintf("%s/%s", ripPath, id) diff --git a/vendor/modules.txt b/vendor/modules.txt index 5f1fc1ef..58417e03 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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