-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from equinix/bgp-enable
add BGP commands for enabling, getting, and session listing
- Loading branch information
Showing
12 changed files
with
377 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.