-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
202 additions
and
35 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,99 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
sastopo "gitlab.alcf.anl.gov/jlse/sastopo/lib" | ||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
var conf sastopo.Conf | ||
|
||
// discoverCmd represents the discover command | ||
var discoverCmd = &cobra.Command{ | ||
Use: "discover", | ||
Short: "Discover host's SAS Topology", | ||
Long: "Discover host's SAS Topology", | ||
Run: run, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(discoverCmd) | ||
discoverCmd.Flags().BoolVarP(&conf.Summary, "summary", "s", true, "Show summary of SAS devices") | ||
discoverCmd.Flags().BoolVarP(&conf.Mismatch, "mismatch", "m", false, "Show devices with path count mismatch") | ||
discoverCmd.Flags().IntVarP(&conf.PathCount, "pathcount", "p", 2, "Number of expected paths to each SAS device") | ||
discoverCmd.Flags().IntVar(&conf.SysfsMatchPathEncl, "sysfsMatchPathEncl", 8, "Number of sysfs elements expected for a sysfs device") | ||
|
||
} | ||
|
||
func run(cmd *cobra.Command, args []string) { | ||
loadConf() | ||
|
||
devices, multiPathDevices, enclosures, HBAs, err := sastopo.ScsiDevices(conf) | ||
if err != nil { | ||
fmt.Print(err) | ||
} | ||
if conf.Mismatch { | ||
findDevMissingPaths(conf.PathCount, devices) | ||
} | ||
if conf.Summary { | ||
summary(devices, multiPathDevices, enclosures, HBAs) | ||
} | ||
} | ||
|
||
func findDevMissingPaths(count int, devices map[string]*sastopo.Device) { | ||
for _, d := range devices { | ||
if len(d.MultiPath.Paths) != count { | ||
fmt.Printf("Path Count Mismatch: %#v, found %d paths\n", d.Serial, len(d.MultiPath.Paths)) | ||
} | ||
} | ||
} | ||
|
||
func summary(devices map[string]*sastopo.Device, multiPathDevices map[string]*sastopo.MultiPathDevice, enclosures map[*sastopo.Enclosure]bool, HBAs map[string]*sastopo.HBA) { | ||
|
||
fmt.Printf("Found %d SAS Devices\n", len(devices)) | ||
//for _, device := range devices { | ||
// fmt.Printf("Found Device: %p\n", device.Enclosure) | ||
//} | ||
fmt.Printf("Found %d Unique Multi-pathed SAS Devices\n", len(multiPathDevices)) | ||
for hba := range HBAs { | ||
fmt.Printf("Found HBA: %s, Slot: %s, Host: %s\n", HBAs[hba].PciID, HBAs[hba].Slot, HBAs[hba].Host) | ||
} | ||
|
||
fmt.Printf("Found %d Enclosures\n", len(enclosures)) | ||
for enclosure := range enclosures { | ||
fmt.Printf("Found Enclosure: %p with %d slots populated\n", enclosure, len(enclosure.Slots)) | ||
for path := range enclosure.MultiPathDevice.Paths { | ||
fmt.Printf("HBA: %s, Slot %s, Port: %s\n", path.HBA.PciID, path.HBA.Slot, path.Port) | ||
} | ||
//for slot := range enclosure.Slots { | ||
// fmt.Printf("%s\n", slot) | ||
//} | ||
} | ||
} | ||
|
||
func loadConf() { | ||
|
||
var data = []byte(` | ||
# Labels of PCI bus addresses to Slot ID | ||
HBALabels: | ||
"0000:11:00.0": 'C3' | ||
"0000:8b:00.0": 'C5' | ||
"0000:90:00.0": 'C6' | ||
EnclLabels: | ||
"0000:11:00.0": | ||
"0000:8b:00.0": | ||
"0000:90:00.0": | ||
`) | ||
|
||
err := yaml.Unmarshal(data, &conf) | ||
if err != nil { | ||
log.Fatalf("error: %v", err) | ||
} | ||
|
||
} |
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,64 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var cfgFile string | ||
|
||
// RootCmd represents the base command when called without any subcommands | ||
var RootCmd = &cobra.Command{ | ||
Use: "sastopo", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
examples and usage of using your application. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
} | ||
|
||
// Execute adds all child commands to the root command sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
if err := RootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(-1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
|
||
// Here you will define your flags and configuration settings. | ||
// Cobra supports Persistent Flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.sastopo.yaml)") | ||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} | ||
|
||
// initConfig reads in config file and ENV variables if set. | ||
func initConfig() { | ||
if cfgFile != "" { // enable ability to specify config file via flag | ||
viper.SetConfigFile(cfgFile) | ||
} | ||
|
||
viper.SetConfigName(".sastopo") // name of config file (without extension) | ||
viper.AddConfigPath("$HOME") // adding home directory as first search path | ||
viper.AutomaticEnv() // read in environment variables that match | ||
|
||
// If a config file is found, read it in. | ||
if err := viper.ReadInConfig(); err == nil { | ||
fmt.Println("Using config file:", viper.ConfigFileUsed()) | ||
} | ||
} |
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,11 @@ | ||
package sastopo | ||
|
||
// Conf is a struct used for parsing the yaml configure file | ||
type Conf struct { | ||
Mismatch bool | ||
PathCount int | ||
SysfsMatchPathEncl int | ||
Summary bool | ||
HBALabels map[string]string `yaml:"HBALabels"` | ||
EnclLabels map[string]map[string]string `yaml:"EnclLabels"` | ||
} |
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
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
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
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