|
| 1 | +// |
| 2 | +// SPDX-License-Identifier: BSD-3-Clause |
| 3 | +// |
| 4 | + |
| 5 | +package smc |
| 6 | + |
| 7 | +import ( |
| 8 | + "encoding/json" |
| 9 | + "errors" |
| 10 | + |
| 11 | + "github.com/stmcginnis/gofish/common" |
| 12 | +) |
| 13 | + |
| 14 | +// Dump represents a dump from the DumpService. |
| 15 | +// NOTE: This is another one where the jsonschema reported by SMC appears to be |
| 16 | +// wildly inaccurate. Use with caution. |
| 17 | +type Dump struct { |
| 18 | + common.Entity |
| 19 | + |
| 20 | + AttestationFile []string |
| 21 | +} |
| 22 | + |
| 23 | +// GetDump will get a Dump instance from the service. |
| 24 | +func GetDump(c common.Client, uri string) (*Dump, error) { |
| 25 | + return common.GetObject[Dump](c, uri) |
| 26 | +} |
| 27 | + |
| 28 | +// ListReferencedDumps gets the collection of Dumps from |
| 29 | +// a provided reference. |
| 30 | +func ListReferencedDumps(c common.Client, uri string) ([]*Dump, error) { |
| 31 | + return common.GetCollectionObjects[Dump](c, uri) |
| 32 | +} |
| 33 | + |
| 34 | +// DumpService is the dump service instance associated with the system. |
| 35 | +type DumpService struct { |
| 36 | + common.Entity |
| 37 | + |
| 38 | + // Link to a DumpCollection. |
| 39 | + dumps string |
| 40 | + |
| 41 | + createDumpTarget string |
| 42 | + deleteAllTarget string |
| 43 | + collectTarget string |
| 44 | +} |
| 45 | + |
| 46 | +// UnmarshalJSON unmarshals an DumpService object from the raw JSON. |
| 47 | +func (ds *DumpService) UnmarshalJSON(b []byte) error { |
| 48 | + type temp DumpService |
| 49 | + var t struct { |
| 50 | + temp |
| 51 | + Dumps common.Link |
| 52 | + Actions struct { |
| 53 | + CreateDump common.ActionTarget `json:"#SmcDumpService.CreateDump"` |
| 54 | + DeleteAll common.ActionTarget `json:"#SmcDumpService.DeleteAll"` |
| 55 | + Collect common.ActionTarget `json:"#OemDumpService.Collect"` |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + err := json.Unmarshal(b, &t) |
| 60 | + if err != nil { |
| 61 | + return err |
| 62 | + } |
| 63 | + |
| 64 | + *ds = DumpService(t.temp) |
| 65 | + |
| 66 | + ds.dumps = t.Dumps.String() |
| 67 | + |
| 68 | + ds.createDumpTarget = t.Actions.CreateDump.Target |
| 69 | + ds.deleteAllTarget = t.Actions.DeleteAll.Target |
| 70 | + ds.collectTarget = t.Actions.Collect.Target |
| 71 | + |
| 72 | + return nil |
| 73 | +} |
| 74 | + |
| 75 | +// GetDefaultDumpService will get the default DumpService instance from the service. |
| 76 | +func GetDefaultDumpService(c common.Client) (*DumpService, error) { |
| 77 | + return common.GetObject[DumpService](c, "/redfish/v1/Oem/Supermicro/DumpService/") |
| 78 | +} |
| 79 | + |
| 80 | +// GetDumpService will get a DumpService instance from the service. |
| 81 | +func GetDumpService(c common.Client, uri string) (*DumpService, error) { |
| 82 | + return common.GetObject[DumpService](c, uri) |
| 83 | +} |
| 84 | + |
| 85 | +// CreateDump creates a new dump. Allowable dumpType is usually only |
| 86 | +// "Host Dump". |
| 87 | +func (ds *DumpService) CreateDump(dumpType string) error { |
| 88 | + if ds.createDumpTarget == "" { |
| 89 | + return errors.New("create dump is not supported by this system") |
| 90 | + } |
| 91 | + |
| 92 | + return ds.Post(ds.createDumpTarget, map[string]any{ |
| 93 | + "DumpType": dumpType, |
| 94 | + }) |
| 95 | +} |
| 96 | + |
| 97 | +// DeleteAll deletes all dumps. |
| 98 | +func (ds *DumpService) DeleteAll() error { |
| 99 | + if ds.deleteAllTarget == "" { |
| 100 | + return errors.New("delete all is not supported by this system") |
| 101 | + } |
| 102 | + |
| 103 | + return ds.Post(ds.deleteAllTarget, nil) |
| 104 | +} |
| 105 | + |
| 106 | +// Collect collects a dump. |
| 107 | +// dumptType is usually only "HGXLogDump". |
| 108 | +// actionType is usually one of "Create", "Delete", "Download", or "Query". |
| 109 | +func (ds *DumpService) Collect(dumpType, actionType string) error { |
| 110 | + if ds.collectTarget == "" { |
| 111 | + return errors.New("collect is not supported by this system") |
| 112 | + } |
| 113 | + |
| 114 | + return ds.Post(ds.collectTarget, map[string]any{ |
| 115 | + "DumpType": dumpType, |
| 116 | + "ActionType": actionType, |
| 117 | + }) |
| 118 | +} |
| 119 | + |
| 120 | +// Dumps will get the Dumps from the service. |
| 121 | +func (ds *DumpService) Dumps() ([]*Dump, error) { |
| 122 | + return ListReferencedDumps(ds.GetClient(), ds.dumps) |
| 123 | +} |
0 commit comments