refactor: updated PrintDrives() implementation

This commit is contained in:
David Allen 2025-06-20 14:16:20 -06:00
parent 8fd48f0d13
commit 3a825f1239
Signed by: towk
GPG key ID: 0430CDBE22619155

View file

@ -72,14 +72,31 @@ func ListDrives(cc *crawler.CrawlerConfig) ([]*redfish.Drive, error) {
return foundDrives, nil return foundDrives, nil
} }
func PrintDrives(drives []*redfish.Drive) { func PrintDrives(drives []*redfish.Drive, format string) {
switch format {
case "json":
util.PrintJSON(drives)
case "yaml":
util.PrintYAML(drives)
case "list":
for i, drive := range drives { for i, drive := range drives {
fmt.Printf("Drive %d\n", i) fmt.Printf(`
fmt.Printf("\tManufacturer: %s\n", drive.Manufacturer) Drive %d
fmt.Printf("\tModel: %s\n", drive.Model) \tManufacturuer: %s
fmt.Printf("\tSize: %d GiB\n", (drive.CapacityBytes / 1024 / 1024 / 1024)) \tModel: %s
fmt.Printf("\tSerial number: %s\n", drive.SerialNumber) \tSize: %d GiB
fmt.Printf("\tPart number: %s\n", drive.PartNumber) \tSerial Number: %s
fmt.Printf("\tLocation: %s %d\n", drive.PhysicalLocation.PartLocation.LocationType, drive.PhysicalLocation.PartLocation.LocationOrdinalValue) \tPart Number: %s
\tLocation: %s,%s
`, i,
drive.Manufacturer,
drive.Model,
(drive.CapacityBytes / 1024 / 1024 / 1024),
drive.SerialNumber,
drive.PartNumber,
drive.PhysicalLocation.PartLocation.LocationType,
drive.PhysicalLocation.PartLocation.LocationOrdinalValue,
)
}
} }
} }