Skip to content

Commit

Permalink
Add filter flags for partition capacity command. (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Aug 26, 2021
1 parent 6ca73bb commit f450451
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
36 changes: 35 additions & 1 deletion cmd/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ var (
RunE: func(cmd *cobra.Command, args []string) error {
return partitionList(driver)
},
PreRun: bindPFlags,
}
partitionCapacityCmd = &cobra.Command{
Use: "capacity",
Short: "show partition capacity",
RunE: func(cmd *cobra.Command, args []string) error {
return partitionCapacity(driver)
},
PreRun: bindPFlags,
}
partitionDescribeCmd = &cobra.Command{
Use: "describe <partitionID>",
Expand Down Expand Up @@ -125,6 +127,23 @@ Example:
log.Fatal(err.Error())
}

partitionCapacityCmd.Flags().StringP("id", "", "", "filter on partition id. [optional]")
partitionCapacityCmd.Flags().StringP("size", "", "", "filter on size id. [optional]")
err = partitionCapacityCmd.RegisterFlagCompletionFunc("id", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return partitionListCompletion(driver)
})
if err != nil {
log.Fatal(err.Error())
}
err = partitionCapacityCmd.RegisterFlagCompletionFunc("size", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
sizes, comp := sizeListCompletion(driver)
sizes = append(sizes, "unknown")
return sizes, comp
})
if err != nil {
log.Fatal(err.Error())
}

partitionCmd.AddCommand(partitionListCmd)
partitionCmd.AddCommand(partitionCapacityCmd)
partitionCmd.AddCommand(partitionDescribeCmd)
Expand Down Expand Up @@ -154,13 +173,28 @@ func partitionDescribe(driver *metalgo.Driver, args []string) error {
}
return detailer.Detail(resp.Partition)
}

func partitionCapacity(driver *metalgo.Driver) error {
resp, err := driver.PartitionCapacity()
var (
pcr = metalgo.PartitionCapacityRequest{}
id = viper.GetString("id")
size = viper.GetString("size")
)

if id != "" {
pcr.ID = &id
}
if size != "" {
pcr.Size = &size
}

resp, err := driver.PartitionCapacity(pcr)
if err != nil {
return err
}
return printer.Print(resp.Capacity)
}

func partitionCreate(driver *metalgo.Driver) error {
var icrs []metalgo.PartitionCreateRequest
var icr metalgo.PartitionCreateRequest
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.12.0
github.com/metal-stack/masterdata-api v0.8.8
github.com/metal-stack/metal-go v0.15.5
github.com/metal-stack/metal-go v0.15.6
github.com/metal-stack/metal-lib v0.8.0
github.com/metal-stack/updater v1.1.3
github.com/metal-stack/v v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/metal-stack/masterdata-api v0.8.8 h1:SkKw53K0lEZgH74/h3RfSMpxfb/agmxrId8i51Da0a8=
github.com/metal-stack/masterdata-api v0.8.8/go.mod h1:rpwFGYKHAtoZ/Phi6WQCt4VgswA7lcLambbleqFgMMg=
github.com/metal-stack/metal-go v0.15.5 h1:WrHPzljK8pjx0USvxFsVg8ZvhxNFoVli4zCgdk+1/kU=
github.com/metal-stack/metal-go v0.15.5/go.mod h1:YL8RKVfDR/fINWIQI9U/tuJw3mXEvaKTv617sxBuX6c=
github.com/metal-stack/metal-go v0.15.6 h1:wAMJHaDzXqLF8gkYXsRPUMo82iEV7c69LRG+W3cKD/0=
github.com/metal-stack/metal-go v0.15.6/go.mod h1:YL8RKVfDR/fINWIQI9U/tuJw3mXEvaKTv617sxBuX6c=
github.com/metal-stack/metal-lib v0.8.0 h1:PVV+vWrkorlnSEuIByk/rwFnVO4mmJeLzNAnMZwJ+3Y=
github.com/metal-stack/metal-lib v0.8.0/go.mod h1:eDBJ88yC8jUk+bAJXpF1Upw6j3lbbgv3UIF0D+llMec=
github.com/metal-stack/security v0.5.3/go.mod h1:t7P93F6/iSDR729OS/3x5t69ewBCsHUYqRVaHb5nxjc=
Expand Down

0 comments on commit f450451

Please sign in to comment.