Skip to content

Commit

Permalink
Merge pull request #177 from equinix/bgp-enable
Browse files Browse the repository at this point in the history
add BGP commands for enabling, getting, and session listing
  • Loading branch information
cprivitere authored Jun 17, 2022
2 parents 8885fc7 + d907509 commit 9296126
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 26 deletions.
3 changes: 3 additions & 0 deletions docs/metal_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Project operations: create, get, update, and delete.
### SEE ALSO

* [metal](metal.md) - Command line interface for Equinix Metal
* [metal project bgp-config](metal_project_bgp-config.md) - Gets BGP Config for a project.
* [metal project bgp-enable](metal_project_bgp-enable.md) - Enables BGP on a project.
* [metal project bgp-sessions](metal_project_bgp-sessions.md) - Gets BGP Sessions for a project.
* [metal project create](metal_project_create.md) - Creates a project.
* [metal project delete](metal_project_delete.md) - Deletes a project.
* [metal project get](metal_project_get.md) - Retrieves all the current user's projects or the details of a specified project.
Expand Down
44 changes: 44 additions & 0 deletions docs/metal_project_bgp-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## metal project bgp-config

Gets BGP Config for a project.

### Synopsis

Gets BGP Config for a project.

```
metal project bgp-config --project-id <project_UUID> [flags]
```

### Examples

```
# Get BGP config for project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375:
metal project bgp-config --project-id 50693ba9-e4e4-4d8a-9eb2-4840b11e9375
```

### Options

```
-h, --help help for bgp-config
-p, --project-id string Project ID (METAL_PROJECT_ID)
```

### Options inherited from parent commands

```
--config string Path to JSON or YAML configuration file
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters.
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
-o, --output string Output format (*table, json, yaml)
--search string Search keyword for use in 'get' actions. Search is not supported by all resources.
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources.
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources.
--token string Metal API Token (METAL_AUTH_TOKEN)
```

### SEE ALSO

* [metal project](metal_project.md) - Project operations. For more information on Equinix Metal Projects, visit https://metal.equinix.com/developers/docs/accounts/projects/.

48 changes: 48 additions & 0 deletions docs/metal_project_bgp-enable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## metal project bgp-enable

Enables BGP on a project.

### Synopsis

Enables BGP on a project.

```
metal project bgp-enable --project-id <project_UUID> --deployment-type <deployment_type> [--asn <asn>] [--md5 <md5_secret>] [--use-case <use_case>] [flags]
```

### Examples

```
# Enable BGP on project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375:
metal project bgp-enable --project-id 50693ba9-e4e4-4d8a-9eb2-4840b11e9375 --deployment-type local --asn 65000
```

### Options

```
--asn int Local ASN (default 65000)
--deployment-type string Deployment type (local, global)
-h, --help help for bgp-enable
--md5 string BGP Password
-p, --project-id string Project ID (METAL_PROJECT_ID)
--use-case string Use case for BGP
```

### Options inherited from parent commands

```
--config string Path to JSON or YAML configuration file
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters.
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
-o, --output string Output format (*table, json, yaml)
--search string Search keyword for use in 'get' actions. Search is not supported by all resources.
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources.
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources.
--token string Metal API Token (METAL_AUTH_TOKEN)
```

### SEE ALSO

* [metal project](metal_project.md) - Project operations. For more information on Equinix Metal Projects, visit https://metal.equinix.com/developers/docs/accounts/projects/.

44 changes: 44 additions & 0 deletions docs/metal_project_bgp-sessions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## metal project bgp-sessions

Gets BGP Sessions for a project.

### Synopsis

Gets BGP Sessions for a project.

```
metal project bgp-sessions --project-id <project_UUID> [flags]
```

### Examples

```
# Get BGP Sessions for project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375:
metal project bgp-sessions --project-id 50693ba9-e4e4-4d8a-9eb2-4840b11e9375
```

### Options

```
-h, --help help for bgp-sessions
-p, --project-id string Project ID (METAL_PROJECT_ID)
```

### Options inherited from parent commands

```
--config string Path to JSON or YAML configuration file
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters.
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
-o, --output string Output format (*table, json, yaml)
--search string Search keyword for use in 'get' actions. Search is not supported by all resources.
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources.
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources.
--token string Metal API Token (METAL_AUTH_TOKEN)
```

### SEE ALSO

* [metal project](metal_project.md) - Project operations. For more information on Equinix Metal Projects, visit https://metal.equinix.com/developers/docs/accounts/projects/.

62 changes: 62 additions & 0 deletions internal/projects/bgpconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright © 2022 Equinix Metal Developers <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package projects

import (
"strconv"

"github.com/packethost/packngo"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

func (c *Client) BGPConfig() *cobra.Command {
var projectID string

// bgpConfigProjectCmd represents the updateProject command
bgpConfigProjectCmd := &cobra.Command{
Use: `bgp-config --project-id <project_UUID>`,
Short: "Gets BGP Config for a project.",
Long: `Gets BGP Config for a project.`,
Example: ` # Get BGP config for project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375:
metal project bgp-config --project-id 50693ba9-e4e4-4d8a-9eb2-4840b11e9375`,
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
listOpt := c.Servicer.ListOptions(nil, nil)
getOpts := &packngo.GetOptions{Includes: listOpt.Includes, Excludes: listOpt.Excludes}
p, _, err := c.BGPConfigService.Get(projectID, getOpts)
if err != nil {
return errors.Wrap(err, "Could not get Project BGP Config")
}

data := make([][]string, 1)

data[0] = []string{projectID, p.Status, strconv.Itoa(p.Asn), p.DeploymentType, strconv.Itoa(p.MaxPrefix)}
header := []string{"ID", "Status", "Sessions", "ASN", "DeploymentType", "MaxPrefix"}
return c.Out.Output(p, header, &data)
},
}

bgpConfigProjectCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "Project ID (METAL_PROJECT_ID)")

