mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Add some initial files
This commit is contained in:
parent
04e1fb26c9
commit
7aeb3aa6c5
5 changed files with 141 additions and 0 deletions
58
cmd/pdu-collect.go
Normal file
58
cmd/pdu-collect.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/OpenCHAMI/magellan/pkg/jaws"
|
||||
"github.com/OpenCHAMI/magellan/pkg/pdu"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var pduCollectCmd = &cobra.Command{
|
||||
Use: "collect [hosts...]",
|
||||
Short: "Collect inventory from JAWS-based PDUs",
|
||||
Long: `Connects to one or more PDUs with a JAWS interface to collect hardware inventory.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 0 {
|
||||
log.Error().Msg("no PDU hosts provided")
|
||||
return
|
||||
}
|
||||
|
||||
if username == "" || password == "" {
|
||||
log.Error().Msg("--username and --password are required for PDU collection")
|
||||
return
|
||||
}
|
||||
|
||||
collection := make([]*pdu.PDUInventory, 0)
|
||||
for _, host := range args {
|
||||
log.Info().Msgf("Collecting from PDU: %s", host)
|
||||
config := jaws.CrawlerConfig{
|
||||
URI: host,
|
||||
Username: username,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
inventory, err := jaws.CrawlPDU(config)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("failed to crawl PDU %s", host)
|
||||
continue
|
||||
}
|
||||
collection = append(collection, inventory)
|
||||
}
|
||||
|
||||
output, err := json.MarshalIndent(collection, "", " ")
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("failed to marshal PDU collection to JSON")
|
||||
}
|
||||
fmt.Println(string(output))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
PduCmd.AddCommand(pduCollectCmd)
|
||||
|
||||
pduCollectCmd.Flags().StringVarP(&username, "username", "u", "", "Set the PDU username")
|
||||
pduCollectCmd.Flags().StringVarP(&password, "password", "p", "", "Set the PDU password")
|
||||
}
|
||||
15
cmd/pdu.go
Normal file
15
cmd/pdu.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var PduCmd = &cobra.Command{
|
||||
Use: "pdu",
|
||||
Short: "Perform actions on Power Distribution Units (PDUs)",
|
||||
Long: `A collection of commands to discover and manage PDUs that may not use the Redfish protocol.`,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(PduCmd)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue