Skip to content

Commit

Permalink
feat: Enabled virtual-circuit subcomands in metal-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
codinja1188 committed Oct 30, 2023
1 parent a64058f commit 2f0f46f
Show file tree
Hide file tree
Showing 12 changed files with 632 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/equinix/metal-cli/internal/ssh"
"github.com/equinix/metal-cli/internal/twofa"
"github.com/equinix/metal-cli/internal/users"
"github.com/equinix/metal-cli/internal/virtualcircuit"
"github.com/equinix/metal-cli/internal/vlan"
)

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(),
virtualcircuit.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 @@ -45,5 +45,6 @@ Command line interface for Equinix Metal
* [metal project](metal_project.md) - Project operations: create, get, update, delete, and bgpenable, bgpconfig, bgpsessions.
* [metal ssh-key](metal_ssh-key.md) - SSH key operations: create, get, update, and delete.
* [metal user](metal_user.md) - User operations: get and add.
* [metal virtual-circuit](metal_virtual-circuit.md) - virtual-circuit operations: create, get, update, delete
* [metal virtual-network](metal_virtual-network.md) - Virtual network (VLAN) operations : create, get, delete.

37 changes: 37 additions & 0 deletions docs/metal_virtual-circuit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## metal virtual-circuit

virtual-circuit operations: create, get, update, delete

### Synopsis

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

### Options

```
-h, --help help for virtual-circuit
```

### 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 virtual-circuit create](metal_virtual-circuit_create.md) - Creates an create-virtual-circuit for specific interconnection.
* [metal virtual-circuit delete](metal_virtual-circuit_delete.md) - Deletes a virtual-circuit.
* [metal virtual-circuit get](metal_virtual-circuit_get.md) - Retrieves virtual circuit for a specific circuit Id.
* [metal virtual-circuit update](metal_virtual-circuit_update.md) - Updates a virtualcircuit.

61 changes: 61 additions & 0 deletions docs/metal_virtual-circuit_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## metal virtual-circuit create

Creates an create-virtual-circuit for specific interconnection.

### Synopsis

Creates an create-virtual-circuit for specific interconnection

```
metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ] --n <name> [-d <description>] [-v <vlanID> ] [-t <tags> ] [-vlan <vlan> ] [-speed <speed> ] [flags]
```

### Examples

```
# Creates a new virtual-circuit named "interconnection":
metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ] --n <name> [-d <description>] [-v <vlanID> ] [-t <tags> ] [-vlan <vlan> ] [-speed <speed> ]
metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ] -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] -T <service_token_type> -v <vrfs>
metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ] -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] -T <service_token_type> -v <vrfs>
```

### Options

```
-c, --customerIP string An IP address from the subnet that will be used on the Customer side
-d, --description string Adds or updates the description for the interconnection.
-h, --help help for create
-i, --id string The UUID of the interconnection.
-M, --md5 string The plaintext BGP peering password shared by neighbors as an MD5 checksum
-m, --metalIP string An IP address from the subnet that will be used on the Metal side.
-n, --name string Name of the interconnection
-a, --peerAsn int The peer ASN that will be used with the VRF on the Virtual Circuit.
-p, --port string The UUID of the port.
-P, --projectId string The UUID of the projectID.
-s, --speed int bps speed or string (e.g. 52 - '52m' or '100g' or '4 gbps')
--subnet string adds or updates the Email
-t, --tags strings Return only the specified tags.
--vlan int Adds or updates vlan Must be between 2 and 3999
-v, --vnid string The UUID of the VLAN.
```

### 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 virtual-circuit](metal_virtual-circuit.md) - virtual-circuit operations: create, get, update, delete

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

Deletes a virtual-circuit.

### Synopsis

Deletes the specified virtual-circuit.

```
metal virtual-circuit delete -i <virtual-circuit_id> [flags]
```

### Examples

```
# Deletes the specified virtual-circuit:
metal virtua-circuit delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277
```

### Options

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

### 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 virtual-circuit](metal_virtual-circuit.md) - virtual-circuit operations: create, get, update, delete

47 changes: 47 additions & 0 deletions docs/metal_virtual-circuit_get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## metal virtual-circuit get

Retrieves virtual circuit for a specific circuit Id.

### Synopsis

Retrieves virtual circuit for a specific circuit Id.

```
metal virtual-circuit get -i <VcId> [flags]
```

### Examples

```
# Retrieve virtual circuit for a specific circuit::
# Retrieve the details of a specific virtual-circuit:
metal interconnections get -i e9a969b3-8911-4667-9d99-57cd3dd4ef6f
```

### Options

```
-h, --help help for get
-i, --vcID string UUID of the virtual-circuit
```

### 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 virtual-circuit](metal_virtual-circuit.md) - virtual-circuit operations: create, get, update, delete

