-
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.
feat: Enabled virtual-circuit subcomands in metal-cli
- Loading branch information
1 parent
a64058f
commit dfc8b69
Showing
5 changed files
with
415 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package virtualcircuit | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
metal "github.com/equinix-labs/metal-go/metal/v1" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (c *Client) CreateVirtualCricuit() *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 virtualCircuitCreateInput metal.VirtualCircuitCreateInput | ||
|
||
if vrf != "" { | ||
vrfVirtualCircuitCreateInput := metal.NewVrfVirtualCircuitCreateInputWithDefaults() | ||
|
||
if projectID != "" { | ||
vrfVirtualCircuitCreateInput.SetProjectId(projectID) | ||
} | ||
|
||
if description != "" { | ||
vrfVirtualCircuitCreateInput.SetDescription(description) | ||
} | ||
|
||
if name != "" { | ||
vrfVirtualCircuitCreateInput.SetName(name) | ||
} | ||
|
||
if nnVlan > 2 { | ||
vrfVirtualCircuitCreateInput.SetNniVlan(int32(nnVlan)) | ||
} | ||
|
||
if speed > 0 { | ||
vrfVirtualCircuitCreateInput.SetSpeed(int32(speed)) | ||
} | ||
|
||
if len(tags) > 0 { | ||
vrfVirtualCircuitCreateInput.SetTags(tags) | ||
} | ||
|
||
if subnet != "" { | ||
vrfVirtualCircuitCreateInput.SetSubnet(subnet) | ||
} | ||
|
||
if peerAsn > 0 { | ||
vrfVirtualCircuitCreateInput.SetPeerAsn(int32(peerAsn)) | ||
} | ||
|
||
if customerIP != "" { | ||
vrfVirtualCircuitCreateInput.SetCustomerIp(customerIP) | ||
} | ||
|
||
if metalIP != "" { | ||
vrfVirtualCircuitCreateInput.SetMetalIp(metalIP) | ||
} | ||
|
||
if md5 != "" { | ||
vrfVirtualCircuitCreateInput.SetMd5(md5) | ||
} | ||
virtualCircuitCreateInput = metal.VirtualCircuitCreateInput{VrfVirtualCircuitCreateInput: vrfVirtualCircuitCreateInput} | ||
|
||
} else { | ||
vlanVirtualCircuitCreateInput := metal.NewVlanVirtualCircuitCreateInput(projectID) | ||
|
||
if description != "" { | ||
vlanVirtualCircuitCreateInput.SetDescription(description) | ||
} | ||
|
||
if name != "" { | ||
vlanVirtualCircuitCreateInput.SetName(name) | ||
} | ||
|
||
if nnVlan > 2 { | ||
vlanVirtualCircuitCreateInput.SetNniVlan(int32(nnVlan)) | ||
} | ||
|
||
if vnid != "" { | ||
vlanVirtualCircuitCreateInput.SetVnid(vnid) | ||
} | ||
|
||
if speed > 0 { | ||
vlanVirtualCircuitCreateInput.SetSpeed(int32(speed)) | ||
} | ||
|
||
if len(tags) > 0 { | ||
vlanVirtualCircuitCreateInput.SetTags(tags) | ||
} | ||
|
||
virtualCircuitCreateInput = metal.VirtualCircuitCreateInput{VlanVirtualCircuitCreateInput: vlanVirtualCircuitCreateInput} | ||
} | ||
|
||
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(&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 | ||
} |
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,38 @@ | ||
package virtualcircuit | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (c *Client) Delete() *cobra.Command { | ||
var vcID string | ||
|
||
deleteVirtualcircuitCmd := &cobra.Command{ | ||
Use: `delete -i <virtual-circuit_id> `, | ||
Short: "Deletes a virtual-circuit.", | ||
Long: "Deletes the specified virtual-circuit.", | ||
Example: ` # Deletes the specified virtual-circuit: | ||
metal virtua-circuit delete -i 7ec86e23-8dcf-48ed-bd9b-c25c20958277`, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.SilenceUsage = true | ||
inc := []string{} | ||
exc := []string{} | ||
_, _, err := c.Service.DeleteVirtualCircuit(context.Background(), vcID).Include(inc).Exclude(exc).Execute() | ||
if err != nil { | ||
return fmt.Errorf("Error when calling `InterconnectionsApi.DeleteVirtualCircuit``: %w\n", err) | ||
} | ||
fmt.Println("virtual-circuit deletion initiated. Please check 'metal virtual-circuit get -i", vcID, "' for status") | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
deleteVirtualcircuitCmd.Flags().StringVarP(&vcID, "id", "i", "", "The UUID of the virtual-circuit.") | ||
_ = deleteVirtualcircuitCmd.MarkFlagRequired("id") | ||
|
||
return deleteVirtualcircuitCmd | ||
} |
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,41 @@ | ||
package virtualcircuit | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (c *Client) Retrieve() *cobra.Command { | ||
var vcID string | ||
retrieveVirtualCircuitCmd := &cobra.Command{ | ||
Use: "get -i <VcId>", | ||
Aliases: []string{"list"}, | ||
Short: "Retrieves virtual circuit for a specific circuit Id.", | ||
Long: "Retrieves virtual circuit for a specific circuit Id.", | ||
Example: ` # Retrieve virtual circuit for a specific circuit:: | ||
# Retrieve the details of a specific virtual-circuit: | ||
metal interconnections get -i e9a969b3-8911-4667-9d99-57cd3dd4ef6f`, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.SilenceUsage = true | ||
|
||
inc := []string{} | ||
header := []string{"ID", "Name", "Port", "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() | ||
if err != nil { | ||
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()} | ||
return c.Out.Output(vcUID, header, &data) | ||
}, | ||
} | ||
retrieveVirtualCircuitCmd.Flags().StringVarP(&vcID, "vcID", "i", "", "UUID of the virtual-circuit") | ||
return retrieveVirtualCircuitCmd | ||
} |
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,127 @@ | ||
package virtualcircuit | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
metal "github.com/equinix-labs/metal-go/metal/v1" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (c *Client) Update() *cobra.Command { | ||
var ( | ||
description string | ||
speed string | ||
name string | ||
vnid string | ||
vcID string | ||
subnet string | ||
customerIP string | ||
metalIP string | ||
md5 string | ||
tags []string | ||
peerAsn int | ||
) | ||
// updateConnectionCmd represents the updateConnectionCmd command | ||
updateVirtualCircuitCmd := &cobra.Command{ | ||
Use: `update -i <virtualcircuit_id> [--vnid <vn UUID>] [-d <description>] [-n <name>] [-s <speed>] [-t <tags>]`, | ||
Short: "Updates a virtualcircuit.", | ||
Long: "Updates a specified virtualcircuit.", | ||
Example: ` # Updates a specified virtualcircuit.: | ||
metal virtual-circuit update --id 30c15082-a06e-4c43-bfc3-252616b46eba`, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.SilenceUsage = true | ||
inc := []string{} | ||
var virtualCircuitUpdateInput metal.VirtualCircuitUpdateInput | ||
header := []string{"ID", "Name", "Type", "Created"} | ||
|
||
if vnid != "" { | ||
vlanVirtualCircuitUpdateInput := metal.NewVlanVirtualCircuitUpdateInput() | ||
|
||
if speed != "" { | ||
vlanVirtualCircuitUpdateInput.SetSpeed(speed) | ||
} | ||
|
||
if description != "" { | ||
vlanVirtualCircuitUpdateInput.SetDescription(description) | ||
} | ||
|
||
if name != "" { | ||
vlanVirtualCircuitUpdateInput.SetName(name) | ||
} | ||
|
||
if len(tags) > 0 { | ||
vlanVirtualCircuitUpdateInput.SetTags(tags) | ||
} | ||
|
||
virtualCircuitUpdateInput = metal.VirtualCircuitUpdateInput{VlanVirtualCircuitUpdateInput: vlanVirtualCircuitUpdateInput} | ||
} else { | ||
vrfVirtualCircuitUpdateInput := metal.NewVrfVirtualCircuitUpdateInput() | ||
|
||
if speed != "" { | ||
vrfVirtualCircuitUpdateInput.SetSpeed(speed) | ||
} | ||
|
||
if description != "" { | ||
vrfVirtualCircuitUpdateInput.SetDescription(description) | ||
} | ||
|
||
if name != "" { | ||
vrfVirtualCircuitUpdateInput.SetName(name) | ||
} | ||
|
||
if len(tags) > 0 { | ||
vrfVirtualCircuitUpdateInput.SetTags(tags) | ||
} | ||
if subnet != "" { | ||
vrfVirtualCircuitUpdateInput.SetSubnet(subnet) | ||
} | ||
|
||
if peerAsn > 0 { | ||
vrfVirtualCircuitUpdateInput.SetPeerAsn(int32(peerAsn)) | ||
} | ||
|
||
if customerIP != "" { | ||
vrfVirtualCircuitUpdateInput.SetCustomerIp(customerIP) | ||
} | ||
|
||
if metalIP != "" { | ||
vrfVirtualCircuitUpdateInput.SetMetalIp(metalIP) | ||
} | ||
|
||
if md5 != "" { | ||
vrfVirtualCircuitUpdateInput.SetMd5(md5) | ||
} | ||
virtualCircuitUpdateInput = metal.VirtualCircuitUpdateInput{VrfVirtualCircuitUpdateInput: vrfVirtualCircuitUpdateInput} | ||
} | ||
vc, _, err := c.Service.UpdateVirtualCircuit(context.Background(), vcID).VirtualCircuitUpdateInput(virtualCircuitUpdateInput).Include(c.Servicer.Includes(inc)).Execute() | ||
if err != nil { | ||
return fmt.Errorf("could not update virtual-circuit: %w", err) | ||
} | ||
|
||
data := make([][]string, 1) | ||
|
||
data[0] = []string{vc.VlanVirtualCircuit.GetId(), vc.VlanVirtualCircuit.GetName(), string(vc.VlanVirtualCircuit.GetType()), vc.VlanVirtualCircuit.GetCreatedAt().String()} | ||
|
||
return c.Out.Output(vc, header, &data) | ||
|
||
}, | ||
} | ||
|
||
updateVirtualCircuitCmd.Flags().StringVarP(&vcID, "id", "i", "", "The UUID of the virtual-circuit.") | ||
updateVirtualCircuitCmd.Flags().StringVarP(&name, "name", "n", "", "The new name of the interconnection.") | ||
updateVirtualCircuitCmd.Flags().StringVarP(&description, "description", "d", "", "Adds or updates the description for the interconnection.") | ||
updateVirtualCircuitCmd.Flags().StringVarP(&speed, "speed", "s", "", "Adds or updates Speed can be changed only if it is an interconnection on a Dedicated Port") | ||
|
||
updateVirtualCircuitCmd.Flags().StringSliceVarP(&tags, "tags", "t", []string{}, `Adds or updates the tags for the connection --tags="tag1,tag2".`) | ||
|
||
updateVirtualCircuitCmd.Flags().StringVarP(&subnet, "subnet", "", "", "adds or updates the Email") | ||
updateVirtualCircuitCmd.Flags().StringVarP(&customerIP, "customerIP", "c", "", "An IP address from the subnet that will be used on the Customer side") | ||
updateVirtualCircuitCmd.Flags().StringVarP(&metalIP, "metalIP", "m", "", "An IP address from the subnet that will be used on the Metal side. ") | ||
updateVirtualCircuitCmd.Flags().IntVarP(&peerAsn, "peerAsn", "a", 0, "The peer ASN that will be used with the VRF on the Virtual Circuit.") | ||
updateVirtualCircuitCmd.Flags().StringVarP(&md5, "md5", "m", "", "The plaintext BGP peering password shared by neighbors as an MD5 checksum") | ||
|
||
_ = updateVirtualCircuitCmd.MarkFlagRequired("id") | ||
return updateVirtualCircuitCmd | ||
} |
Oops, something went wrong.