Skip to content

Commit

Permalink
Added support for Metal Interconnections
Browse files Browse the repository at this point in the history
  • Loading branch information
codinja1188 committed Oct 12, 2023
1 parent ccfb9bd commit c69a457
Show file tree
Hide file tree
Showing 15 changed files with 618 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/equinix/metal-cli/internal/gateway"
"github.com/equinix/metal-cli/internal/hardware"
initPkg "github.com/equinix/metal-cli/internal/init"
"github.com/equinix/metal-cli/internal/interconnections"
"github.com/equinix/metal-cli/internal/ips"
"github.com/equinix/metal-cli/internal/metros"
"github.com/equinix/metal-cli/internal/organizations"
Expand Down Expand Up @@ -93,5 +94,6 @@ func (cli *Cli) RegisterCommands(client *root.Client) {
twofa.NewClient(client, cli.Outputer).NewCommand(),
gateway.NewClient(client, cli.Outputer).NewCommand(),
ports.NewClient(client, cli.Outputer).NewCommand(),
interconnections.NewClient(client, cli.Outputer).NewCommand(),
)
}
1 change: 1 addition & 0 deletions docs/metal.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Command line interface for Equinix Metal
* [metal gateway](metal_gateway.md) - Metal Gateway operations: create, delete, and retrieve.
* [metal hardware-reservation](metal_hardware-reservation.md) - Hardware reservation operations: get, move.
* [metal init](metal_init.md) - Create a configuration file.
* [metal interconnections](metal_interconnections.md) - interconnections operations: create, get.
* [metal ip](metal_ip.md) - IP address, reservations, and assignment operations: assign, unassign, remove, available, request and get.
* [metal metros](metal_metros.md) - Metro operations: get.
* [metal operating-systems](metal_operating-systems.md) - Operating system operations: get.
Expand Down
36 changes: 36 additions & 0 deletions docs/metal_interconnections.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## metal interconnections

interconnections operations: create, get.

### Synopsis

Get information on Metro locations. For more information on https://deploy.equinix.com/developers/docs/metal/interconnections.

### Options

```
-h, --help help for interconnections
```

### 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.
--http-header strings Headers to add to requests (in format key=value)
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
--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](metal.md) - Command line interface for Equinix Metal
* [metal interconnections create](metal_interconnections_create.md) - Creates an interconnection.
* [metal interconnections delete](metal_interconnections_delete.md) - Deletes a interconnection.
* [metal interconnections get](metal_interconnections_get.md) - Retrieves interconnections for the current user, an organization, a project or the details of a specific interconnection.

55 changes: 55 additions & 0 deletions docs/metal_interconnections_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## metal interconnections create

Creates an interconnection.

### Synopsis

Creates a new interconnection as per the organization ID or project ID

```
metal interconnections create -n <name> [-m <metro>] [-r <redundancy> ] [-t <type> ] [-p <project_id> ] | [-O <organization_id> ] [flags]
```

### Examples

```
# Creates a new interconnection named "it-interconnection":
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "dedicated" ] [-p <project_id>] | [-O <organization_id>]
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type>
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type> -v <vrfs>
```

### Options

```
-h, --help help for create
-m, --metro string metro in the interconnection
-n, --name string Name of the interconnection
-O, --organizationID string Org ID
-p, --projectID string project ID
-r, --redundancy string Website URL of the organization.
-t, --type string type of of interconnection.
-v, --vrfs strings Return only the specified vrfs.
```

### 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.
--http-header strings Headers to add to requests (in format key=value)
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
--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 interconnections](metal_interconnections.md) - interconnections operations: create, get.

45 changes: 45 additions & 0 deletions docs/metal_interconnections_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## metal interconnections delete

Deletes a interconnection.

### Synopsis

Deletes the specified interconnection.

```
metal interconnections delete -i <connection_id> [flags]
```

### Examples

```
# Deletes the specified interconnection:
metal interconnections delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277
```

### Options

```
-h, --help help for delete
-i, --id string The UUID of the interconnection.
```

### 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.
--http-header strings Headers to add to requests (in format key=value)
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
--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 interconnections](metal_interconnections.md) - interconnections operations: create, get.

55 changes: 55 additions & 0 deletions docs/metal_interconnections_get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## metal interconnections get

Retrieves interconnections for the current user, an organization, a project or the details of a specific interconnection.

### Synopsis

Retrieves interconnections for the current user, an organization, a project or the details of a specific interconnection.

```
metal interconnections get [flags]
```

### Examples

```
# Retrieve all interconnections of a current user::
# Retrieve the details of a specific interconnection:
metal interconnections get -i e9a969b3-8911-4667-9d99-57cd3dd4ef6f
# Retrieve all the interconnection of an organization:
metal interconnections get -O c079178c-9557-48f2-9ce7-cfb927b81928
# Retrieve all interconnection of a project:
metal interconnections get -p 1867ee8f-6a11-470a-9505-952d6a324040
```