54 changes: 54 additions & 0 deletions docs/metal_virtual-circuit_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## metal virtual-circuit update

Updates a virtualcircuit.

### Synopsis

Updates a specified virtualcircuit.

```
metal virtual-circuit update -i <virtualcircuit_id> [--vnid <vn UUID>] [-d <description>] [-n <name>] [-s <speed>] [-t <tags>] [flags]
```

### Examples

```
# Updates a specified virtualcircuit.:
metal virtual-circuit update --id 30c15082-a06e-4c43-bfc3-252616b46eba
```

### Options

```
-c, --customerIP string An IP address from the subnet that will be used on the Customer side
-d, --description string Adds or updates the description for the interconnection.
-h, --help help for update
-i, --id string The UUID of the virtual-circuit.
-M, --md5 string The plaintext BGP peering password shared by neighbors as an MD5 checksum
-m, --metalIP string An IP address from the subnet that will be used on the Metal side.
-n, --name string The new name of the interconnection.
-a, --peerAsn int The peer ASN that will be used with the VRF on the Virtual Circuit.
-s, --speed string Adds or updates Speed can be changed only if it is an interconnection on a Dedicated Port
--subnet string adds or updates the Email
-t, --tags strings Adds or updates the tags for the connection --tags="tag1,tag2".
```

### 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 virtual-circuit](metal_virtual-circuit.md) - virtual-circuit operations: create, get, update, delete

120 changes: 120 additions & 0 deletions internal/virtualcircuit/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package virtualcircuit

import (
"context"
"fmt"

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

func (c *Client) Create() *cobra.Command {
var (
connectionID string
portID string
name string
description string
projectID string
vnid string
vrf string
subnet string
customerIP string
metalIP string
md5 string
peerAsn int
speed int
nnVlan int
tags []string
)

createVirtualCricuitCmd := &cobra.Command{
Use: `create [-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 virtual-circuit named "interconnection":
metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ] --n <name> [-d <description>] [-v <vlanID> ] [-t <tags> ] [-vlan <vlan> ] [-speed <speed> ]
metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ] -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] -T <service_token_type> -v <vrfs>
metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ] -n <name> [-m <metro>] [-r <redundancy>] [-t "shared" ] -T <service_token_type> -v <vrfs>`,

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

if vrf != "" {
vrfInput := metal.NewVrfVirtualCircuitCreateInputWithDefaults()
SetParams(vrfInput, name, description, tags)

// set any VRF only things
vrfInput.SetProjectId(projectID)
vrfInput.SetSubnet(subnet)
vrfInput.SetCustomerIp(customerIP)
vrfInput.SetMetalIp(metalIP)
vrfInput.SetMd5(md5)

if speed > 0 {
vrfInput.SetSpeed(int32(speed))
}

if peerAsn > 0 {
vrfInput.SetPeerAsn(int32(peerAsn))
}
if nnVlan > 0 {
vrfInput.SetNniVlan(int32(nnVlan))
}

createInput = metal.VirtualCircuitCreateInput{VrfVirtualCircuitCreateInput: vrfInput}

} else {
vlanInput := metal.NewVlanVirtualCircuitCreateInput(projectID)

SetParams(vlanInput, name, description, tags)
// set any VLAN only things
vlanInput.SetVnid(vnid)

if nnVlan > 0 {
vlanInput.SetNniVlan(int32(nnVlan))
}
if speed > 0 {
vlanInput.SetSpeed(int32(speed))
}

createInput = metal.VirtualCircuitCreateInput{VlanVirtualCircuitCreateInput: vlanInput}
}

vc, _, err := c.Service.CreateInterconnectionPortVirtualCircuit(context.Background(), connectionID, portID).VirtualCircuitCreateInput(createInput).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(&vnid, "vnid", "v", "", "The UUID of the VLAN.")
createVirtualCricuitCmd.Flags().IntVarP(&nnVlan, "vlan", "", 0, "Adds or updates vlan Must be between 2 and 3999")
createVirtualCricuitCmd.Flags().IntVarP(&speed, "speed", "s", 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.Flags().StringVarP(&subnet, "subnet", "", "", "adds or updates the Email")
createVirtualCricuitCmd.Flags().StringVarP(&customerIP, "customerIP", "c", "", "An IP address from the subnet that will be used on the Customer side")
createVirtualCricuitCmd.Flags().StringVarP(&metalIP, "metalIP", "m", "", "An IP address from the subnet that will be used on the Metal side. ")
createVirtualCricuitCmd.Flags().IntVarP(&peerAsn, "peerAsn", "a", 0, "The peer ASN that will be used with the VRF on the Virtual Circuit.")
createVirtualCricuitCmd.Flags().StringVarP(&md5, "md5", "M", "", "The plaintext BGP peering password shared by neighbors as an MD5 checksum")

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

0 comments on commit 2f0f46f

Please sign in to comment.