1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-24 13:48:56 +08:00
shirou_gopsutil/disk/disk_aix.go

51 lines
1.4 KiB
Go
Raw Permalink Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2021-12-22 21:54:41 +00:00
//go:build aix
2021-11-09 13:14:54 +00:00
package disk
import (
2021-12-22 21:46:33 +00:00
"context"
"errors"
"strings"
2021-11-09 13:14:54 +00:00
"github.com/shirou/gopsutil/v4/internal/common"
2021-11-09 13:14:54 +00:00
)
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
2021-12-22 21:46:33 +00:00
return nil, common.ErrNotImplementedError
2021-11-09 13:14:54 +00:00
}
func LabelWithContext(ctx context.Context, name string) (string, error) {
2021-12-22 21:46:33 +00:00
return "", common.ErrNotImplementedError
2021-11-09 13:14:54 +00:00
}
// Using lscfg and a device name, we can get the device information
// This is a pure go implementation, and should be moved to disk_aix_nocgo.go
// if a more efficient CGO method is introduced in disk_aix_cgo.go
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
// This isn't linux, these aren't actual disk devices
if strings.HasPrefix(name, "/dev/") {
return "", errors.New("devices on /dev are not physical disks on aix")
}
out, err := invoke.CommandWithContext(ctx, "lscfg", "-vl", name)
if err != nil {
return "", err
}
ret := ""
// Kind of inefficient, but it works
lines := strings.Split(string(out[:]), "\n")
for line := 1; line < len(lines); line++ {
v := strings.TrimSpace(lines[line])
if strings.HasPrefix(v, "Serial Number...............") {
ret = strings.TrimPrefix(v, "Serial Number...............")
if ret == "" {
return "", errors.New("empty serial for disk")
}
return ret, nil
}
}
return ret, errors.New("serial entry not found for disk")
}