Skip to content

Commit

Permalink
Refactor bgp dynamic neighbour subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Rangwala <[email protected]>
  • Loading branch information
aayushrangwala committed Jan 25, 2024
1 parent aaf1ec5 commit 1c1bdb5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 95 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/equinix/equinix-sdk-go v0.31.2 h1:7aFyKtuja2OSd7ocIHW/YugeubWIQUcVb1+g1cRbiZo=
github.com/equinix/equinix-sdk-go v0.31.2/go.mod h1:qnpdRzVftHFNaJFk1VSIrAOTLrIoeDrxzUr3l8ARyvQ=
github.com/equinix/equinix-sdk-go v0.32.0 h1:zUn0Em5FJe6f6bntftrDBpO9L+XhbpFMPuQ7RKEOgXM=
github.com/equinix/equinix-sdk-go v0.32.0/go.mod h1:qnpdRzVftHFNaJFk1VSIrAOTLrIoeDrxzUr3l8ARyvQ=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand Down
55 changes: 0 additions & 55 deletions internal/gateway/bgp-dynamic-neighbours/bgp-dynamic-neighbours.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package bgp_dynamic_neighbours
package gateway

import (
"context"
Expand All @@ -31,16 +31,19 @@ import (
"github.com/spf13/cobra"
)

func (c *Client) Create() *cobra.Command {
func (c *Client) CreateBgpNeighbours() *cobra.Command {
var gatewayId, bgpNeighbourRange string
var asn int32

// createGwBgpCmd represents the creation of gateway bgp dynamic neighbour command
createGwBgpCmd := &cobra.Command{
Use: `create`,
Short: "",
Long: "",
Example: ``,
Use: `create-bgp-dynamic-neighbours`,
Short: "Creates a BGP Dynamic Neighbour",
Long: "Creates the BGP Dynamic Neighbour for the metal gateway with the specified IP Range and ASN",
Example: `# Create a BGP Dynamic Neighbour using ip range and asn for the gateway-id
metal gateways create-bgp-dynamic-neighbour --gateway-id "9c56fa1d-ec05-470b-a938-0e5dd6a1540c" --bgp-neighbour-range "10.70.43.226/29" --asn 65000
`,

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
Expand All @@ -55,7 +58,7 @@ func (c *Client) Create() *cobra.Command {
return nil
}

bgpNeighbour, _, err := c.Service.
bgpNeighbour, _, err := c.VrfService.
CreateBgpDynamicNeighbor(context.Background(), gatewayId).
BgpDynamicNeighborCreateInput(*metal.NewBgpDynamicNeighborCreateInput(bgpNeighbourRange, asn)).
Include(c.Servicer.Includes([]string{"created_by"})).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package bgp_dynamic_neighbours
package gateway

import (
"context"
Expand All @@ -29,20 +29,25 @@ import (
"github.com/spf13/cobra"
)

func (c *Client) Delete() *cobra.Command {
func (c *Client) DeleteBgpNeighbours() *cobra.Command {
var bgpNeighbourId string

// deleteGwBgpCmd represents the delete gateway bgp dynamic neighbour command
deleteGwBgpCmd := &cobra.Command{
Use: `delete`,
Short: "",
Long: "",
Example: ``,
Use: `delete-bgp-dynamic-neighbours`,
Short: "Deletes a BGP Dynamic Neighbour",
Long: "Deletes the BGP Dynamic Neighbour for the metal gateway with the specified ID",
Example: `# Deletes a BGP Dynamic Neighbour using the bgp dynamic neighbour ID
$ metal gateways delete-bgp-dynamic-neighbour --id "9c56fa1d-ec05-470b-a938-0e5dd6a1540c"
BGP Dynamic Neighbour deletion initiated. Please check 'metal gateway get-bgp-dynamic-neighbour -i 9c56fa1d-ec05-470b-a938-0e5dd6a1540c for status
`,

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

_, _, err := c.Service.
_, _, err := c.VrfService.
DeleteBgpDynamicNeighborById(context.Background(), bgpNeighbourId).
Include(c.Servicer.Includes([]string{"created_by"})).
Exclude(c.Servicer.Excludes([]string{})).
Expand All @@ -51,13 +56,13 @@ func (c *Client) Delete() *cobra.Command {
return errors.WithMessage(err, "Could not create BGP Dynamic Neighbour")
}

fmt.Println("BGP Dynamic Neighbour deletion initiated. Please check 'metal gateway bgp-dynamic-neighbour get -i", bgpNeighbourId, "' for status")
fmt.Println("BGP Dynamic Neighbour deletion initiated. Please check 'metal gateway get-bgp-dynamic-neighbour -i", bgpNeighbourId, "' for status")
return nil
},
}

deleteGwBgpCmd.Flags().StringVar(&bgpNeighbourId, "bgp-dynamic-neighbour-id", "", "")
deleteGwBgpCmd.Flags().StringVarP(&bgpNeighbourId, "id", "i", "", "")

_ = deleteGwBgpCmd.MarkFlagRequired("bgp-neighbour-id")
_ = deleteGwBgpCmd.MarkFlagRequired("id")
return deleteGwBgpCmd
}
14 changes: 9 additions & 5 deletions internal/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
package gateway

import (
neighbours "github.com/equinix/metal-cli/internal/gateway/bgp-dynamic-neighbours"
"github.com/equinix/metal-cli/internal/outputs"

metal "github.com/equinix/equinix-sdk-go/services/metalv1"
"github.com/spf13/cobra"
)

type Client struct {
Servicer Servicer
Service *metal.MetalGatewaysApiService
Out outputs.Outputer
Servicer Servicer
Service *metal.MetalGatewaysApiService
VrfService *metal.VRFsApiService
Out outputs.Outputer
}

func (c *Client) NewCommand() *cobra.Command {
Expand All @@ -48,14 +48,18 @@ func (c *Client) NewCommand() *cobra.Command {
}
}
c.Service = c.Servicer.MetalAPI(cmd).MetalGatewaysApi
c.VrfService = c.Servicer.MetalAPI(cmd).VRFsApi
},
}

cmd.AddCommand(
c.Retrieve(),
c.Create(),
c.Delete(),
neighbours.NewClient(c.Servicer, c.Out).NewCommand(),
c.CreateBgpNeighbours(),
c.DeleteBgpNeighbours(),
c.GetBgpNeighbours(),
c.ListBgpNeighbours(),
)
return cmd
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bgp_dynamic_neighbours
package gateway

import (
"context"
Expand All @@ -8,20 +8,23 @@ import (
"github.com/spf13/cobra"
)

func (c *Client) Get() *cobra.Command {
func (c *Client) GetBgpNeighbours() *cobra.Command {
var bgpNeighbourID string

// getGwayBgpDynamicNeighbourCmd represents command to get Metal Gateway Dynamic Neighbour by ID.
getGwayBgpDynamicNeighbourCmd := &cobra.Command{
Use: `get`,
Short: "",
Long: "",
Example: ``,
Use: `get-bgp-dynamic-neighbours`,
Short: "Gets a BGP Dynamic Neighbour",
Long: "Gets the BGP Dynamic Neighbour for the metal gateway with the specified ID",
Example: `# Gets a BGP Dynamic Neighbour using the bgp dynamic neighbour ID
$ metal gateways get-bgp-dynamic-neighbour --id "9c56fa1d-ec05-470b-a938-0e5dd6a1540c"
`,

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

n, _, err := c.Service.
n, _, err := c.VrfService.
BgpDynamicNeighborsIdGet(context.Background(), bgpNeighbourID).
Include(c.Servicer.Includes([]string{"created_by"})).
Exclude(c.Servicer.Excludes([]string{})).
Expand All @@ -40,7 +43,7 @@ func (c *Client) Get() *cobra.Command {
},
}

getGwayBgpDynamicNeighbourCmd.Flags().StringVar(&bgpNeighbourID, "bgp-dynamic-neighbour-id", "", "BGP Dynamic Neighbour ID. Ex: []")
_ = getGwayBgpDynamicNeighbourCmd.MarkFlagRequired("bgp-dynamic-neighbour-id")
getGwayBgpDynamicNeighbourCmd.Flags().StringVarP(&bgpNeighbourID, "id", "i", "", "BGP Dynamic Neighbour ID. Ex: []")
_ = getGwayBgpDynamicNeighbourCmd.MarkFlagRequired("id")
return getGwayBgpDynamicNeighbourCmd
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bgp_dynamic_neighbours
package gateway

import (
"context"
Expand All @@ -8,20 +8,23 @@ import (
"github.com/spf13/cobra"
)

func (c *Client) List() *cobra.Command {
func (c *Client) ListBgpNeighbours() *cobra.Command {
var gatewayId string

// createMetalGatewayCmd represents the createMetalGateway command
createMetalGatewayCmd := &cobra.Command{
Use: `list`,
Short: "",
Long: "",
Example: ``,
Use: `list-bgp-dynamic-neighbours`,
Short: "Lists BGP Dynamic Neighbours for Metal Gateway",
Long: "Lists the BGP Dynamic Neighbour for the metal gateway with the specified gateway ID",
Example: `# Lists BGP Dynamic Neighbour for the specified metal gateway ID
$ metal gateways list-bgp-dynamic-neighbour --id "9c56fa1d-ec05-470b-a938-0e5dd6a1540c"
`,

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

n, _, err := c.Service.
n, _, err := c.VrfService.
GetBgpDynamicNeighbors(context.Background(), gatewayId).
Include(c.Servicer.Includes([]string{"created_by"})).
Exclude(c.Servicer.Excludes([]string{})).
Expand Down

0 comments on commit 1c1bdb5

Please sign in to comment.