Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions commands/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ doctl nfs list --region 'atl1' --format ID,Name,Size,Status`
cmdNfsDetach.Example =
`doctl nfs detach --region 'atl1' --id b050990d-4337-4a9d-9c8d-9f759a83936a --vpc_id example-vpc-id`

cmdNfsReassign := CmdBuilder(cmd, nfsReassign, "reassign [flags]", "Reassign an NFS share between VPCs", "Reassigns an NFS share from one VPC to another with the given ID.", Writer)
AddStringFlag(cmdNfsReassign, "id", "", "", "the ID of the NFS share", requiredOpt())
AddStringFlag(cmdNfsReassign, "old-vpc-id", "", "", "the id of the VPC we want to detach NFS share from", requiredOpt())
AddStringFlag(cmdNfsReassign, "new-vpc-id", "", "", "the id of the VPC we want to attach NFS share to", requiredOpt())
AddBoolFlag(cmdNfsReassign, doctl.ArgCommandWait, "", false, "Wait for action to complete")
cmdNfsReassign.Example =
`doctl nfs reassign --id b050990d-4337-4a9d-9c8d-9f759a83936a --old-vpc-id old-vpc-id --new-vpc-id new-vpc-id`

cmdNfsSwitchPerformanceTier := CmdBuilder(cmd, nfsSwitchPerformanceTier, "switch-performance-tier [flags]", "Switch the performance tier of an NFS share", "Switch the performance tier of an NFS share with the given ID and tier.", Writer)
AddStringFlag(cmdNfsSwitchPerformanceTier, "id", "", "", "the ID of the NFS share", requiredOpt())
AddStringFlag(cmdNfsSwitchPerformanceTier, "performance-tier", "", "", "the performance tier of the NFS share", requiredOpt())
Expand Down Expand Up @@ -410,6 +418,41 @@ func nfsDetach(c *CmdConfig) error {
return c.Display(item)
}

func nfsReassign(c *CmdConfig) error {
id, err := c.Doit.GetString(c.NS, "id")
if err != nil {
return err
}
oldVpcID, err := c.Doit.GetString(c.NS, "old-vpc-id")
if err != nil {
return err
}
newVpcID, err := c.Doit.GetString(c.NS, "new-vpc-id")
if err != nil {
return err
}

action, err := c.NfsActions().Reassign(id, oldVpcID, newVpcID)
if err != nil {
return err
}

wait, err := c.Doit.GetBool(c.NS, doctl.ArgCommandWait)
if err != nil {
return err
}

if wait {
_, err := actionWait(c, action.ID, 5)
if err != nil {
return err
}
}

item := &displayers.NfsAction{NfsActions: []do.NfsAction{*action}}
return c.Display(item)
}

func nfsSwitchPerformanceTier(c *CmdConfig) error {
id, err := c.Doit.GetString(c.NS, "id")
if err != nil {
Expand Down
55 changes: 54 additions & 1 deletion commands/nfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (
func TestNfsCommand(t *testing.T) {
cmd := Nfs()
assert.NotNil(t, cmd)
assertCommandNames(t, cmd, "create", "list", "get", "delete", "snapshot", "resize", "attach", "detach", "switch-performance-tier")
assertCommandNames(t, cmd, "create", "list", "get", "delete", "snapshot", "resize", "attach", "detach", "reassign", "switch-performance-tier")
}

func TestRunNfsCreate(t *testing.T) {
Expand Down Expand Up @@ -495,6 +495,59 @@ func TestRunNfsDetach(t *testing.T) {
}
}

func TestRunNfsReassign(t *testing.T) {
testCases := []struct {
name string
id string
oldVpcID string
newVpcID string
wait bool
expectErr bool
}{
{
name: "success without wait",
id: testId,
oldVpcID: "vpc-old",
newVpcID: "vpc-new",
wait: false,
expectErr: false,
},
{
name: "success with wait",
id: testId,
oldVpcID: "vpc-old",
newVpcID: "vpc-new",
wait: true,
expectErr: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
if !tc.expectErr {
tm.nfsActions.EXPECT().Reassign(tc.id, tc.oldVpcID, tc.newVpcID).Return(&testNfsAction, nil)
if tc.wait {
tm.actions.EXPECT().Get(testNfsAction.ID).Return(&testAction, nil)
}
}

config.Doit.Set(config.NS, "id", tc.id)
config.Doit.Set(config.NS, "old-vpc-id", tc.oldVpcID)
config.Doit.Set(config.NS, "new-vpc-id", tc.newVpcID)
config.Doit.Set(config.NS, "wait", tc.wait)

err := nfsReassign(config)
if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
})
}
}

func TestRunNfsSwitchPerformanceTier(t *testing.T) {
testCases := []struct {
name string
Expand Down
15 changes: 15 additions & 0 deletions do/mocks/NfsActionsService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions do/nfs_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type NfsActionsService interface {
Snapshot(id, name, region string) (*NfsAction, error)
Attach(id, vpcID, region string) (*NfsAction, error)
Detach(id, vpcID, region string) (*NfsAction, error)
Reassign(id, oldVpcID, newVpcID string) (*NfsAction, error)
SwitchPerformanceTier(id, tier string) (*NfsAction, error)
}

Expand Down Expand Up @@ -81,6 +82,14 @@ func (s *nfsActionsService) Detach(id, vpcID, region string) (*NfsAction, error)
return &NfsAction{NfsAction: action}, nil
}

func (s *nfsActionsService) Reassign(id, oldVpcID, newVpcID string) (*NfsAction, error) {
action, _, err := s.client.NfsActions.Reassign(context.TODO(), id, oldVpcID, newVpcID)
if err != nil {
return nil, err
}
return &NfsAction{NfsAction: action}, nil
}

func (s *nfsActionsService) SwitchPerformanceTier(id, tier string) (*NfsAction, error) {
action, _, err := s.client.NfsActions.SwitchPerformanceTier(context.TODO(), id, tier)
if err != nil {
Expand Down
Loading