Skip to content

Commit f08b94d

Browse files
Adding volume username lookups to block and file commands. #722
1 parent 2a34a5b commit f08b94d

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

plugin/commands/block/block.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
1212
StorageCommand := &metadata.SoftlayerStorageCommand{
1313
SoftlayerCommand: sl,
1414
StorageI18n: map[string]interface{}{"storageType": "block"},
15+
StorageType: "block",
1516
}
1617
cobraCmd := &cobra.Command{
1718
Use: "block",

plugin/commands/block/volume_detail.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,19 @@ func (cmd *VolumeDetailCommand) Run(args []string) error {
4545

4646
volumeID, err := strconv.Atoi(args[0])
4747
if err != nil {
48-
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
48+
// Maybe this is a volume username
49+
volumes, err := cmd.StorageManager.ListVolumes(cmd.StorageType, "", args[0], "", "", 0, "mask[id,username]")
50+
if err != nil {
51+
fmt.Printf("=============== ERROR: %s\n", err.Error())
52+
return slErr.NewInvalidSoftlayerIdInputError("Volume ID")
53+
}
54+
if len(volumes) != 1 {
55+
subs := map[string]interface{}{"VolumeName": args[0], "VolumeCount": len(volumes)}
56+
return slErr.New(
57+
T("Search for volume {{.VolumeName}} found {{.VolumeCount}} volumes, expected 1.", subs),
58+
)
59+
}
60+
volumeID = *volumes[0].Id
4961
}
5062

5163
outputFormat := cmd.GetOutputFlag()

plugin/commands/file/file.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
2121
StorageCommand := &metadata.SoftlayerStorageCommand{
2222
SoftlayerCommand: sl,
2323
StorageI18n: map[string]interface{}{"storageType": "file"},
24+
StorageType: "file",
2425
}
2526
cobraCmd := &cobra.Command{
2627
Use: "file",

0 commit comments

Comments
 (0)