Skip to content

Commit 647e2ee

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #717 from Brian-Flores/issue716
Add `--biling` option in `ibmcloud sl block volume-duplicate`
2 parents 96c5db8 + ad55df9 commit 647e2ee

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

plugin/commands/block/volume_duplicate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type VolumeDuplicateCommand struct {
2323
DuplicateSnapshotSize int
2424
DependentDuplicate bool
2525
Force bool
26+
Billing string
2627
}
2728

2829
func NewVolumeDuplicateCommand(sl *metadata.SoftlayerStorageCommand) *VolumeDuplicateCommand {
@@ -50,6 +51,7 @@ EXAMPLE:
5051
cobraCmd.Flags().IntVarP(&thisCmd.DuplicateSnapshotSize, "duplicate-snapshot-size", "n", -1, T("The size of snapshot space to order for the duplicate, if no snapshot space size is specified, the snapshot space size of the origin volume will be used"))
5152
cobraCmd.Flags().BoolVarP(&thisCmd.DependentDuplicate, "dependent-duplicate", "d", false, T("Whether or not this duplicate will be a dependent duplicate of the origin volume."))
5253
cobraCmd.Flags().BoolVarP(&thisCmd.Force, "force", "f", false, T("Force operation without confirmation"))
54+
cobraCmd.Flags().StringVar(&thisCmd.Billing, "billing", "monthly", T("Optional parameter for Billing rate (default to monthly) Choices: hourly or monthly"))
5355
thisCmd.Command = cobraCmd
5456
return thisCmd
5557
}
@@ -61,6 +63,14 @@ func (cmd *VolumeDuplicateCommand) Run(args []string) error {
6163
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
6264
}
6365

66+
billing := cmd.Billing
67+
hourlyBillingFlag := false
68+
if billing != "monthly" && billing != "hourly" {
69+
return slErr.NewInvalidUsageError("--billing")
70+
} else if billing == "hourly" {
71+
hourlyBillingFlag = true
72+
}
73+
6474
outputFormat := cmd.GetOutputFlag()
6575

6676
if !cmd.Force && outputFormat != "JSON" {
@@ -82,6 +92,7 @@ func (cmd *VolumeDuplicateCommand) Run(args []string) error {
8292
DuplicateTier: cmd.DuplicateTier,
8393
DuplicateSnapshotSize: cmd.DuplicateSnapshotSize,
8494
DependentDuplicate: cmd.DependentDuplicate,
95+
HourlyBillingFlag: hourlyBillingFlag,
8596
}
8697
orderReceipt, err := cmd.StorageManager.OrderDuplicateVolume(config)
8798
if err != nil {

plugin/commands/block/volume_duplicate_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ var _ = Describe("Volume duplicate", func() {
8585
Expect(results).To(ContainSubstring("Order 555 was placed"))
8686
})
8787
})
88+
Context("Volume duplicate witho hourly billing", func() {
89+
BeforeEach(func() {
90+
FakeStorageManager.OrderDuplicateVolumeReturns(FakeOrderReceipt, nil)
91+
})
92+
It("No return error", func() {
93+
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345", "--billing=hourly", "-f")
94+
Expect(err).NotTo(HaveOccurred())
95+
results := fakeUI.Outputs()
96+
calledWith := FakeStorageManager.OrderDuplicateVolumeArgsForCall(0)
97+
Expect(calledWith.DuplicateSnapshotSize).To(Equal(-1))
98+
Expect(results).To(ContainSubstring("Order 555 was placed"))
99+
})
100+
It("Set invalid billing value", func() {
101+
err := testhelpers.RunCobraCommand(cliCommand.Command, "12345", "--billing=hour", "-f")
102+
Expect(err).To(HaveOccurred())
103+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: --billing"))
104+
})
105+
})
88106
Context("Ordering Error", func() {
89107
BeforeEach(func() {
90108
FakeStorageManager.OrderDuplicateVolumeReturns(FakeOrderReceipt, errors.New("SoftLayer_Exception_ApiError"))

plugin/managers/storage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ type DuplicateOrderConfig struct {
142142
DuplicateSnapshotSize int
143143
//Create a dependent duplicate volume.
144144
DependentDuplicate bool
145+
//Set hourly or monthly billing.
146+
HourlyBillingFlag bool
145147
}
146148

147149
func NewStorageManager(session *session.Session) *storageManager {
@@ -615,6 +617,7 @@ func (s storageManager) OrderDuplicateVolume(config DuplicateOrderConfig) (datat
615617
if err != nil {
616618
return datatypes.Container_Product_Order_Receipt{}, err
617619
}
620+
order.UseHourlyPricing = &config.HourlyBillingFlag
618621
if config.VolumeType == VOLUME_TYPE_BLOCK {
619622
order.OsFormatType = &datatypes.Network_Storage_Iscsi_OS_Type{KeyName: sl.String(osType)}
620623
}

0 commit comments

Comments
 (0)