-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new subcommand for printing out processor information.
- Loading branch information
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
MIT License | ||
(C) Copyright 2023-2024 Hewlett Packard Enterprise Development LP | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package proc | ||
|
||
// Processors represents a list of Processor types. | ||
type Processors []Processor | ||
|
||
// Processor represents a single, physical processor. | ||
// The processor's model number is stored in either Processor.Model or Processor.VendorID depending | ||
// on the vendor. The user may need to interpret both fields to understand what they have. | ||
type Processor struct { | ||
Architecture string `json:"architecture" yaml:"architecture"` | ||
TotalCores int `json:"totalCores" yaml:"total_cores"` | ||
Model string `json:"model" yaml:"model"` | ||
Socket string `json:"socket" yaml:"socket"` | ||
Threads int `json:"threads" yaml:"threads"` | ||
VendorID string `json:"vendorID" yaml:"vendor_id"` | ||
Error error `json:"error,omitempty" yaml:"error,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
MIT License | ||
(C) Copyright 2023-2024 Hewlett Packard Enterprise Development LP | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package proc | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Cray-HPE/gru/internal/query" | ||
"github.com/Cray-HPE/gru/pkg/auth" | ||
"github.com/Cray-HPE/gru/pkg/cmd/cli" | ||
"github.com/spf13/cobra" | ||
"strings" | ||
) | ||
|
||
// NewShowCommand creates the `system` subcommand for `show`. | ||
func NewShowCommand() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "proc host [...host]", | ||
Short: "Processor information", | ||
Long: `Show the Server's processors, a full list with their core count, model, architecture, and serial numbers.`, | ||
Run: func(c *cobra.Command, args []string) { | ||
hosts := cli.ParseHosts(args) | ||
content := query.Async(getProcessors, hosts) | ||
cli.PrettyPrint(content) | ||
}, | ||
} | ||
return c | ||
} | ||
|
||
func getProcessors(host string) interface{} { | ||
foundProcessors := Processors{} | ||
c, err := auth.Connection(host) | ||
if err != nil { | ||
foundProcessors = append( | ||
foundProcessors, Processor{ | ||
Error: err, | ||
}, | ||
) | ||
return foundProcessors | ||
} | ||
defer c.Logout() | ||
service := c.Service | ||
|
||
managers, err := service.Managers() | ||
if err != nil || len(managers) < 1 { | ||
foundProcessors = append( | ||
foundProcessors, Processor{ | ||
Error: err, | ||
}, | ||
) | ||
return foundProcessors | ||
} | ||
|
||
systems, err := service.Systems() | ||
if err != nil || len(systems) < 1 { | ||
foundProcessors = append( | ||
foundProcessors, Processor{ | ||
Error: err, | ||
}, | ||
) | ||
return foundProcessors | ||
} | ||
systemProcessors, err := systems[0].Processors() | ||
if err != nil { | ||
foundProcessors = append( | ||
foundProcessors, Processor{ | ||
Error: err, | ||
}, | ||
) | ||
} else { | ||
for i := range systemProcessors { | ||
processor := Processor{ | ||
Architecture: strings.TrimSpace(fmt.Sprintf("%v", systemProcessors[i].ProcessorArchitecture)), | ||
TotalCores: systemProcessors[i].TotalCores, | ||
Model: strings.TrimSpace(systemProcessors[i].Model), | ||
Socket: strings.TrimSpace(systemProcessors[i].Socket), | ||
Threads: systemProcessors[i].TotalThreads, | ||
VendorID: strings.TrimSpace(systemProcessors[i].ProcessorID.VendorID), | ||
} | ||
foundProcessors = append(foundProcessors, processor) | ||
} | ||
} | ||
return foundProcessors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters