Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for getting drive information #337

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
}
```