-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathfirmware.go
195 lines (159 loc) · 5.83 KB
/
firmware.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
// (C) Copyright 2020-2022 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package main
import (
"io"
"strings"
"github.com/daos-stack/daos/src/control/cmd/dmg/pretty"
"github.com/daos-stack/daos/src/control/common/cmdutil"
"github.com/daos-stack/daos/src/control/lib/control"
)
// firmwareOption defines a DMG option that enables firmware management in DAOS.
type firmwareOption struct {
Firmware firmwareCmd `command:"firmware" hidden:"true" description:"Manage the storage device firmware"`
}
// firmwareCmd defines the firmware management subcommands.
type firmwareCmd struct {
Query firmwareQueryCmd `command:"query" description:"Query device firmware versions and status on DAOS storage nodes"`
Update firmwareUpdateCmd `command:"update" description:"Update the device firmware on DAOS storage nodes"`
}
// firmwareQueryCmd is used to query the storage device firmware on a set of DAOS hosts.
type firmwareQueryCmd struct {
baseCmd
ctlInvokerCmd
hostListCmd
cmdutil.JSONOutputCmd
DeviceType string `short:"t" long:"type" choice:"nvme" choice:"scm" choice:"all" default:"all" description:"Type of storage devices to query"`
Devices string `short:"d" long:"devices" description:"Comma-separated list of device identifiers to query"`
ModelID string `short:"m" long:"model" description:"Model ID to filter results by"`
FirmwareRev string `short:"f" long:"fwrev" description:"Firmware revision to filter results by"`
Verbose bool `short:"v" long:"verbose" description:"Display verbose output"`
}
// Execute runs the firmware query command.
func (cmd *firmwareQueryCmd) Execute(args []string) error {
ctx := cmd.MustLogCtx()
req := &control.FirmwareQueryReq{
SCM: cmd.isSCMRequested(),
NVMe: cmd.isNVMeRequested(),
ModelID: cmd.ModelID,
FirmwareRev: cmd.FirmwareRev,
}
if cmd.Devices != "" {
req.Devices = strings.Split(cmd.Devices, ",")
}
req.SetHostList(cmd.getHostList())
resp, err := control.FirmwareQuery(ctx, cmd.ctlInvoker, req)
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
}
if err != nil {
return err
}
var bld strings.Builder
if err := pretty.PrintResponseErrors(resp, &bld); err != nil {
return err
}
printSCMFirmware, printNVMeFirmware := cmd.getDisplayFunctions()
if cmd.isSCMRequested() {
if err := printSCMFirmware(resp.HostSCMFirmware, &bld); err != nil {
return err
}
}
if cmd.isNVMeRequested() {
if err := printNVMeFirmware(resp.HostNVMeFirmware, &bld); err != nil {
return err
}
}
cmd.Info(bld.String())
return resp.Errors()
}
func (cmd *firmwareQueryCmd) isSCMRequested() bool {
return cmd.DeviceType == "scm" || cmd.DeviceType == "all"
}
func (cmd *firmwareQueryCmd) isNVMeRequested() bool {
return cmd.DeviceType == "nvme" || cmd.DeviceType == "all"
}
type (
hostSCMQueryMapPrinter func(control.HostSCMQueryMap, io.Writer, ...pretty.PrintConfigOption) error
hostNVMeQueryMapPrinter func(control.HostNVMeQueryMap, io.Writer, ...pretty.PrintConfigOption) error
)
func (cmd *firmwareQueryCmd) getDisplayFunctions() (hostSCMQueryMapPrinter, hostNVMeQueryMapPrinter) {
printSCM := pretty.PrintSCMFirmwareQueryMap
printNVMe := pretty.PrintNVMeFirmwareQueryMap
if cmd.Verbose {
printSCM = pretty.PrintSCMFirmwareQueryMapVerbose
printNVMe = pretty.PrintNVMeFirmwareQueryMapVerbose
}
return printSCM, printNVMe
}
// firmwareUpdateCmd updates the firmware on storage devices on a set of DAOS hosts.
type firmwareUpdateCmd struct {
baseCmd
ctlInvokerCmd
hostListCmd
cmdutil.JSONOutputCmd
DeviceType string `short:"t" long:"type" choice:"nvme" choice:"scm" required:"1" description:"Type of storage devices to update"`
FilePath string `short:"p" long:"path" required:"1" description:"Path to the firmware file accessible from all nodes"`
Devices string `short:"d" long:"devices" description:"Comma-separated list of device identifiers to update"`
ModelID string `short:"m" long:"model" description:"Limit update to a model ID"`
FirmwareRev string `short:"f" long:"fwrev" description:"Limit update to a current firmware revision"`
Verbose bool `short:"v" long:"verbose" description:"Display verbose output"`
}
// Execute runs the firmware update command.
func (cmd *firmwareUpdateCmd) Execute(args []string) error {
ctx := cmd.MustLogCtx()
req := &control.FirmwareUpdateReq{
FirmwarePath: cmd.FilePath,
ModelID: cmd.ModelID,
FirmwareRev: cmd.FirmwareRev,
}
if cmd.isSCMUpdate() {
req.Type = control.DeviceTypeSCM
} else {
req.Type = control.DeviceTypeNVMe
}
if cmd.Devices != "" {
req.Devices = strings.Split(cmd.Devices, ",")
}
req.SetHostList(cmd.getHostList())
resp, err := control.FirmwareUpdate(ctx, cmd.ctlInvoker, req)
if cmd.JSONOutputEnabled() {
return cmd.OutputJSON(resp, err)
}
if err != nil {
return err
}
var bld strings.Builder
if err := pretty.PrintResponseErrors(resp, &bld); err != nil {
return err
}
if err := cmd.printUpdateResult(resp, &bld); err != nil {
return err
}
cmd.Info(bld.String())
return resp.Errors()
}
func (cmd *firmwareUpdateCmd) isSCMUpdate() bool {
return cmd.DeviceType == "scm"
}
func (cmd *firmwareUpdateCmd) printUpdateResult(resp *control.FirmwareUpdateResp, out io.Writer) error {
if cmd.isSCMUpdate() {
return cmd.printSCMUpdateResult(resp, out)
}
return cmd.printNVMeUpdateResult(resp, out)
}
func (cmd *firmwareUpdateCmd) printSCMUpdateResult(resp *control.FirmwareUpdateResp, out io.Writer) error {
if cmd.Verbose {
return pretty.PrintSCMFirmwareUpdateMapVerbose(resp.HostSCMResult, out)
}
return pretty.PrintSCMFirmwareUpdateMap(resp.HostSCMResult, out)
}
func (cmd *firmwareUpdateCmd) printNVMeUpdateResult(resp *control.FirmwareUpdateResp, out io.Writer) error {
if cmd.Verbose {
return pretty.PrintNVMeFirmwareUpdateMapVerbose(resp.HostNVMeResult, out)
}
return pretty.PrintNVMeFirmwareUpdateMap(resp.HostNVMeResult, out)
}