/
storagesystem.go
64 lines (53 loc) · 1.41 KB
/
storagesystem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// SPDX-License-Identifier: BSD-3-Clause
//
package swordfish
import (
"github.com/stmcginnis/gofish/common"
"github.com/stmcginnis/gofish/redfish"
)
// StorageSystem is a Swordfish storage system instance.
type StorageSystem struct {
redfish.ComputerSystem
}
// GetStorageSystem will get a StorageSystem instance from the Swordfish service.
func GetStorageSystem(c common.Client, uri string) (*StorageSystem, error) {
var storageSystem StorageSystem
return &storageSystem, storageSystem.Get(c, uri, &storageSystem)
}
// ListReferencedStorageSystems gets the collection of StorageSystems.
func ListReferencedStorageSystems(c common.Client, link string) ([]*StorageSystem, error) { //nolint:dupl
var result []*StorageSystem
if link == "" {
return result, nil
}
type GetResult struct {
Item *StorageSystem
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
storagesystem, err := GetStorageSystem(c, link)
ch <- GetResult{Item: storagesystem, Link: link, Error: err}
}
go func() {
err := common.CollectList(get, c, link)
if err != nil {
collectionError.Failures[link] = err
}
close(ch)
}()
for r := range ch {
if r.Error != nil {
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}