Skip to content

Commit

Permalink
Add example for getting drive information
Browse files Browse the repository at this point in the history
Signed-off-by: Sean McGinnis <[email protected]>
  • Loading branch information
stmcginnis committed May 16, 2024
1 parent 2062c26 commit 177e80f
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions examples/list_drives.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# List Drives

This is an example of listing information about the drives in a system.

```go
//
// SPDX-License-Identifier: BSD-3-Clause
//
package main

import (
"fmt"

"github.com/stmcginnis/gofish"
)

func main() {
// Create a new instance of gofish client, ignoring self-signed certs
config := gofish.ClientConfig{
Endpoint: "https://bmc-ip",
Username: "my-username",
Password: "my-password",
Insecure: true,
}
c, err := gofish.Connect(config)
if err != nil {
panic(err)
}
defer c.Logout()

// Retrieve the service root
service := c.Service

systems, err := service.Systems()
if err != nil {
panic(err)
}

for _, system := range systems {
storage, err := system.Storage()
if err != nil {
continue
}

for _, ss := range storage {
drives, err := ss.Drives()
if err != nil {
continue
}

for i, drive := range drives {
fmt.Printf("Drive %d\n", i)
fmt.Printf("\tManufacturer: %s\n", drive.Manufacturer)
fmt.Printf("\tModel: %s\n", drive.Model)
fmt.Printf("\tSize: %d GiB\n", (drive.CapacityBytes / 1024 / 1024 / 1024))
fmt.Printf("\tSerial number: %s\n", drive.SerialNumber)
fmt.Printf("\tPart number: %s\n", drive.PartNumber)
fmt.Printf("\tLocation: %s %d\n", drive.PhysicalLocation.PartLocation.LocationType, drive.PhysicalLocation.PartLocation.LocationOrdinalValue)
}
}
}
}
```

0 comments on commit 177e80f

Please sign in to comment.