-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added get and list interconnect attachment support
- Loading branch information
Showing
7 changed files
with
308 additions
and
3 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,76 @@ | ||
package displayers | ||
|
||
import ( | ||
"io" | ||
"strings" | ||
|
||
"github.com/digitalocean/doctl/do" | ||
) | ||
|
||
type PartnerInterconnectAttachment struct { | ||
PartnerInterconnectAttachments do.PartnerInterconnectAttachments | ||
} | ||
|
||
var _ Displayable = &PartnerInterconnectAttachment{} | ||
|
||
func (v *PartnerInterconnectAttachment) JSON(out io.Writer) error { | ||
return writeJSON(v.PartnerInterconnectAttachments, out) | ||
} | ||
|
||
func (v *PartnerInterconnectAttachment) Cols() []string { | ||
return []string{ | ||
"ID", | ||
"Name", | ||
"State", | ||
"ConnectionBandwidthInMbps", | ||
"Region", | ||
"NaaSProvider", | ||
"VPCIDs", | ||
"CreatedAt", | ||
"BGPLocalASN", | ||
"BGPLocalRouterIP", | ||
"BGPPeerASN", | ||
"BGPPeerRouterIP", | ||
} | ||
} | ||
|
||
func (v *PartnerInterconnectAttachment) ColMap() map[string]string { | ||
return map[string]string{ | ||
"ID": "ID", | ||
"Name": "Name", | ||
"State": "State", | ||
"ConnectionBandwidthInMbps": "Connection Bandwidth (MBPS)", | ||
"Region": "Region", | ||
"NaaSProvider": "NaaS Provider", | ||
"VPCIDs": "VPCIDs", | ||
"Created": "Created At", | ||
"BGPLocalASN": "BGP Local ASN", | ||
"BGPLocalRouterIP": "BGP Local Router IP", | ||
"BGPPeerASN": "BGP Peer ASN", | ||
"BGPPeerRouterIP": "BGP Peer Router IP", | ||
} | ||
} | ||
|
||
func (v *PartnerInterconnectAttachment) KV() []map[string]any { | ||
out := make([]map[string]any, 0, len(v.PartnerInterconnectAttachments)) | ||
|
||
for _, ia := range v.PartnerInterconnectAttachments { | ||
o := map[string]any{ | ||
"ID": ia.ID, | ||
"Name": ia.Name, | ||
"State": ia.State, | ||
"ConnectionBandwidthInMbps": ia.ConnectionBandwidthInMbps, | ||
"Region": ia.Region, | ||
"NaaSProvider": ia.NaaSProvider, | ||
"VPCIDs": strings.Join(ia.VPCIDs, ","), | ||
"Created": ia.CreatedAt, | ||
"BGPLocalASN": ia.BGP.LocalASN, | ||
"BGPLocalRouterIP": ia.BGP.LocalRouterIP, | ||
"BGPPeerASN": ia.BGP.PeerASN, | ||
"BGPPeerRouterIP": ia.BGP.PeerRouterIP, | ||
} | ||
out = append(out, o) | ||
} | ||
|
||
return out | ||
} |
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
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,93 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/digitalocean/doctl/commands/displayers" | ||
"github.com/digitalocean/doctl/do" | ||
) | ||
|
||
// Partner creates the partner commands | ||
func Partner() *Command { | ||
cmd := &Command{ | ||
Command: &cobra.Command{ | ||
Use: "partner", | ||
Short: "Display commands that manage Partner products", | ||
Long: `The commands under ` + "`" + `doctl partner` + "`" + ` are for managing Partner products`, | ||
GroupID: manageResourcesGroup, | ||
}, | ||
} | ||
|
||
cmd.AddCommand(InterconnectAttachments()) | ||
|
||
return cmd | ||
} | ||
|
||
// InterconnectAttachments creates the interconnect attachment command | ||
func InterconnectAttachments() *Command { | ||
cmd := &Command{ | ||
Command: &cobra.Command{ | ||
Use: "interconnect-attachment", | ||
Short: "Display commands that manage Partner Interconnect Attachments", | ||
Long: `The commands under ` + "`" + `doctl partner interconnect-attachment` + "`" + ` are for managing your Partner Interconnect Attachments. | ||
With the Partner Interconnect Attachments commands, you can get or list, create, update, or delete Partner Interconnect Attachments, and manage their configuration details.`, | ||
}, | ||
} | ||
|
||
interconnectAttachmentDetails := ` | ||
- The Partner Interconnect Attachment ID | ||
- The Partner Interconnect Attachment Name | ||
- The Partner Interconnect Attachment State | ||
- The Partner Interconnect Attachment Connection Bandwidth in Mbps | ||
- The Partner Interconnect Attachment Region | ||
- The Partner Interconnect Attachment NaaS Provider | ||
- The Partner Interconnect Attachment VPC network IDs | ||
- The Partner Interconnect Attachment creation date, in ISO8601 combined date and time format | ||
- The Partner Interconnect Attachment BGP Local ASN | ||
- The Partner Interconnect Attachment BGP Local Router IP | ||
- The Partner Interconnect Attachment BGP Peer ASN | ||
- The Partner Interconnect Attachment BGP Peer Router IP | ||
` | ||
|
||
cmdPartnerIAGet := CmdBuilder(cmd, RunPartnerInterconnectAttachmentGet, "get <interconnect-attachment-id>", | ||
"Retrieves a Partner Interconnect Attachment", "Retrieves information about a Partner Interconnect Attachment, including:"+interconnectAttachmentDetails, Writer, | ||
aliasOpt("g"), displayerType(&displayers.PartnerInterconnectAttachment{})) | ||
cmdPartnerIAGet.Example = `The following example retrieves information about a Partner Interconnect Attachment with the ID ` + "`" + `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` + "`" + `: doctl partner interconnect-attachment get f81d4fae-7dec-11d0-a765-00a0c91e6bf6` | ||
|
||
cmdPartnerIAList := CmdBuilder(cmd, RunPartnerInterconnectAttachmentList, "list", "List Partner Interconnect Attachments", "Retrieves a list of the Partner Interconnect Attachments on your account, including the following information for each:"+interconnectAttachmentDetails, Writer, | ||
aliasOpt("ls"), displayerType(&displayers.PartnerInterconnectAttachment{})) | ||
cmdPartnerIAList.Example = `The following example lists the Partner Interconnect Attachments on your account : doctl partner interconnect-attachment list --format Name,VPCIDs` | ||
|
||
return cmd | ||
} | ||
|
||
// RunPartnerInterconnectAttachmentGet retrieves an existing Partner Interconnect Attachment by its identifier. | ||
func RunPartnerInterconnectAttachmentGet(c *CmdConfig) error { | ||
err := ensureOneArg(c) | ||
if err != nil { | ||
return err | ||
} | ||
iaID := c.Args[0] | ||
|
||
interconnectAttachment, err := c.VPCs().GetPartnerInterconnectAttachment(iaID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
item := &displayers.PartnerInterconnectAttachment{ | ||
PartnerInterconnectAttachments: do.PartnerInterconnectAttachments{*interconnectAttachment}, | ||
} | ||
return c.Display(item) | ||
} | ||
|
||
// RunPartnerInterconnectAttachmentList lists Partner Interconnect Attachment | ||
func RunPartnerInterconnectAttachmentList(c *CmdConfig) error { | ||
|
||
list, err := c.VPCs().ListPartnerInterconnectAttachments() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
item := &displayers.PartnerInterconnectAttachment{PartnerInterconnectAttachments: list} | ||
return c.Display(item) | ||
} |
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,57 @@ | ||
package commands | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/digitalocean/godo" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/digitalocean/doctl/do" | ||
) | ||
|
||
var ( | ||
testIA = do.PartnerInterconnectAttachment{ | ||
PartnerInterconnectAttachment: &godo.PartnerInterconnectAttachment{ | ||
Name: "ia-name", | ||
VPCIDs: []string{"f81d4fae-7dec-11d0-a765-00a0c91e6bf6", "3f900b61-30d7-40d8-9711-8c5d6264b268"}, | ||
}, | ||
} | ||
|
||
testIAList = do.PartnerInterconnectAttachments{ | ||
testIA, | ||
} | ||
) | ||
|
||
func TestInterconnectAttachmentsCommand(t *testing.T) { | ||
cmd := InterconnectAttachments() | ||
assert.NotNil(t, cmd) | ||
assertCommandNames(t, cmd, "get", "list") | ||
} | ||
|
||
func TestInterconnectAttachmentsGet(t *testing.T) { | ||
withTestClient(t, func(config *CmdConfig, tm *tcMocks) { | ||
iaID := "e819b321-a9a1-4078-b437-8e6b8bf13530" | ||
tm.vpcs.EXPECT().GetPartnerInterconnectAttachment(iaID).Return(&testIA, nil) | ||
|
||
config.Args = append(config.Args, iaID) | ||
|
||
err := RunPartnerInterconnectAttachmentGet(config) | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
|
||
func TestInterconnectAttachmentsGetNoID(t *testing.T) { | ||
withTestClient(t, func(config *CmdConfig, tm *tcMocks) { | ||
err := RunPartnerInterconnectAttachmentGet(config) | ||
assert.Error(t, err) | ||
}) | ||
} | ||
|
||
func TestInterconnectAttachmentsList(t *testing.T) { | ||
withTestClient(t, func(config *CmdConfig, tm *tcMocks) { | ||
tm.vpcs.EXPECT().ListPartnerInterconnectAttachments().Return(testIAList, nil) | ||
|
||
err := RunPartnerInterconnectAttachmentList(config) | ||
assert.NoError(t, err) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.