Skip to content

Commit cd40bb0

Browse files
authored
feat: Added support for Metal Interconnections (#321)
## Description: ## What this PR does / why we need it: Added support for metal interconnections ## What issues has this PR fixed? #307
2 parents 2554db1 + 74a5014 commit cd40bb0

13 files changed

+583
-0
lines changed

cmd/cli.go

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/equinix/metal-cli/internal/gateway"
1616
"github.com/equinix/metal-cli/internal/hardware"
1717
initPkg "github.com/equinix/metal-cli/internal/init"
18+
"github.com/equinix/metal-cli/internal/interconnections"
1819
"github.com/equinix/metal-cli/internal/ips"
1920
"github.com/equinix/metal-cli/internal/metros"
2021
"github.com/equinix/metal-cli/internal/organizations"
@@ -93,5 +94,6 @@ func (cli *Cli) RegisterCommands(client *root.Client) {
9394
twofa.NewClient(client, cli.Outputer).NewCommand(),
9495
gateway.NewClient(client, cli.Outputer).NewCommand(),
9596
ports.NewClient(client, cli.Outputer).NewCommand(),
97+
interconnections.NewClient(client, cli.Outputer).NewCommand(),
9698
)
9799
}

docs/metal.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Command line interface for Equinix Metal
3636
* [metal gateway](metal_gateway.md) - Metal Gateway operations: create, delete, and retrieve.
3737
* [metal hardware-reservation](metal_hardware-reservation.md) - Hardware reservation operations: get, move.
3838
* [metal init](metal_init.md) - Create a configuration file.
39+
* [metal interconnections](metal_interconnections.md) - interconnections operations: create, get, update, delete
3940
* [metal ip](metal_ip.md) - IP address, reservations, and assignment operations: assign, unassign, remove, available, request and get.
4041
* [metal metros](metal_metros.md) - Metro operations: get.
4142
* [metal operating-systems](metal_operating-systems.md) - Operating system operations: get.

docs/metal_interconnections.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## metal interconnections
2+
3+
interconnections operations: create, get, update, delete
4+
5+
### Synopsis
6+
7+
Get information on Metro locations. For more information on https://deploy.equinix.com/developers/docs/metal/interconnections.
8+
9+
### Options
10+
11+
```
12+
-h, --help help for interconnections
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
--config string Path to JSON or YAML configuration file
19+
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep
20+
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters.
21+
--http-header strings Headers to add to requests (in format key=value)
22+
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
23+
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
24+
--search string Search keyword for use in 'get' actions. Search is not supported by all resources.
25+
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources.
26+
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources.
27+
--token string Metal API Token (METAL_AUTH_TOKEN)
28+
```
29+
30+
### SEE ALSO
31+
32+
* [metal](metal.md) - Command line interface for Equinix Metal
33+
* [metal interconnections create](metal_interconnections_create.md) - Creates an interconnection.
34+
* [metal interconnections delete](metal_interconnections_delete.md) - Deletes a interconnection.
35+
* [metal interconnections get](metal_interconnections_get.md) - Retrieves interconnections for the current user, an organization, a project or the details of a specific interconnection.
36+
* [metal interconnections update](metal_interconnections_update.md) - Updates a connection.
37+

docs/metal_interconnections_create.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## metal interconnections create
2+
3+
Creates an interconnection.
4+
5+
### Synopsis
6+
7+
Creates a new interconnection as per the organization ID or project ID
8+
9+
```
10+
metal interconnections create -n <name> [-m <metro>] [-r <redundancy> ] [-t <type> ] [-p <project_id> ] | [-O <organization_id> ] [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
# Creates a new interconnection named "it-interconnection":
17+
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "dedicated" ] [-p <project_id>] | [-O <organization_id>]
18+
19+
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type>
20+
21+
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type> -v <vrfs>
22+
```
23+
24+
### Options
25+
26+
```
27+
-h, --help help for create
28+
-m, --metro string metro in the interconnection
29+
-n, --name string Name of the interconnection
30+
-O, --organizationID string Org ID
31+
-p, --projectID string project ID
32+
-r, --redundancy string Website URL of the organization.
33+
-t, --type string type of of interconnection.
34+
-v, --vrfs strings Return only the specified vrfs.
35+
```
36+
37+
### Options inherited from parent commands
38+
39+
```
40+
--config string Path to JSON or YAML configuration file
41+
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep
42+
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters.
43+
--http-header strings Headers to add to requests (in format key=value)
44+
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
45+
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
46+
--search string Search keyword for use in 'get' actions. Search is not supported by all resources.
47+
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources.
48+
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources.
49+
--token string Metal API Token (METAL_AUTH_TOKEN)
50+
```
51+
52+
### SEE ALSO
53+
54+
* [metal interconnections](metal_interconnections.md) - interconnections operations: create, get, update, delete
55+

