Skip to content

Commit f810087

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
added the descriptions and sub features like --sortby and INTERVAL
1 parent 2fb289c commit f810087

7 files changed

Lines changed: 99 additions & 8 deletions

File tree

plugin/commands/block/replica_order.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ 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+
38+
Order a block storage replica volume.
39+
3840
EXAMPLE:
3941
${COMMAND_NAME} sl {{.storageType}} replica-order 12345678 -s DAILY -d dal09 --tier 4 --os-type LINUX
4042
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: 24 additions & 1 deletion
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,14 +60,32 @@ 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
}
6184

6285
if len(partners) == 0 {
6386
cmd.UI.Print(T("There are no replication partners for volume {{.VolumeID}}.\n", subs))
6487
} else {
65-
table := cmd.UI.Table([]string{T("ID"), T("User name"), T("Account ID"), T("Capacity (GB)"), T("Hardware ID"), T("Guest ID"), T("Host ID")})
88+
table := cmd.UI.Table([]string{T("id"), T("username"), T("accountId"), T("capacityGb"), T("hardwareId"), T("guestId"), T("hostId")})
6689
for _, p := range partners {
6790
table.Add(
6891
utils.FormatIntPointer(p.Id),

plugin/commands/block/snapshot_cancel.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ 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+
33+
Cancel existing snapshot space for a given volume.
34+
3335
EXAMPLE:
3436
${COMMAND_NAME} sl {{.storageType}} snapshot-cancel 12345678 --immediate -f
3537
This command cancels snapshot with ID 12345678 immediately without asking for confirmation.`, sl.StorageI18n),

plugin/commands/block/snapshot_create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func NewSnapshotCreateCommand(sl *metadata.SoftlayerStorageCommand) *SnapshotCre
2929
Short: T("Create a snapshot on a given volume"),
3030
Long: T(`${COMMAND_NAME} sl {{.storageType}} snapshot-create VOLUME_ID [OPTIONS]
3131
32+
Creates a snapshot on a given volume.
33+
3234
EXAMPLE:
3335
${COMMAND_NAME} sl {{.storageType}} snapshot-create 12345678 --note snapshotforibmcloud
3436
This command creates a snapshot for volume with ID 12345678 and with addition note as snapshotforibmcloud.`, sl.StorageI18n),

plugin/commands/block/snapshot_disable.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func NewSnapshotDisableCommand(sl *metadata.SoftlayerStorageCommand) *SnapshotDi
2828
Short: T("Disable snapshots on the specified schedule for a given volume"),
2929
Long: T(`${COMMAND_NAME} sl {{.storageType}} snapshot-disable VOLUME_ID [OPTIONS]
3030
31+
Disables snapshots on the specified schedule for a given volume.
32+
3133
EXAMPLE:
3234
${COMMAND_NAME} sl {{.storageType}} snapshot-disable 12345678 -s DAILY
3335
This command disables daily snapshot for volume with ID 12345678.`, sl.StorageI18n),
@@ -36,7 +38,7 @@ EXAMPLE:
3638
return thisCmd.Run(args)
3739
},
3840
}
39-
cobraCmd.Flags().StringVarP(&thisCmd.Schedule_type, "schedule-type", "s", "", T("Snapshot schedule [required], options are: HOURLY,DAILY,WEEKLY"))
41+
cobraCmd.Flags().StringVarP(&thisCmd.Schedule_type, "schedule-type", "s", "", T("Snapshot schedule [required], options are: INTERVAL,HOURLY,DAILY,WEEKLY"))
4042
thisCmd.Command = cobraCmd
4143
return thisCmd
4244
}
@@ -48,11 +50,11 @@ func (cmd *SnapshotDisableCommand) Run(args []string) error {
4850
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
4951
}
5052
if cmd.Schedule_type == "" {
51-
return slErr.NewInvalidUsageError(T("[--schedule-type] is required, options are: HOURLY, DAILY, WEEKLY."))
53+
return slErr.NewInvalidUsageError(T("[--schedule-type] is required, options are: INTERVAL, HOURLY, DAILY, WEEKLY."))
5254
}
5355
scheduleType := cmd.Schedule_type
54-
if scheduleType != "HOURLY" && scheduleType != "DAILY" && scheduleType != "WEEKLY" {
55-
return slErr.NewInvalidUsageError(T("[--schedule-type] must be HOURLY, DAILY, or WEEKLY."))
56+
if scheduleType != "HOURLY" && scheduleType != "DAILY" && scheduleType != "WEEKLY" && scheduleType != "INTERVAL" {
57+
return slErr.NewInvalidUsageError(T("[--schedule-type] must be INTERVAL, HOURLY, DAILY, or WEEKLY."))
5658
}
5759
err = cmd.StorageManager.DisableSnapshots(volumeID, scheduleType)
5860
subs := map[string]interface{}{"ScheduleType": scheduleType, "VolumeID": volumeID}

plugin/managers/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ func (s storageManager) EnableSnapshot(volumeId int, scheduleType string, retent
693693

694694
// Disables snapshots for a specific block volume at a given schedule.
695695
// volumeId: The id of the volume
696-
// scheduleType: 'HOURLY'|'DAILY'|'WEEKLY'
696+
// scheduleType: 'INTERVAL'|'HOURLY'|'DAILY'|'WEEKLY'
697697
func (s storageManager) DisableSnapshots(volumeId int, scheduleType string) error {
698698
_, err := s.StorageService.Id(volumeId).DisableSnapshots(sl.String(scheduleType))
699699
return err

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)