-
Notifications
You must be signed in to change notification settings - Fork 171
Add dynamic disk CLI support: disks --dynamic and delete-disk --dynamic
#728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e093a56
Add dynamic disk CLI commands (TNZ-99509, TNZ-109499)
Alphasite 98c5764
only implement list and delete for dynamic disks
KauzClay 0541a50
Add disk_pool_name to dynamic disk list response
Alphasite 062a1a8
Address PR review feedback for dynamic disk CLI
julian-hj 001aa75
Address further PR review feedback for dynamic disk CLI
julian-hj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,23 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| . "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" //nolint:staticcheck | ||
| boshdir "github.com/cloudfoundry/bosh-cli/v7/director" | ||
| boshui "github.com/cloudfoundry/bosh-cli/v7/ui" | ||
| ) | ||
|
|
||
| type AttachDynamicDiskCmd struct { | ||
| ui boshui.UI | ||
| director boshdir.Director | ||
| } | ||
|
|
||
| func NewAttachDynamicDiskCmd(ui boshui.UI, director boshdir.Director) AttachDynamicDiskCmd { | ||
| return AttachDynamicDiskCmd{ui: ui, director: director} | ||
| } | ||
|
|
||
| func (c AttachDynamicDiskCmd) Run(opts AttachDynamicDiskOpts) error { | ||
| instanceID := opts.Args.InstanceID.String() | ||
| diskName := opts.Args.DiskName | ||
|
|
||
| return c.director.AttachDynamicDisk(diskName, instanceID) | ||
| } |
This file contains hidden or 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,62 @@ | ||
| package cmd_test | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/cloudfoundry/bosh-cli/v7/cmd" | ||
| "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" | ||
| boshdir "github.com/cloudfoundry/bosh-cli/v7/director" | ||
| fakedir "github.com/cloudfoundry/bosh-cli/v7/director/directorfakes" | ||
| fakeui "github.com/cloudfoundry/bosh-cli/v7/ui/fakes" | ||
| ) | ||
|
|
||
| var _ = Describe("AttachDynamicDiskCmd", func() { | ||
| var ( | ||
| ui *fakeui.FakeUI | ||
| director *fakedir.FakeDirector | ||
| command cmd.AttachDynamicDiskCmd | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| ui = &fakeui.FakeUI{} | ||
| director = &fakedir.FakeDirector{} | ||
| command = cmd.NewAttachDynamicDiskCmd(ui, director) | ||
| }) | ||
|
|
||
| Describe("Run", func() { | ||
| var attachOpts opts.AttachDynamicDiskOpts | ||
|
|
||
| BeforeEach(func() { | ||
| slug := boshdir.NewInstanceSlug("worker", "xyz789") | ||
|
Check failure on line 33 in cmd/attach_dynamic_disk_test.go
|
||
|
|
||
| attachOpts = opts.AttachDynamicDiskOpts{ | ||
| Args: opts.AttachDynamicDiskArgs{ | ||
| DiskName: "my-disk", | ||
| InstanceID: slug, | ||
| }, | ||
| } | ||
| }) | ||
|
julian-hj marked this conversation as resolved.
Outdated
|
||
|
|
||
| act := func() error { return command.Run(attachOpts) } | ||
|
|
||
| It("attaches the dynamic disk to the instance", func() { | ||
| err := act() | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| diskName, instanceID := director.AttachDynamicDiskArgsForCall(0) | ||
| Expect(diskName).To(Equal("my-disk")) | ||
| Expect(instanceID).To(Equal("worker/xyz789")) | ||
| }) | ||
|
|
||
| It("returns error if attaching fails", func() { | ||
| director.AttachDynamicDiskReturns(errors.New("fake-err")) | ||
|
|
||
| err := act() | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring("fake-err")) | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or 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 hidden or 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,28 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| . "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" //nolint:staticcheck | ||
| boshdir "github.com/cloudfoundry/bosh-cli/v7/director" | ||
| boshui "github.com/cloudfoundry/bosh-cli/v7/ui" | ||
| ) | ||
|
|
||
| type CreateDynamicDiskCmd struct { | ||
| ui boshui.UI | ||
| director boshdir.Director | ||
| } | ||
|
|
||
| func NewCreateDynamicDiskCmd(ui boshui.UI, director boshdir.Director) CreateDynamicDiskCmd { | ||
| return CreateDynamicDiskCmd{ui: ui, director: director} | ||
| } | ||
|
|
||
| func (c CreateDynamicDiskCmd) Run(opts CreateDynamicDiskOpts) error { | ||
| diskName := opts.Args.DiskName | ||
|
|
||
| diskCID, err := c.director.CreateDynamicDisk(diskName, opts.DiskPool, opts.Size, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| c.ui.PrintLinef("Dynamic disk '%s' created (CID: %s)", diskName, diskCID) | ||
| return nil | ||
| } |
This file contains hidden or 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,64 @@ | ||
| package cmd_test | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/cloudfoundry/bosh-cli/v7/cmd" | ||
| "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" | ||
| fakedir "github.com/cloudfoundry/bosh-cli/v7/director/directorfakes" | ||
| fakeui "github.com/cloudfoundry/bosh-cli/v7/ui/fakes" | ||
| ) | ||
|
|
||
| var _ = Describe("CreateDynamicDiskCmd", func() { | ||
| var ( | ||
| ui *fakeui.FakeUI | ||
| director *fakedir.FakeDirector | ||
| command cmd.CreateDynamicDiskCmd | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| ui = &fakeui.FakeUI{} | ||
| director = &fakedir.FakeDirector{} | ||
| command = cmd.NewCreateDynamicDiskCmd(ui, director) | ||
| }) | ||
|
|
||
| Describe("Run", func() { | ||
| var createOpts opts.CreateDynamicDiskOpts | ||
|
|
||
| BeforeEach(func() { | ||
| createOpts = opts.CreateDynamicDiskOpts{ | ||
| Args: opts.CreateDynamicDiskArgs{DiskName: "my-disk"}, | ||
| DiskPool: "large", | ||
| Size: 102400, | ||
| } | ||
| }) | ||
|
|
||
| act := func() error { return command.Run(createOpts) } | ||
|
|
||
| It("creates a dynamic disk without attaching", func() { | ||
| director.CreateDynamicDiskReturns("disk-cid-456", nil) | ||
|
|
||
| err := act() | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| diskName, diskPool, sizeInMB, metadata := director.CreateDynamicDiskArgsForCall(0) | ||
| Expect(diskName).To(Equal("my-disk")) | ||
| Expect(diskPool).To(Equal("large")) | ||
| Expect(sizeInMB).To(Equal(102400)) | ||
| Expect(metadata).To(BeNil()) | ||
|
|
||
| Expect(ui.Said).To(ContainElement(ContainSubstring("my-disk"))) | ||
| }) | ||
|
|
||
| It("returns error if creation fails", func() { | ||
| director.CreateDynamicDiskReturns("", errors.New("fake-err")) | ||
|
|
||
| err := act() | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring("fake-err")) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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,25 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| . "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" //nolint:staticcheck | ||
| boshdir "github.com/cloudfoundry/bosh-cli/v7/director" | ||
| boshui "github.com/cloudfoundry/bosh-cli/v7/ui" | ||
| ) | ||
|
|
||
| type DeleteDynamicDiskCmd struct { | ||
| ui boshui.UI | ||
| director boshdir.Director | ||
| } | ||
|
|
||
| func NewDeleteDynamicDiskCmd(ui boshui.UI, director boshdir.Director) DeleteDynamicDiskCmd { | ||
| return DeleteDynamicDiskCmd{ui: ui, director: director} | ||
| } | ||
|
|
||
| func (c DeleteDynamicDiskCmd) Run(opts DeleteDynamicDiskOpts) error { | ||
| err := c.ui.AskForConfirmation() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.director.DeleteDynamicDisk(opts.Args.DiskName) | ||
| } |
This file contains hidden or 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,64 @@ | ||
| package cmd_test | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/cloudfoundry/bosh-cli/v7/cmd" | ||
| "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" | ||
| fakedir "github.com/cloudfoundry/bosh-cli/v7/director/directorfakes" | ||
| fakeui "github.com/cloudfoundry/bosh-cli/v7/ui/fakes" | ||
| ) | ||
|
|
||
| var _ = Describe("DeleteDynamicDiskCmd", func() { | ||
| var ( | ||
| ui *fakeui.FakeUI | ||
| director *fakedir.FakeDirector | ||
| command cmd.DeleteDynamicDiskCmd | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| ui = &fakeui.FakeUI{} | ||
| director = &fakedir.FakeDirector{} | ||
| command = cmd.NewDeleteDynamicDiskCmd(ui, director) | ||
| }) | ||
|
|
||
| Describe("Run", func() { | ||
| var deleteOpts opts.DeleteDynamicDiskOpts | ||
|
|
||
| BeforeEach(func() { | ||
| deleteOpts = opts.DeleteDynamicDiskOpts{ | ||
| Args: opts.DeleteDynamicDiskArgs{DiskName: "my-disk"}, | ||
| } | ||
| }) | ||
|
|
||
| act := func() error { return command.Run(deleteOpts) } | ||
|
|
||
| It("deletes the dynamic disk", func() { | ||
| err := act() | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| Expect(director.DeleteDynamicDiskArgsForCall(0)).To(Equal("my-disk")) | ||
| }) | ||
|
|
||
| It("returns error if deletion fails", func() { | ||
| director.DeleteDynamicDiskReturns(errors.New("fake-err")) | ||
|
|
||
| err := act() | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring("fake-err")) | ||
| }) | ||
|
|
||
| It("does not delete if confirmation is rejected", func() { | ||
| ui.AskedConfirmationErr = errors.New("stop") | ||
|
|
||
| err := act() | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring("stop")) | ||
|
|
||
| Expect(director.DeleteDynamicDiskCallCount()).To(Equal(0)) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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,25 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| . "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" //nolint:staticcheck | ||
| boshdir "github.com/cloudfoundry/bosh-cli/v7/director" | ||
| boshui "github.com/cloudfoundry/bosh-cli/v7/ui" | ||
| ) | ||
|
|
||
| type DetachDynamicDiskCmd struct { | ||
| ui boshui.UI | ||
| director boshdir.Director | ||
| } | ||
|
|
||
| func NewDetachDynamicDiskCmd(ui boshui.UI, director boshdir.Director) DetachDynamicDiskCmd { | ||
| return DetachDynamicDiskCmd{ui: ui, director: director} | ||
| } | ||
|
|
||
| func (c DetachDynamicDiskCmd) Run(opts DetachDynamicDiskOpts) error { | ||
| err := c.ui.AskForConfirmation() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.director.DetachDynamicDisk(opts.Args.DiskName) | ||
| } |
This file contains hidden or 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,64 @@ | ||
| package cmd_test | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/cloudfoundry/bosh-cli/v7/cmd" | ||
| "github.com/cloudfoundry/bosh-cli/v7/cmd/opts" | ||
| fakedir "github.com/cloudfoundry/bosh-cli/v7/director/directorfakes" | ||
| fakeui "github.com/cloudfoundry/bosh-cli/v7/ui/fakes" | ||
| ) | ||
|
|
||
| var _ = Describe("DetachDynamicDiskCmd", func() { | ||
| var ( | ||
| ui *fakeui.FakeUI | ||
| director *fakedir.FakeDirector | ||
| command cmd.DetachDynamicDiskCmd | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| ui = &fakeui.FakeUI{} | ||
| director = &fakedir.FakeDirector{} | ||
| command = cmd.NewDetachDynamicDiskCmd(ui, director) | ||
| }) | ||
|
|
||
| Describe("Run", func() { | ||
| var detachOpts opts.DetachDynamicDiskOpts | ||
|
|
||
| BeforeEach(func() { | ||
| detachOpts = opts.DetachDynamicDiskOpts{ | ||
| Args: opts.DetachDynamicDiskArgs{DiskName: "my-disk"}, | ||
| } | ||
| }) | ||
|
|
||
| act := func() error { return command.Run(detachOpts) } | ||
|
|
||
| It("detaches the dynamic disk", func() { | ||
| err := act() | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| Expect(director.DetachDynamicDiskArgsForCall(0)).To(Equal("my-disk")) | ||
| }) | ||
|
|
||
| It("returns error if detaching fails", func() { | ||
| director.DetachDynamicDiskReturns(errors.New("fake-err")) | ||
|
|
||
| err := act() | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring("fake-err")) | ||
| }) | ||
|
|
||
| It("does not detach if confirmation is rejected", func() { | ||
| ui.AskedConfirmationErr = errors.New("stop") | ||
|
|
||
| err := act() | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring("stop")) | ||
|
|
||
| Expect(director.DetachDynamicDiskCallCount()).To(Equal(0)) | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.