docs/metal_interconnections_delete.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## metal interconnections delete
2+
3+
Deletes a interconnection.
4+
5+
### Synopsis
6+
7+
Deletes the specified interconnection.
8+
9+
```
10+
metal interconnections delete -i <connection_id> [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
# Deletes the specified interconnection:
17+
metal interconnections delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help help for delete
24+
-i, --id string The UUID of the interconnection.
25+
```
26+
27+
### Options inherited from parent commands
28+
29+
```
30+
--config string Path to JSON or YAML configuration file
31+
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep
32+
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters.
33+
--http-header strings Headers to add to requests (in format key=value)
34+
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
35+
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
36+
--search string Search keyword for use in 'get' actions. Search is not supported by all resources.
37+
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources.
38+
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources.
39+
--token string Metal API Token (METAL_AUTH_TOKEN)
40+
```
41+
42+
### SEE ALSO
43+
44+
* [metal interconnections](metal_interconnections.md) - interconnections operations: create, get, update, delete
45+

docs/metal_interconnections_get.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## metal interconnections get
2+
3+
Retrieves interconnections for the current user, an organization, a project or the details of a specific interconnection.
4+
5+
### Synopsis
6+
7+
Retrieves interconnections for the current user, an organization, a project or the details of a specific interconnection.
8+
9+
```
10+
metal interconnections get [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
# Retrieve all interconnections of a current user::
17+
18+
# Retrieve the details of a specific interconnection:
19+
metal interconnections get -i e9a969b3-8911-4667-9d99-57cd3dd4ef6f
20+
21+
# Retrieve all the interconnection of an organization:
22+
metal interconnections get -O c079178c-9557-48f2-9ce7-cfb927b81928
23+
24+
# Retrieve all interconnection of a project:
25+
metal interconnections get -p 1867ee8f-6a11-470a-9505-952d6a324040
26+
```
27+
28+
### Options
29+
30+
```
31+
-i, --connID string UUID of the interconnection
32+
-h, --help help for get
33+
-O, --organizationID string UUID of the organization
34+
-p, --projectID string Project ID (METAL_PROJECT_ID)
35+
```
36+
37+
### Options inherited from parent commands
38+
39+
```
40+
--config string Path to JSON or YAML configuration file
41+
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep
42+
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters.
43+
--http-header strings Headers to add to requests (in format key=value)
44+
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
45+
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
46+
--search string Search keyword for use in 'get' actions. Search is not supported by all resources.
47+
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources.
48+
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources.
49+
--token string Metal API Token (METAL_AUTH_TOKEN)
50+
```
51+
52+
### SEE ALSO
53+
54+
* [metal interconnections](metal_interconnections.md) - interconnections operations: create, get, update, delete
55+

docs/metal_interconnections_update.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## metal interconnections update
2+
3+
Updates a connection.
4+
5+
### Synopsis
6+
7+
Updates a specified connection.
8+
9+
```
10+
metal interconnections update -i <connection_id> [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
# Updates a specified connection.:
17+
metal interconnections update --id 30c15082-a06e-4c43-bfc3-252616b46eba -n [<name>] -d [<description>] -r [<'redundant'|'primary'>]-m [<standard|tunnel>] -e [<E-mail>] --tags="tag1,tag2"
18+
```
19+
20+
### Options
21+
22+
```
23+
-e, --contactEmail string adds or updates the Email
24+
-d, --description string Adds or updates the description for the interconnection.
25+
-h, --help help for update
26+
-i, --id string The UUID of the interconnection.
27+
-m, --mode string Adds or updates the mode for the interconnection.
28+
-n, --name string The new name of the interconnection.
29+
-r, --redundancy string Updating from 'redundant' to 'primary' will remove a secondary port, while updating from 'primary' to 'redundant' will add one.
30+
-t, --tags strings Adds or updates the tags for the connection --tags="tag1,tag2".
31+
```
32+
33+
### Options inherited from parent commands
34+
35+
```
36+
--config string Path to JSON or YAML configuration file
37+
--exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep
38+
--filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters.
39+
--http-header strings Headers to add to requests (in format key=value)
40+
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
41+
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
42+
--search string Search keyword for use in 'get' actions. Search is not supported by all resources.
43+
--sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources.
44+
--sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources.
45+
--token string Metal API Token (METAL_AUTH_TOKEN)
46+
```
47+
48+
### SEE ALSO
49+
50+
* [metal interconnections](metal_interconnections.md) - interconnections operations: create, get, update, delete
51+