### Options

```
-i, --connID string UUID of the interconnection
-h, --help help for get
-O, --organizationID string UUID of the organization
-p, --projectID 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.
--http-header strings Headers to add to requests (in format key=value)
--include strings Comma separated Href references to expand in results, may be dotted three levels deep
-o, --output string Output format (*table, json, yaml). env output formats are (*sh, terraform, capp).
--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 interconnections](metal_interconnections.md) - interconnections operations: create, get.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/equinix/metal-cli
go 1.19

require (
github.com/equinix-labs/metal-go v0.23.1
github.com/equinix-labs/metal-go v0.24.0
github.com/manifoldco/promptui v0.9.0
github.com/olekukonko/tablewriter v0.0.5
github.com/packethost/packngo v0.30.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/equinix-labs/metal-go v0.23.1 h1:u6rdCKW7ZN/ydxS63+cbPMjHk8wYiVPYJsb8LB1sXZM=
github.com/equinix-labs/metal-go v0.23.1/go.mod h1:SmxCklxW+KjmBLVMdEXgtFO5gD5/b4N0VxcNgUYbOH4=
github.com/equinix-labs/metal-go v0.24.0 h1:dxIZXG3P/KKHOLmFfiDpwxMmahfiwFqbzk/i0OPETvA=
github.com/equinix-labs/metal-go v0.24.0/go.mod h1:SmxCklxW+KjmBLVMdEXgtFO5gD5/b4N0VxcNgUYbOH4=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
Expand Down
71 changes: 71 additions & 0 deletions internal/interconnections/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package interconnections

import (
"context"
"fmt"

metal "github.com/equinix-labs/metal-go/metal/v1"
"github.com/spf13/cobra"
)

func (c *Client) Create() *cobra.Command {
var name, metro, redundancy, connType, projectID, organizationID string
var vrfs []string

createInterconnectionsCmd := &cobra.Command{
Use: `create -n <name> [-m <metro>] [-r <redundancy> ] [-t <type> ] [-p <project_id> ] | [-O <organization_id> ]`,
Short: "Creates an interconnection.",
Long: "Creates a new interconnection as per the organization ID or project ID ",
Example: ` # Creates a new interconnection named "it-interconnection":
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "dedicated" ] [-p <project_id>] | [-O <organization_id>]
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type>
metal interconnections create -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type> -v <vrfs>`,

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

createOrganizationInterconnectionRequest := metal.CreateOrganizationInterconnectionRequest{DedicatedPortCreateInput: metal.NewDedicatedPortCreateInput(metro, name, redundancy, metal.DedicatedPortCreateInputType(connType))}
if projectID != "" {

interconn, _, err = c.Service.CreateProjectInterconnection(context.Background(), projectID).CreateOrganizationInterconnectionRequest(createOrganizationInterconnectionRequest).Execute()
if err != nil {
return fmt.Errorf("could not create interconnections: %w", err)

}
} else if organizationID != "" {
interconn, _, err = c.Service.CreateOrganizationInterconnection(context.Background(), organizationID).CreateOrganizationInterconnectionRequest(createOrganizationInterconnectionRequest).Execute()
if err != nil {
return fmt.Errorf("could not create interconnections: %w", err)
}
} else {
return fmt.Errorf("Could you provide at least either of projectID OR organizationID")
}

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

data[0] = []string{interconn.GetId(), interconn.GetName(), string(interconn.GetType()), interconn.GetCreatedAt().String()}
header := []string{"ID", "Name", "Type", "Created"}

return c.Out.Output(interconn, header, &data)
},
}

createInterconnectionsCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the interconnection")
createInterconnectionsCmd.Flags().StringVarP(&metro, "metro", "m", "", "metro in the interconnection")
createInterconnectionsCmd.Flags().StringVarP(&redundancy, "redundancy", "r", "", "Website URL of the organization.")
createInterconnectionsCmd.Flags().StringVarP(&connType, "type", "t", "", "type of of interconnection.")
// createInterconnectionsCmd.Flags().StringVarP(&connType, "serviceTokentype", "T", "", "service token type for interconnection either fabric OR Metal builds")
createInterconnectionsCmd.Flags().StringSliceVarP(&vrfs, "vrfs", "v", []string{}, "Return only the specified vrfs.")
createInterconnectionsCmd.Flags().StringVarP(&projectID, "projectID", "p", "", "project ID")
createInterconnectionsCmd.Flags().StringVarP(&organizationID, "organizationID", "O", "", "Org ID")

_ = createInterconnectionsCmd.MarkFlagRequired("name")
_ = createInterconnectionsCmd.MarkFlagRequired("metro")
_ = createInterconnectionsCmd.MarkFlagRequired("redundancy")
_ = createInterconnectionsCmd.MarkFlagRequired("type")
return createInterconnectionsCmd
}
85 changes: 85 additions & 0 deletions internal/interconnections/createvc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package interconnections

import (
"context"
"fmt"

metal "github.com/equinix-labs/metal-go/metal/v1"
"github.com/spf13/cobra"
)

func (c *Client) CreateVirtualCricuit() *cobra.Command {
var connectionID, portID, name, description, projectID, vlanID string
var vlan, speed int
var tags []string

createVirtualCricuitCmd := &cobra.Command{
Use: `create-virtual-circuit [-i connection_id] [-p port_id] [-P <project_id> ] --n <name> [-d <description>] [-v <vlanID> ] [-t <tags> ] [-vlan <vlan> ] [-speed <speed> ]`,
Short: "Creates an create-virtual-circuit for specific interconnection.",
Long: "Creates an create-virtual-circuit for specific interconnection",
Example: ` # Creates a new interconnection named "it-interconnection":
metal interconnections create-virtual-circuit [-i connection_id] [-p port_id] [-P <project_id> ] --n <name> [-d <description>] [-v <vlanID> ] [-t <tags> ] [-vlan <vlan> ] [-speed <speed> ]
metal interconnections create-virtual-circuit -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type>
metal interconnections create-virtual-circuit -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] [-p <project_id>] | [-O <organization_id>] -T <service_token_type> -v <vrfs>`,

RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
vlanVirtualCircuitCreateInput := metal.NewVlanVirtualCircuitCreateInput(projectID)
virtualCircuitCreateInput := metal.VirtualCircuitCreateInput{VlanVirtualCircuitCreateInput: vlanVirtualCircuitCreateInput}

if description != "" {
virtualCircuitCreateInput.VlanVirtualCircuitCreateInput.SetDescription(description)
}

if name != "" {
virtualCircuitCreateInput.VlanVirtualCircuitCreateInput.SetName(name)
}

if vlan > 0 {
virtualCircuitCreateInput.VlanVirtualCircuitCreateInput.SetNniVlan(int32(vlan))
}

if speed > 0 {
virtualCircuitCreateInput.VlanVirtualCircuitCreateInput.SetSpeed(int32(speed))
}

if len(tags) > 0 {
virtualCircuitCreateInput.VlanVirtualCircuitCreateInput.SetTags(tags)
}

if vlanID != "" {
virtualCircuitCreateInput.VlanVirtualCircuitCreateInput.SetVnid(vlanID)
}

vc, _, err := c.Service.CreateInterconnectionPortVirtualCircuit(context.Background(), connectionID, portID).VirtualCircuitCreateInput(virtualCircuitCreateInput).Execute()
if err != nil {
return fmt.Errorf("could not create interconnections: %w", err)
}

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

data[0] = []string{vc.VlanVirtualCircuit.GetId(), vc.VlanVirtualCircuit.GetName(), vc.VlanVirtualCircuit.GetDescription(), vc.VlanVirtualCircuit.GetCreatedAt().String()}
header := []string{"ID", "Name", "Description", "Created"}

return c.Out.Output(vc.VlanVirtualCircuit, header, &data)

},
}

createVirtualCricuitCmd.Flags().StringVarP(&connectionID, "id", "i", "", "The UUID of the interconnection.")
createVirtualCricuitCmd.Flags().StringVarP(&portID, "port", "p", "", "The UUID of the port.")
createVirtualCricuitCmd.Flags().StringVarP(&projectID, "projectId", "P", "", "The UUID of the projectID.")
createVirtualCricuitCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the interconnection")
createVirtualCricuitCmd.Flags().StringVarP(&description, "description", "d", "", "Adds or updates the description for the interconnection.")
createVirtualCricuitCmd.Flags().StringVarP(&vlanID, "vID", "v", "", "The UUID of the VLAN.")
createVirtualCricuitCmd.Flags().IntVarP(&vlan, "vlan", "", 0, "Adds or updates vlan Must be between 2 and 3999")
createVirtualCricuitCmd.Flags().IntVarP(&speed, "speed", "", 0, "bps speed or string (e.g. 52 - '52m' or '100g' or '4 gbps')")
createVirtualCricuitCmd.Flags().StringSliceVarP(&tags, "tags", "t", []string{}, "Return only the specified tags.")

_ = createVirtualCricuitCmd.MarkFlagRequired("id")
_ = createVirtualCricuitCmd.MarkFlagRequired("portId")
_ = createVirtualCricuitCmd.MarkFlagRequired("projectId")
return createVirtualCricuitCmd
}
Loading

0 comments on commit c69a457

Please sign in to comment.