Skip to content

Commit

Permalink
addred review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
codinja1188 committed Oct 31, 2023
1 parent 2f0f46f commit 749fee1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 33 deletions.
6 changes: 3 additions & 3 deletions docs/metal_virtual-circuit_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Creates an create-virtual-circuit for specific interconnection.
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]
metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ] -n <name> [-d <description>] [-v <vnid> ] [-t <tags> ] [-V <vlan> ] [-s <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> [-d <description>] [-v <vnid> ] [-t <tags> ] [-V <vlan> ] [-s <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>
Expand All @@ -36,7 +36,7 @@ metal virtual-circuit create [-i connection_id] [-p port_id] [-P <project_id> ]
-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, --vlan int Adds or updates vlan Must be between 2 and 4094
-v, --vnid string The UUID of the VLAN.
```

Expand Down
12 changes: 8 additions & 4 deletions internal/virtualcircuit/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package virtualcircuit
import (
"context"
"fmt"
"os"

metal "github.com/equinix-labs/metal-go/metal/v1"
"github.com/spf13/cobra"
Expand All @@ -28,11 +29,11 @@ func (c *Client) Create() *cobra.Command {
)

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> ]`,
Use: `create [-i connection_id] [-p port_id] [-P <project_id> ] -n <name> [-d <description>] [-v <vnid> ] [-t <tags> ] [-V <vlan> ] [-s <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> [-d <description>] [-v <vnid> ] [-t <tags> ] [-V <vlan> ] [-s <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>`,
Expand All @@ -42,6 +43,7 @@ func (c *Client) Create() *cobra.Command {
var createInput metal.VirtualCircuitCreateInput

if vrf != "" {
fmt.Print("set any VRF only things")
vrfInput := metal.NewVrfVirtualCircuitCreateInputWithDefaults()
SetParams(vrfInput, name, description, tags)

Expand All @@ -66,6 +68,7 @@ func (c *Client) Create() *cobra.Command {
createInput = metal.VirtualCircuitCreateInput{VrfVirtualCircuitCreateInput: vrfInput}

} else {
fmt.Print("set any VLAN only things")
vlanInput := metal.NewVlanVirtualCircuitCreateInput(projectID)

SetParams(vlanInput, name, description, tags)
Expand All @@ -82,8 +85,9 @@ func (c *Client) Create() *cobra.Command {
createInput = metal.VirtualCircuitCreateInput{VlanVirtualCircuitCreateInput: vlanInput}
}

vc, _, err := c.Service.CreateInterconnectionPortVirtualCircuit(context.Background(), connectionID, portID).VirtualCircuitCreateInput(createInput).Execute()
vc, r, err := c.Service.CreateInterconnectionPortVirtualCircuit(context.Background(), connectionID, portID).VirtualCircuitCreateInput(createInput).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
return fmt.Errorf("could not create interconnections: %w", err)
}

Expand All @@ -103,7 +107,7 @@ func (c *Client) Create() *cobra.Command {
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(&nnVlan, "vlan", "V", 0, "Adds or updates vlan Must be between 2 and 4094")
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.")

Expand Down
12 changes: 8 additions & 4 deletions internal/virtualcircuit/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package virtualcircuit
import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"
)
Expand All @@ -23,16 +24,19 @@ func (c *Client) Retrieve() *cobra.Command {
cmd.SilenceUsage = true

inc := []string{}
header := []string{"ID", "Name", "Port", "Speed", "Created"}
if vcID != "" {
header := []string{"ID", "Name", "Speed", "Created"}
if vcID == "" {
return fmt.Errorf("should provide poroper Virtual-circuit ID")
}
vcUID, _, err := c.Service.GetVirtualCircuit(context.Background(), vcID).Include(c.Servicer.Includes(inc)).Execute()
vcUID, r, err := c.Service.GetVirtualCircuit(context.Background(), vcID).Include(c.Servicer.Includes(inc)).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
return fmt.Errorf("error when calling `InterconnectionsApi.GetVirtualCircuit``: %w", err)
}
data := make([][]string, 1)
data[0] = []string{vcUID.VlanVirtualCircuit.GetId(), vcUID.VlanVirtualCircuit.GetName(), string(vcUID.VlanVirtualCircuit.GetType()), string(vcUID.VlanVirtualCircuit.GetSpeed()), vcUID.VlanVirtualCircuit.GetCreatedAt().String()}

id, name, speed, time := getParams(vcUID.VlanVirtualCircuit)

Check failure on line 38 in internal/virtualcircuit/retrieve.go

View workflow job for this annotation

GitHub Actions / test

undefined: getParams

Check failure on line 38 in internal/virtualcircuit/retrieve.go

View workflow job for this annotation

GitHub Actions / docs (1.19)

undefined: getParams

Check failure on line 38 in internal/virtualcircuit/retrieve.go

View workflow job for this annotation

GitHub Actions / lint

undefined: getParams (typecheck)

Check failure on line 38 in internal/virtualcircuit/retrieve.go

View workflow job for this annotation

GitHub Actions / lint

undefined: getParams) (typecheck)
data[0] = []string{id, name, speed, time}
return c.Out.Output(vcUID, header, &data)
},
}
Expand Down
32 changes: 10 additions & 22 deletions internal/virtualcircuit/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,27 @@ func (c *Client) Update() *cobra.Command {
if vnid != "" {
vlanUpdateInput := metal.NewVlanVirtualCircuitUpdateInput()
SetParams(vlanUpdateInput, name, description, tags)
if speed != "" {
vlanUpdateInput.SetSpeed(speed)
}
// set any VLAN only things
vlanUpdateInput.SetSpeed(speed)
vlanUpdateInput.SetVnid(vnid)

virtualCircuitUpdateInput = metal.VirtualCircuitUpdateInput{VlanVirtualCircuitUpdateInput: vlanUpdateInput}
} else {
vrfUpdateInput := metal.NewVrfVirtualCircuitUpdateInput()

SetParams(vrfUpdateInput, name, description, tags)

if speed != "" {
vrfUpdateInput.SetSpeed(speed)
}

if subnet != "" {
vrfUpdateInput.SetSubnet(subnet)
}
// set any VRF only things
vrfUpdateInput.SetSpeed(speed)
vrfUpdateInput.SetSubnet(subnet)
vrfUpdateInput.SetCustomerIp(customerIP)
vrfUpdateInput.SetMetalIp(metalIP)
vrfUpdateInput.SetMd5(md5)
vrfUpdateInput.SetCustomerIp(customerIP)

if peerAsn > 0 {
vrfUpdateInput.SetPeerAsn(int32(peerAsn))
}

if customerIP != "" {
vrfUpdateInput.SetCustomerIp(customerIP)
}

if metalIP != "" {
vrfUpdateInput.SetMetalIp(metalIP)
}

if md5 != "" {
vrfUpdateInput.SetMd5(md5)
}
virtualCircuitUpdateInput = metal.VirtualCircuitUpdateInput{VrfVirtualCircuitUpdateInput: vrfUpdateInput}
}
vc, _, err := c.Service.UpdateVirtualCircuit(context.Background(), vcID).VirtualCircuitUpdateInput(virtualCircuitUpdateInput).Include(c.Servicer.Includes(inc)).Execute()
Expand Down
24 changes: 24 additions & 0 deletions internal/virtualcircuit/virtualcircuit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package virtualcircuit

import (
"strconv"
"time"

metal "github.com/equinix-labs/metal-go/metal/v1"
"github.com/equinix/metal-cli/internal/outputs"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -39,6 +42,27 @@ func SetParams(p vcParamBuilder, name, description string, tags []string) {
}
}

type vcParamOuter interface {
GetId() string
GetName() string
GetSpeed() int32
GetCreatedAt() time.Time
}

var (
_ vcParamOuter = (*metal.VlanVirtualCircuit)(nil)
_ vcParamOuter = (*metal.VrfVirtualCircuit)(nil)
)

func GetParams(p vcParamOuter) (id, name, speed, time string) {
id = p.GetId()
name = p.GetName()
sp := p.GetSpeed()
speed = strconv.FormatInt(int64(sp), 10)
time = p.GetCreatedAt().String()
return id, name, speed, time
}

func (c *Client) NewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: `virtual-circuit`,
Expand Down

0 comments on commit 749fee1

Please sign in to comment.