internal/interconnections/create.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package interconnections
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
metal "github.com/equinix-labs/metal-go/metal/v1"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func (c *Client) Create() *cobra.Command {
12+
var name, metro, redundancy, connType, projectID, organizationID string
13+
var vrfs []string
14+
15+
createInterconnectionsCmd := &cobra.Command{
16+
Use: `create -n <name> [-m <metro>] [-r <redundancy> ] [-t <type> ] [-p <project_id> ] | [-O <organization_id> ]`,
17+
Short: "Creates an interconnection.",
18+
Long: "Creates a new interconnection as per the organization ID or project ID ",
19+
Example: ` # Creates a new interconnection named "it-interconnection":
20+
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "dedicated" ] [-p <project_id>] | [-O <organization_id>]
21+
22+
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type>
23+
24+
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type> -v <vrfs>`,
25+
26+
RunE: func(cmd *cobra.Command, args []string) error {
27+
cmd.SilenceUsage = true
28+
var interconn *metal.Interconnection
29+
var err error
30+
31+
createOrganizationInterconnectionRequest := metal.CreateOrganizationInterconnectionRequest{DedicatedPortCreateInput: metal.NewDedicatedPortCreateInput(metro, name, redundancy, metal.DedicatedPortCreateInputType(connType))}
32+
if projectID != "" {
33+
34+
interconn, _, err = c.Service.CreateProjectInterconnection(context.Background(), projectID).CreateOrganizationInterconnectionRequest(createOrganizationInterconnectionRequest).Execute()
35+
if err != nil {
36+
return fmt.Errorf("could not create interconnections: %w", err)
37+
38+
}
39+
} else if organizationID != "" {
40+
interconn, _, err = c.Service.CreateOrganizationInterconnection(context.Background(), organizationID).CreateOrganizationInterconnectionRequest(createOrganizationInterconnectionRequest).Execute()
41+
if err != nil {
42+
return fmt.Errorf("could not create interconnections: %w", err)
43+
}
44+
} else {
45+
return fmt.Errorf("Could you provide at least either of projectID OR organizationID")
46+
}
47+
48+
data := make([][]string, 1)
49+
50+
data[0] = []string{interconn.GetId(), interconn.GetName(), string(interconn.GetType()), interconn.GetCreatedAt().String()}
51+
header := []string{"ID", "Name", "Type", "Created"}
52+
53+
return c.Out.Output(interconn, header, &data)
54+
},
55+
}
56+
57+
createInterconnectionsCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the interconnection")
58+
createInterconnectionsCmd.Flags().StringVarP(&metro, "metro", "m", "", "metro in the interconnection")
59+
createInterconnectionsCmd.Flags().StringVarP(&redundancy, "redundancy", "r", "", "Website URL of the organization.")
60+
createInterconnectionsCmd.Flags().StringVarP(&connType, "type", "t", "", "type of of interconnection.")
61+
// createInterconnectionsCmd.Flags().StringVarP(&connType, "serviceTokentype", "T", "", "service token type for interconnection either fabric OR Metal builds")
62+
createInterconnectionsCmd.Flags().StringSliceVarP(&vrfs, "vrfs", "v", []string{}, "Return only the specified vrfs.")
63+
createInterconnectionsCmd.Flags().StringVarP(&projectID, "projectID", "p", "", "project ID")
64+
createInterconnectionsCmd.Flags().StringVarP(&organizationID, "organizationID", "O", "", "Org ID")
65+
66+
_ = createInterconnectionsCmd.MarkFlagRequired("name")
67+
_ = createInterconnectionsCmd.MarkFlagRequired("metro")
68+
_ = createInterconnectionsCmd.MarkFlagRequired("redundancy")
69+
_ = createInterconnectionsCmd.MarkFlagRequired("type")
70+
return createInterconnectionsCmd
71+
}

internal/interconnections/delete.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package interconnections
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func (c *Client) Delete() *cobra.Command {
11+
var connectionID string
12+
13+
deleteConnectionCmd := &cobra.Command{
14+
Use: `delete -i <connection_id> `,
15+
Short: "Deletes a interconnection.",
16+
Long: "Deletes the specified interconnection.",
17+
Example: ` # Deletes the specified interconnection:
18+
metal interconnections delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277`,
19+
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
cmd.SilenceUsage = true
22+
23+
_, _, err := c.Service.DeleteInterconnection(context.Background(), connectionID).Execute()
24+
if err != nil {
25+
return err
26+
}
27+
fmt.Println("connection deletion initiated. Please check 'metal interconnections get -i", connectionID, "' for status")
28+
29+
return nil
30+
},
31+
}
32+
33+
deleteConnectionCmd.Flags().StringVarP(&connectionID, "id", "i", "", "The UUID of the interconnection.")
34+
_ = deleteConnectionCmd.MarkFlagRequired("id")
35+
36+
return deleteConnectionCmd
37+
}

0 commit comments

Comments
 (0)