Skip to content

Commit 02f7022

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #764 from Ramkishor-Chaladi/issue_729
Added Description and some features in sl block replica-order, sl block replica-partners, sl block snapshot-cancel, sl block snapshot-create, sl block snapshot-disable
2 parents 333f6e1 + 37c069d commit 02f7022

5 files changed

Lines changed: 161 additions & 2 deletions

File tree

plugin/commands/block/replica_order.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewReplicaOrderCommand(sl *metadata.SoftlayerStorageCommand) *ReplicaOrderC
3434
Use: "replica-order " + T("IDENTIFIER"),
3535
Short: T("Order a block storage replica volume"),
3636
Long: T(`${COMMAND_NAME} sl {{.storageType}} replica-order VOLUME_ID [OPTIONS]
37-
37+
3838
EXAMPLE:
3939
${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX
4040
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),

plugin/commands/block/replica_partners.go

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

33
import (
4+
"sort"
45
"strconv"
56

67
"github.com/spf13/cobra"
@@ -16,6 +17,7 @@ type ReplicaPartnersCommand struct {
1617
*metadata.SoftlayerStorageCommand
1718
Command *cobra.Command
1819
StorageManager managers.StorageManager
20+
Sortby string
1921
}
2022

2123
func NewReplicaPartnersCommand(sl *metadata.SoftlayerStorageCommand) *ReplicaPartnersCommand {
@@ -37,6 +39,7 @@ EXAMPLE:
3739
},
3840
}
3941

42+
cobraCmd.Flags().StringVar(&thisCmd.Sortby, "sortby", "username", T("Column to sort by. Options are: id, username, accountId, capacityGb, hardwareId, guestId, hostId"))
4043
thisCmd.Command = cobraCmd
4144
return thisCmd
4245
}
@@ -47,6 +50,8 @@ func (cmd *ReplicaPartnersCommand) Run(args []string) error {
4750
if err != nil {
4851
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
4952
}
53+
sortby := cmd.Sortby
54+
5055
outputFormat := cmd.GetOutputFlag()
5156

5257
partners, err := cmd.StorageManager.GetReplicationPartners(volumeID)
@@ -55,6 +60,24 @@ func (cmd *ReplicaPartnersCommand) Run(args []string) error {
5560
return slErr.NewAPIError(T("Failed to get replication partners for volume {{.VolumeID}}.\n", subs), err.Error(), 2)
5661
}
5762

63+
if sortby == "id" {
64+
sort.Sort(utils.VolumeById(partners))
65+
} else if sortby == "username" {
66+
sort.Sort(utils.VolumeByUsername(partners))
67+
} else if sortby == "accountId" {
68+
sort.Sort(utils.VolumeByAccountId(partners))
69+
} else if sortby == "capacityGb" {
70+
sort.Sort(utils.VolumeByCapacity(partners))
71+
} else if sortby == "hardwareId" {
72+
sort.Sort(utils.VolumeByHardwareById(partners))
73+
} else if sortby == "guestId" {
74+
sort.Sort(utils.VolumeByGuestId(partners))
75+
} else if sortby == "hostId" {
76+
sort.Sort(utils.VolumeByHostId(partners))
77+
} else {
78+
return slErr.NewInvalidUsageError(T("--sortby '{{.Column}}' is not supported.", map[string]interface{}{"Column": sortby}))
79+
}
80+
5881
if outputFormat == "JSON" {
5982
return utils.PrintPrettyJSON(cmd.UI, partners)
6083
}

plugin/commands/block/replica_partners_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,81 @@ var _ = Describe("Replica partners", func() {
8484
Expect(fakeUI.Outputs()).To(ContainSubstring("There are no replication partners for volume 1234."))
8585
})
8686
})
87+
Context("Replica partners with correct volume id and --sortby id", func() {
88+
BeforeEach(func() {
89+
FakeStorageManager.GetReplicationPartnersReturns(nil, nil)
90+
})
91+
It("return table", func() {
92+
err := testhelpers.RunCobraCommand(cliCommand.Command, "442707460", "--sortby=id")
93+
Expect(err).NotTo(HaveOccurred())
94+
Expect(fakeUI.Outputs()).To(ContainSubstring("442707460"))
95+
})
96+
})
97+
98+
Context("Replica partners with correct volume id and --sortby accountId", func() {
99+
BeforeEach(func() {
100+
FakeStorageManager.GetReplicationPartnersReturns(nil, nil)
101+
})
102+
It("return table", func() {
103+
err := testhelpers.RunCobraCommand(cliCommand.Command, "307608", "--sortby=accountId")
104+
Expect(err).NotTo(HaveOccurred())
105+
Expect(fakeUI.Outputs()).To(ContainSubstring("307608"))
106+
})
107+
})
108+
109+
Context("Replica partners with correct volume id and --sortby capacityGb", func() {
110+
BeforeEach(func() {
111+
FakeStorageManager.GetReplicationPartnersReturns(nil, nil)
112+
})
113+
It("return table", func() {
114+
err := testhelpers.RunCobraCommand(cliCommand.Command, "25", "--sortby=capacityGb")
115+
Expect(err).NotTo(HaveOccurred())
116+
Expect(fakeUI.Outputs()).To(ContainSubstring("25"))
117+
})
118+
})
119+
120+
Context("Replica partners with correct volume id and --sortby hardwareId", func() {
121+
BeforeEach(func() {
122+
FakeStorageManager.GetReplicationPartnersReturns(nil, nil)
123+
})
124+
It("return table", func() {
125+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--sortby=hardwareId")
126+
Expect(err).NotTo(HaveOccurred())
127+
Expect(fakeUI.Outputs()).To(ContainSubstring("1234"))
128+
})
129+
})
130+
131+
Context("Replica partners with correct volume id and --sortby guestId", func() {
132+
BeforeEach(func() {
133+
FakeStorageManager.GetReplicationPartnersReturns(nil, nil)
134+
})
135+
It("return table", func() {
136+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--sortby=guestId")
137+
Expect(err).NotTo(HaveOccurred())
138+
Expect(fakeUI.Outputs()).To(ContainSubstring("1234"))
139+
})
140+
})
141+
142+
Context("Replica partners with correct volume id and --sortby hostId", func() {
143+
BeforeEach(func() {
144+
FakeStorageManager.GetReplicationPartnersReturns(nil, nil)
145+
})
146+
It("return table", func() {
147+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--sortby=hostId")
148+
Expect(err).NotTo(HaveOccurred())
149+
Expect(fakeUI.Outputs()).To(ContainSubstring("1234"))
150+
})
151+
})
152+
153+
Context("Replica partners with correct volume id and --sortby abcd", func() {
154+
BeforeEach(func() {
155+
FakeStorageManager.GetReplicationPartnersReturns(nil, nil)
156+
})
157+
It("return error", func() {
158+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--sortby=abcd")
159+
Expect(err).To(HaveOccurred())
160+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: --sortby 'abcd' is not supported."))
161+
})
162+
})
87163
})
88164
})

plugin/commands/block/snapshot_cancel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewSnapshotCancelCommand(sl *metadata.SoftlayerStorageCommand) *SnapshotCan
2929
Use: "snapshot-cancel " + T("IDENTIFIER"),
3030
Short: T("Cancel existing snapshot space for a given volume"),
3131
Long: T(`${COMMAND_NAME} sl {{.storageType}} snapshot-cancel SNAPSHOT_ID [OPTIONS]
32-
32+
3333
EXAMPLE:
3434
${COMMAND_NAME} sl {{.storageType}} snapshot-cancel 12345678 --immediate -f
3535
This command cancels snapshot with ID 12345678 immediately without asking for confirmation.`, sl.StorageI18n),

plugin/utils/blocksort.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,66 @@ func (a VolumeByUsername) Less(i, j int) bool {
3636
return false
3737
}
3838

39+
type VolumeByAccountId []datatypes.Network_Storage
40+
41+
func (a VolumeByAccountId) Len() int {
42+
return len(a)
43+
}
44+
func (a VolumeByAccountId) Swap(i, j int) {
45+
a[i], a[j] = a[j], a[i]
46+
}
47+
func (a VolumeByAccountId) Less(i, j int) bool {
48+
if a[i].AccountId != nil && a[j].AccountId != nil {
49+
return *a[i].AccountId < *a[j].AccountId
50+
}
51+
return false
52+
}
53+
54+
type VolumeByHardwareById []datatypes.Network_Storage
55+
56+
func (a VolumeByHardwareById) Len() int {
57+
return len(a)
58+
}
59+
func (a VolumeByHardwareById) Swap(i, j int) {
60+
a[i], a[j] = a[j], a[i]
61+
}
62+
func (a VolumeByHardwareById) Less(i, j int) bool {
63+
if a[i].HardwareId != nil && a[j].HardwareId != nil {
64+
return *a[i].HardwareId < *a[j].HardwareId
65+
}
66+
return false
67+
}
68+
69+
type VolumeByGuestId []datatypes.Network_Storage
70+
71+
func (a VolumeByGuestId) Len() int {
72+
return len(a)
73+
}
74+
func (a VolumeByGuestId) Swap(i, j int) {
75+
a[i], a[j] = a[j], a[i]
76+
}
77+
func (a VolumeByGuestId) Less(i, j int) bool {
78+
if a[i].GuestId != nil && a[j].GuestId != nil {
79+
return *a[i].GuestId < *a[j].GuestId
80+
}
81+
return false
82+
}
83+
84+
type VolumeByHostId []datatypes.Network_Storage
85+
86+
func (a VolumeByHostId) Len() int {
87+
return len(a)
88+
}
89+
func (a VolumeByHostId) Swap(i, j int) {
90+
a[i], a[j] = a[j], a[i]
91+
}
92+
func (a VolumeByHostId) Less(i, j int) bool {
93+
if a[i].HostId != nil && a[j].HostId != nil {
94+
return *a[i].HostId < *a[j].HostId
95+
}
96+
return false
97+
}
98+
3999
type VolumeByDatacenter []datatypes.Network_Storage
40100

41101
func (a VolumeByDatacenter) Len() int {

0 commit comments

Comments
 (0)