_ = bgpConfigProjectCmd.MarkFlagRequired("project-id")
return bgpConfigProjectCmd
}
75 changes: 75 additions & 0 deletions internal/projects/bgpenable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright © 2022 Equinix Metal Developers <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package projects

import (
"strconv"

"github.com/packethost/packngo"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

func (c *Client) BGPEnable() *cobra.Command {
var (
projectID, useCase, md5, deploymentType string
asn int
)
// bgpEnableProjectCmd represents the updateProject command
bgpEnableProjectCmd := &cobra.Command{
Use: `bgp-enable --project-id <project_UUID> --deployment-type <deployment_type> [--asn <asn>] [--md5 <md5_secret>] [--use-case <use_case>]`,
Short: "Enables BGP on a project.",
Long: `Enables BGP on a project.`,
Example: ` # Enable BGP on project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375:
metal project bgp-enable --project-id 50693ba9-e4e4-4d8a-9eb2-4840b11e9375 --deployment-type local --asn 65000`,
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
req := packngo.CreateBGPConfigRequest{
UseCase: useCase,
Asn: asn,
DeploymentType: deploymentType,
Md5: md5,
}

p, err := c.BGPConfigService.Create(projectID, req)
if err != nil {
return errors.Wrap(err, "Could not update Project")
}

data := make([][]string, 1)

data[0] = []string{projectID, useCase, strconv.Itoa(asn), deploymentType}
header := []string{"ID", "UseCase", "ASN", "DeploymentType"}
return c.Out.Output(p, header, &data)
},
}

bgpEnableProjectCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "Project ID (METAL_PROJECT_ID)")
bgpEnableProjectCmd.Flags().StringVar(&useCase, "use-case", "", "Use case for BGP")
bgpEnableProjectCmd.Flags().IntVar(&asn, "asn", 65000, "Local ASN")
bgpEnableProjectCmd.Flags().StringVar(&deploymentType, "deployment-type", "", "Deployment type (local, global)")
bgpEnableProjectCmd.Flags().StringVar(&md5, "md5", "", "BGP Password")

_ = bgpEnableProjectCmd.MarkFlagRequired("project-id")
_ = bgpEnableProjectCmd.MarkFlagRequired("asn")
_ = bgpEnableProjectCmd.MarkFlagRequired("deployment-type")
return bgpEnableProjectCmd
}
69 changes: 69 additions & 0 deletions internal/projects/bgpsessions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright © 2022 Equinix Metal Developers <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package projects

import (
"strconv"
"strings"

"github.com/packethost/packngo"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

func (c *Client) BGPSessions() *cobra.Command {
var projectID string

// bgpSessionsProjectCmd represents the updateProject command
bgpSessionsProjectCmd := &cobra.Command{
Use: `bgp-sessions --project-id <project_UUID>`,
Short: "Gets BGP Sessions for a project.",
Long: `Gets BGP Sessions for a project.`,
Example: ` # Get BGP Sessions for project 50693ba9-e4e4-4d8a-9eb2-4840b11e9375:
metal project bgp-sessions --project-id 50693ba9-e4e4-4d8a-9eb2-4840b11e9375`,
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
listOpt := c.Servicer.ListOptions(nil, nil)
getOpts := &packngo.GetOptions{Includes: listOpt.Includes, Excludes: listOpt.Excludes}
p, _, err := c.BGPConfigService.Get(projectID, getOpts)
if err != nil {
return errors.Wrap(err, "Could not get Project BGP Sessions")
}

data := make([][]string, len(p.Sessions))
for i, s := range p.Sessions {
data[i] = []string{
s.ID,
s.Status,
strings.Join(s.LearnedRoutes, ","),
strconv.FormatBool(s.DefaultRoute != nil && *s.DefaultRoute),
}
}
header := []string{"ID", "Status", "Learned Routes", "Default Route"}
return c.Out.Output(p, header, &data)
},
}

bgpSessionsProjectCmd.Flags().StringVarP(&projectID, "project-id", "p", "", "Project ID (METAL_PROJECT_ID)")

_ = bgpSessionsProjectCmd.MarkFlagRequired("project-id")
return bgpSessionsProjectCmd
}
8 changes: 4 additions & 4 deletions internal/projects/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func (c *Client) Create() *cobra.Command {
)

// projectCreateCmd represents the projectCreate command
var createProjectCmd = &cobra.Command{
Use: `create -n <project_name> [-O <organization_UUID>] [-m <payment_method_UUID>]`,
createProjectCmd := &cobra.Command{
Use: `create -n <project_name> [-O <organization_UUID>] [-m <payment_method_UUID>]`,
Short: "Creates a project.",
Long: "Creates a project with the specified name. If no organization is specified, the project is created in the current user's default organization. If no payment method is specified the organization's default payment method is used.",
Long: "Creates a project with the specified name. If no organization is specified, the project is created in the current user's default organization. If no payment method is specified the organization's default payment method is used.",
Example: ` # Creates a new project named dev-cluster02:
metal project create --name dev-cluster02
Expand All @@ -58,7 +58,7 @@ func (c *Client) Create() *cobra.Command {
req.PaymentMethodID = paymentMethodID
}

p, _, err := c.Service.Create(&req)
p, _, err := c.ProjectService.Create(&req)
if err != nil {
return errors.Wrap(err, "Could not create Project")
}
Expand Down
Loading

0 comments on commit 9296126

Please sign in to comment.