Skip to content

Commit

Permalink
Print lexeme and token for decoder
Browse files Browse the repository at this point in the history
When a decoder is used, print the decoded string (token) and the lexeme (pattern) used. This unmasks the necessary attribute name for `bios set`.

```json
{
  "drax-ncn-m001-mgmt.hpc.amslabs.hpecorp.net": {
    "attributes": {
      "PCIS007 (SR-IOV Support)": "Enabled",
      "Rome0039 (Local APIC Mode)": "Auto",
      "Rome0059 (SMT Control)": "Auto",
      "Rome0162 (IOMMU)": "Enabled",
      "Rome0565 (SVM Mode)": "Enabled"
    }
  },
  "redbull-ncn-m001-mgmt.hpc.amslabs.hpecorp.net": {
    "attributes": {
      "ProcessorVmxEnable": 1,
      "ProcessorX2apic": 1,
      "SRIOVEnable": 1,
      "VTdSupport": 1
    }
  }
}
```
```bash
Asynchronously querying [    2] hosts ...
drax-ncn-m001-mgmt.hpc.amslabs.hpecorp.net:
        PCIS007 (SR-IOV Support)                : Enabled
        Rome0039 (Local APIC Mode)              : Auto
        Rome0059 (SMT Control)                  : Auto
        Rome0162 (IOMMU)                        : Enabled
        Rome0565 (SVM Mode)                     : Enabled
redbull-ncn-m001-mgmt.hpc.amslabs.hpecorp.net:
        ProcessorVmxEnable                      : 1
        ProcessorX2apic                         : 1
        SRIOVEnable                             : 1
        VTdSupport                              : 1
```
  • Loading branch information
rustydb committed Jan 20, 2024
1 parent 8d9b484 commit d020597
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
12 changes: 2 additions & 10 deletions pkg/cmd/cli/bios/amd/epyc/rome/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (
"os"
"path"
"strings"

"github.com/spf13/viper"
)

//go:embed *.json
Expand Down Expand Up @@ -131,14 +129,8 @@ func (l *Library) RegisterAttribute(attribute Attribute) error {

// Decode accepts a key and changes it to a friendly name if it exists and json is not requested
func (d DecoderMap) Decode(key string) string {
romeAttr, exists := d.Map.Attributes[key]
if exists {
// convert to a friendly name for non-json
if viper.GetBool("json") {
key = strings.TrimLeft(romeAttr.DisplayName, " ")
} else {
key = fmt.Sprintf("%s (%s)", romeAttr.AttributeName, strings.TrimLeft(romeAttr.DisplayName, " "))
}
if romeAttr, exists := d.Map.Attributes[key]; exists {
key = fmt.Sprintf("%s (%s)", romeAttr.AttributeName, strings.TrimLeft(romeAttr.DisplayName, " "))
}
return key
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/bios/collections/virtualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func VirtualizationAttributes(enable bool, manufacturer string) (settings redfis
} else {
settings = IntelDisableVirtualization
}
case "GIGABYTE":
case "GIGABYTE", "CRAY INC.":
if enable {
settings = GigabyteEnableVirtualization
} else {
Expand Down
27 changes: 20 additions & 7 deletions pkg/cmd/cli/bios/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,18 @@ func getBiosAttributes(host string) interface{} {

attributes.Attributes = redfish.SettingsAttributes{}

var decodedAttribute string

// Loop through requestedAttributes if defined, otherwise loop through all.
if len(requestedAttributes) != 0 {
// check each requested attribute

for _, attribute := range requestedAttributes {

if biosDecoder != nil {
attribute = biosDecoder.Decode(attribute)
decodedAttribute = biosDecoder.Decode(attribute)
}
if v, exists := bios.Attributes[attribute]; exists {
attributes.Attributes[attribute] = v
attributes = updateAttributeMap(attributes, attribute, v, decodedAttribute)
} else {
attributes.Attributes[attribute] = nil
}
Expand All @@ -150,17 +154,26 @@ func getBiosAttributes(host string) interface{} {
} else {

for k, v := range bios.Attributes {

if biosDecoder != nil {
k = biosDecoder.Decode(k)
attributes.Attributes[k] = v
} else {
attributes.Attributes[k] = v
decodedAttribute = biosDecoder.Decode(k)
}

attributes = updateAttributeMap(attributes, k, v, decodedAttribute)
}
}
return attributes
}

func updateAttributeMap(attributes Attributes, attribute string, value any, decodedAttribute string) Attributes {
if decodedAttribute != "" {
attributes.Attributes[decodedAttribute] = value
} else {
attributes.Attributes[attribute] = value
}
return attributes
}

// getPendingBiosAttributes gets the staged bios attributes from Bios/Settings
func getPendingBiosAttributes(host string) Attributes {
attributes := Attributes{}
Expand Down

0 comments on commit d020597

Please sign in to comment.