Skip to content

Commit 5476a00

Browse files
#722 more command using GetVolumeId
1 parent 4160d74 commit 5476a00

18 files changed

Lines changed: 51 additions & 80 deletions

plugin/commands/block/replica_order.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package block
22

33
import (
44
"fmt"
5-
"strconv"
65

76
"github.com/spf13/cobra"
87

@@ -33,9 +32,7 @@ func NewReplicaOrderCommand(sl *metadata.SoftlayerStorageCommand) *ReplicaOrderC
3332
cobraCmd := &cobra.Command{
3433
Use: "replica-order " + T("IDENTIFIER"),
3534
Short: T("Order a block storage replica volume"),
36-
Long: T(`${COMMAND_NAME} sl {{.storageType}} replica-order VOLUME_ID [OPTIONS]
37-
38-
EXAMPLE:
35+
Long: T(`EXAMPLE:
3936
${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX
4037
This command orders a replica for volume with ID 12345678, which performs DAILY replication, is located at dal09, tier level is 4, OS type is Linux.`, sl.StorageI18n),
4138
Args: metadata.OneArgs,
@@ -55,9 +52,9 @@ EXAMPLE:
5552

5653
func (cmd *ReplicaOrderCommand) Run(args []string) error {
5754

58-
volumeID, err := strconv.Atoi(args[0])
55+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5956
if err != nil {
60-
return errors.NewInvalidSoftlayerIdInputError("Volume ID")
57+
return err
6158
}
6259

6360
snapshotSchedule := cmd.SnapshotSchedule

plugin/commands/block/replica_order_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var _ = Describe("Replica order", func() {
3131
cliCommand = block.NewReplicaOrderCommand(slCommand)
3232
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3333
cliCommand.StorageManager = FakeStorageManager
34+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3435
})
3536

3637
Describe("Replicant order", func() {
@@ -41,13 +42,6 @@ var _ = Describe("Replica order", func() {
4142
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
4243
})
4344
})
44-
Context("Replicant order with wrong volume id", func() {
45-
It("return error", func() {
46-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
47-
Expect(err).To(HaveOccurred())
48-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
49-
})
50-
})
5145
Context("Replicant order without -s", func() {
5246
It("return error", func() {
5347
err := testhelpers.RunCobraCommand(cliCommand.Command, "123")
@@ -112,7 +106,7 @@ var _ = Describe("Replica order", func() {
112106
It("return error", func() {
113107
err := testhelpers.RunCobraCommand(cliCommand.Command, "123", "-s", "DAILY", "-d", "dal09", "-t", "4", "-o", "LINUX", "-f")
114108
Expect(err).To(HaveOccurred())
115-
Expect(err.Error()).To(ContainSubstring("Failed to order replicant for volume 123.Please verify your options and try again."))
109+
Expect(err.Error()).To(ContainSubstring("Failed to order replicant for volume 1234.Please verify your options and try again."))
116110
})
117111
})
118112

plugin/commands/block/replica_partners.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package block
22

33
import (
4-
"strconv"
5-
64
"github.com/spf13/cobra"
75

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -26,9 +24,7 @@ func NewReplicaPartnersCommand(sl *metadata.SoftlayerStorageCommand) *ReplicaPar
2624
cobraCmd := &cobra.Command{
2725
Use: "replica-partners " + T("IDENTIFIER"),
2826
Short: T("List existing replicant volumes for a block volume"),
29-
Long: T(`${COMMAND_NAME} sl {{.storageType}} replica-partners VOLUME_ID [OPTIONS]
30-
31-
EXAMPLE:
27+
Long: T(`EXAMPLE:
3228
${COMMAND_NAME} sl {{.storageType}} replica-partners 12345678
3329
This command lists existing replicant volumes for block volume with ID 12345678.`, sl.StorageI18n),
3430
Args: metadata.OneArgs,
@@ -43,10 +39,11 @@ EXAMPLE:
4339

4440
func (cmd *ReplicaPartnersCommand) Run(args []string) error {
4541

46-
volumeID, err := strconv.Atoi(args[0])
42+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
4743
if err != nil {
48-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
44+
return err
4945
}
46+
5047
outputFormat := cmd.GetOutputFlag()
5148

5249
partners, err := cmd.StorageManager.GetReplicationPartners(volumeID)

plugin/commands/block/replica_partners_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var _ = Describe("Replica partners", func() {
3131
cliCommand = block.NewReplicaPartnersCommand(slCommand)
3232
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3333
cliCommand.StorageManager = FakeStorageManager
34+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3435
})
3536

3637
Describe("Replicant partners", func() {

plugin/commands/block/snapshot-get_notification_status.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package block
22

33
import (
4-
"strconv"
5-
64
"github.com/spf13/cobra"
75

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -38,11 +36,12 @@ func NewSnapshotGetNotificationStatusCommand(sl *metadata.SoftlayerStorageComman
3836

3937
func (cmd *SnapshotGetNotificationStatusCommand) Run(args []string) error {
4038

41-
volumeID, err := strconv.Atoi(args[0])
39+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
4240
if err != nil {
43-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
41+
return err
4442
}
4543

44+
4645
outputFormat := cmd.GetOutputFlag()
4746
subs := map[string]interface{}{"ID": volumeID}
4847
enabled, err := cmd.StorageManager.GetSnapshotNotificationStatus(volumeID)

plugin/commands/block/snapshot-get_notification_status_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var _ = Describe("Volume snapshot notification status", func() {
2929
cliCommand = block.NewSnapshotGetNotificationStatusCommand(slCommand)
3030
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3131
cliCommand.StorageManager = FakeStorageManager
32+
FakeStorageManager.GetVolumeIdReturns(1234567, nil)
3233
})
3334

3435
Describe("Get volume snapshot notification status", func() {
@@ -40,14 +41,6 @@ var _ = Describe("Volume snapshot notification status", func() {
4041
})
4142
})
4243

43-
Context("Volume get notification status with wrong volume id", func() {
44-
It("return error", func() {
45-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
46-
Expect(err).To(HaveOccurred())
47-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
48-
})
49-
})
50-
5144
Context("Volume get notification status with an error", func() {
5245
BeforeEach(func() {
5346
FakeStorageManager.GetSnapshotNotificationStatusReturns(-1, errors.New("Internal Server Error"))

plugin/commands/block/snapshot_cancel.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package block
22

33
import (
4-
"strconv"
5-
64
"github.com/spf13/cobra"
75

86
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
@@ -28,9 +26,7 @@ func NewSnapshotCancelCommand(sl *metadata.SoftlayerStorageCommand) *SnapshotCan
2826
cobraCmd := &cobra.Command{
2927
Use: "snapshot-cancel " + T("IDENTIFIER"),
3028
Short: T("Cancel existing snapshot space for a given volume"),
31-
Long: T(`${COMMAND_NAME} sl {{.storageType}} snapshot-cancel SNAPSHOT_ID [OPTIONS]
32-
33-
EXAMPLE:
29+
Long: T(`EXAMPLE:
3430
${COMMAND_NAME} sl {{.storageType}} snapshot-cancel 12345678 --immediate -f
3531
This command cancels snapshot with ID 12345678 immediately without asking for confirmation.`, sl.StorageI18n),
3632
Args: metadata.OneArgs,
@@ -48,9 +44,9 @@ EXAMPLE:
4844

4945
func (cmd *SnapshotCancelCommand) Run(args []string) error {
5046

51-
volumeID, err := strconv.Atoi(args[0])
47+
volumeID, err := cmd.StorageManager.GetVolumeId(args[0], cmd.StorageType)
5248
if err != nil {
53-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
49+
return err
5450
}
5551
subs := map[string]interface{}{"ID": volumeID}
5652
if !cmd.Force {

plugin/commands/block/snapshot_cancel_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var _ = Describe("Snapshot Cancel", func() {
2929
cliCommand = block.NewSnapshotCancelCommand(slCommand)
3030
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
3131
cliCommand.StorageManager = FakeStorageManager
32+
FakeStorageManager.GetVolumeIdReturns(1234, nil)
3233
})
3334

3435
Describe("Snapshot cancel", func() {
@@ -39,13 +40,6 @@ var _ = Describe("Snapshot Cancel", func() {
3940
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires one argument"))
4041
})
4142
})
42-
Context("Snapshot cancel with wrong volume id", func() {
43-
It("error resolving volume ID", func() {
44-
err := testhelpers.RunCobraCommand(cliCommand.Command, "abc")
45-
Expect(err).To(HaveOccurred())
46-
Expect(err.Error()).To(ContainSubstring("Invalid input for 'Volume ID'. It must be a positive integer."))
47-
})
48-
})
4943

5044
Context("Snapshot cancel with correct volume id without -f and not continue", func() {
5145
BeforeEach(func() {

plugin/i18n/v2Resources/active.de_DE.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@
365365
"${COMMAND_NAME} sl {{.storageType}} replica-locations VOLUME_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-locations 12345678\n This command lists suitable replication data centers for block volume with ID 12345678.": {
366366
"other": "${COMMAND_NAME} sl {{.storageType}} replica-locations DATENTRÄGER_ID [OPTIONEN]\n \nBEISPIEL:\n ${COMMAND_NAME} sl {{.storageType}} replica-locations 12345678\n Dieser Befehl listet geeignete Replikationsrechenzentren für den Blockdatenträger mit der ID 12345678 auf."
367367
},
368-
"${COMMAND_NAME} sl {{.storageType}} replica-order VOLUME_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX\n This command orders a replica for volume with ID 12345678, which performs DAILY replication, is located at dal09, tier level is 4, OS type is Linux.": {
368+
"EXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX\n This command orders a replica for volume with ID 12345678, which performs DAILY replication, is located at dal09, tier level is 4, OS type is Linux.": {
369369
"other": "${COMMAND_NAME} sl {{.storageType}} replica-order DATENTRÄGER_ID [OPTIONEN]\n \nBEISPIEL:\n ${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s TÄGLICH -d dal09 --tier 4 --os-type LINUX\n Dieser Befehl bestellt ein Replikat für den Datenträger mit der ID 12345678, der die Replikation TÄGLICH ausführt, und befindet sich auf dal09, Ebene der Schicht ist 4, Betriebssystemtyp ist Linux."
370370
},
371-
"${COMMAND_NAME} sl {{.storageType}} replica-partners VOLUME_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-partners 12345678\n This command lists existing replicant volumes for block volume with ID 12345678.": {
371+
"EXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-partners 12345678\n This command lists existing replicant volumes for block volume with ID 12345678.": {
372372
"other": "${COMMAND_NAME} sl {{.storageType}} replica-partners DATENTRÄGER_ID [OPTIONEN]\n \nBEISPIEL:\n ${COMMAND_NAME} sl {{.storageType}} replica-partners 12345678\n Dieser Befehl listet vorhandene Replikatdatenträger für Blockdatenträger mit der ID 12345678 auf."
373373
},
374374
"${COMMAND_NAME} sl {{.storageType}} snapshot-cancel SNAPSHOT_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} snapshot-cancel 12345678 --immediate -f \n This command cancels snapshot with ID 12345678 immediately without asking for confirmation.": {

plugin/i18n/v2Resources/active.en-US.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@
365365
"EXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-failover 12345678 87654321\n This command performs failover operation for volume with ID 12345678 to replica volume with ID 87654321.": {
366366
"other": "EXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-failover 12345678 87654321\n This command performs failover operation for volume with ID 12345678 to replica volume with ID 87654321."
367367
},
368-
"${COMMAND_NAME} sl {{.storageType}} replica-order VOLUME_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX\n This command orders a replica for volume with ID 12345678, which performs DAILY replication, is located at dal09, tier level is 4, OS type is Linux.": {
369-
"other": "${COMMAND_NAME} sl {{.storageType}} replica-order VOLUME_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX\n This command orders a replica for volume with ID 12345678, which performs DAILY replication, is located at dal09, tier level is 4, OS type is Linux."
368+
"EXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX\n This command orders a replica for volume with ID 12345678, which performs DAILY replication, is located at dal09, tier level is 4, OS type is Linux.": {
369+
"other": "EXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX\n This command orders a replica for volume with ID 12345678, which performs DAILY replication, is located at dal09, tier level is 4, OS type is Linux."
370370
},
371-
"${COMMAND_NAME} sl {{.storageType}} replica-partners VOLUME_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-partners 12345678\n This command lists existing replicant volumes for block volume with ID 12345678.": {
372-
"other": "${COMMAND_NAME} sl {{.storageType}} replica-partners VOLUME_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-partners 12345678\n This command lists existing replicant volumes for block volume with ID 12345678."
371+
"EXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-partners 12345678\n This command lists existing replicant volumes for block volume with ID 12345678.": {
372+
"other": "EXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} replica-partners 12345678\n This command lists existing replicant volumes for block volume with ID 12345678."
373373
},
374374
"${COMMAND_NAME} sl {{.storageType}} snapshot-cancel SNAPSHOT_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} snapshot-cancel 12345678 --immediate -f \n This command cancels snapshot with ID 12345678 immediately without asking for confirmation.": {
375375
"other": "${COMMAND_NAME} sl {{.storageType}} snapshot-cancel SNAPSHOT_ID [OPTIONS]\n\t\t\nEXAMPLE:\n ${COMMAND_NAME} sl {{.storageType}} snapshot-cancel 12345678 --immediate -f \n This command cancels snapshot with ID 12345678 immediately without asking for confirmation."

0 commit comments

Comments
 (0)