diff --git a/internal/vlan/create.go b/internal/vlan/create.go index f3476714..c8986f7f 100644 --- a/internal/vlan/create.go +++ b/internal/vlan/create.go @@ -21,10 +21,11 @@ package vlan import ( + "context" "fmt" "strconv" - "github.com/packethost/packngo" + metal "github.com/equinix-labs/metal-go/metal/v1" "github.com/spf13/cobra" ) @@ -45,18 +46,20 @@ func (c *Client) Create() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true - - req := &packngo.VirtualNetworkCreateRequest{ - ProjectID: projectID, - Metro: metro, - Facility: facility, - VXLAN: vxlan, + virtualNetworkCreateInput := metal.NewVirtualNetworkCreateInput() + if metro != "" { + virtualNetworkCreateInput.SetMetro(metro) + } + if facility != "" { + virtualNetworkCreateInput.SetFacility(facility) } + virtualNetworkCreateInput.SetVxlan(int32(vxlan)) + if description != "" { - req.Description = description + virtualNetworkCreateInput.Description = &description } - n, _, err := c.Service.Create(req) + n, _, err := c.Service.CreateVirtualNetwork(context.Background(), projectID).VirtualNetworkCreateInput(*virtualNetworkCreateInput).Include(nil).Exclude(nil).Execute() if err != nil { return fmt.Errorf("Could not create ProjectVirtualNetwork: %w", err) } @@ -64,9 +67,9 @@ func (c *Client) Create() *cobra.Command { data := make([][]string, 1) // TODO(displague) metro is not in the response - data[0] = []string{n.ID, n.Description, strconv.Itoa(n.VXLAN), n.MetroCode, n.FacilityCode, n.CreatedAt} + data[0] = []string{n.GetId(), n.GetDescription(), strconv.Itoa(int(n.GetVxlan())), n.GetMetroCode()} - header := []string{"ID", "Description", "VXLAN", "Metro", "Facility", "Created"} + header := []string{"ID", "Description", "VXLAN", "Metro"} return c.Out.Output(n, header, &data) }, diff --git a/internal/vlan/delete.go b/internal/vlan/delete.go index 0156908a..f534a5be 100644 --- a/internal/vlan/delete.go +++ b/internal/vlan/delete.go @@ -21,6 +21,7 @@ package vlan import ( + "context" "fmt" "github.com/manifoldco/promptui" @@ -34,7 +35,7 @@ func (c *Client) Delete() *cobra.Command { ) deleteVnet := func(id string) error { - _, err := c.Service.Delete(id) + _, _, err := c.Service.DeleteVirtualNetwork(context.Background(), vnetID).Execute() if err != nil { return err } diff --git a/internal/vlan/retrieve.go b/internal/vlan/retrieve.go index adfb211b..85664dbf 100644 --- a/internal/vlan/retrieve.go +++ b/internal/vlan/retrieve.go @@ -41,17 +41,26 @@ func (c *Client) Retrieve() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true - vnets, _, err := c.Service.List(projectID, c.Servicer.ListOptions(nil, nil)) + request := c.Service.FindVirtualNetworks(cmd.Context(), projectID).Include(nil).Exclude(nil) + filters := c.Servicer.Filters() + if filters["facility"] != "" { + request = request.Facility(filters["facility"]) + } + + if filters["metro"] != "" { + request = request.Metro(filters["metro"]) + } + VirtualNetworksList, _, err := request.Execute() if err != nil { return fmt.Errorf("Could not list Project Virtual Networks: %w", err) } + VirtualNetworks := VirtualNetworksList.GetVirtualNetworks() + data := make([][]string, len(VirtualNetworks)) - data := make([][]string, len(vnets.VirtualNetworks)) - - for i, n := range vnets.VirtualNetworks { - data[i] = []string{n.ID, n.Description, strconv.Itoa(n.VXLAN), n.FacilityCode, n.CreatedAt} + for i, n := range VirtualNetworks { + data[i] = []string{n.GetId(), n.GetDescription(), strconv.Itoa(int(n.GetVxlan()), n.GetMetroCode()} } - header := []string{"ID", "Description", "VXLAN", "Facility", "Created"} + header := []string{"ID", "Description", "VXLAN", "Metro"} return c.Out.Output(vnets, header, &data) }, diff --git a/internal/vlan/vlan.go b/internal/vlan/vlan.go index 2de94730..adbdd4c9 100644 --- a/internal/vlan/vlan.go +++ b/internal/vlan/vlan.go @@ -21,14 +21,14 @@ package vlan import ( + metal "github.com/equinix-labs/metal-go/metal/v1" "github.com/equinix/metal-cli/internal/outputs" - "github.com/packethost/packngo" "github.com/spf13/cobra" ) type Client struct { Servicer Servicer - Service packngo.ProjectVirtualNetworkService + Service metal.VLANsApiService Out outputs.Outputer } @@ -45,7 +45,7 @@ func (c *Client) NewCommand() *cobra.Command { root.PersistentPreRun(cmd, args) } } - c.Service = c.Servicer.API(cmd).ProjectVirtualNetworks + c.Service = *c.Servicer.MetalAPI(cmd).VLANsApi }, } @@ -58,8 +58,10 @@ func (c *Client) NewCommand() *cobra.Command { } type Servicer interface { - API(*cobra.Command) *packngo.Client - ListOptions(defaultIncludes, defaultExcludes []string) *packngo.ListOptions + MetalAPI(*cobra.Command) *metal.APIClient + Filters() map[string]string + Includes(defaultIncludes []string) (incl []string) + Excludes(defaultExcludes []string) (excl []string) } func NewClient(s Servicer, out outputs.Outputer) *Client {