mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
add a mock flag for running on system without a PDU
This commit is contained in:
parent
ae26dac328
commit
28231c6912
1 changed files with 48 additions and 0 deletions
|
|
@ -10,6 +10,8 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var mock bool
|
||||||
|
|
||||||
func transformToSMDFormat(inventory *pdu.PDUInventory) []map[string]any {
|
func transformToSMDFormat(inventory *pdu.PDUInventory) []map[string]any {
|
||||||
smdRecords := make([]map[string]any, 0)
|
smdRecords := make([]map[string]any, 0)
|
||||||
|
|
||||||
|
|
@ -53,6 +55,51 @@ var pduCollectCmd = &cobra.Command{
|
||||||
Short: "Collect inventory from JAWS-based PDUs",
|
Short: "Collect inventory from JAWS-based PDUs",
|
||||||
Long: `Connects to one or more PDUs with a JAWS interface to collect hardware inventory.`,
|
Long: `Connects to one or more PDUs with a JAWS interface to collect hardware inventory.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if mock {
|
||||||
|
log.Info().Msg("Running in --mock mode. Generating hardcoded PDU payload to standard output.")
|
||||||
|
|
||||||
|
type PDUInventoryForSMD struct {
|
||||||
|
Model string `json:"Model"`
|
||||||
|
SerialNumber string `json:"SerialNumber"`
|
||||||
|
FirmwareVersion string `json:"FirmwareVersion"`
|
||||||
|
Outlets []any `json:"Outlets"`
|
||||||
|
}
|
||||||
|
type PayloadForSMD struct {
|
||||||
|
ID string `json:"ID"`
|
||||||
|
Type string `json:"Type"`
|
||||||
|
FQDN string `json:"FQDN"`
|
||||||
|
Hostname string `json:"Hostname"`
|
||||||
|
Enabled bool `json:"Enabled"`
|
||||||
|
RediscoverOnUpdate bool `json:"RediscoverOnUpdate"`
|
||||||
|
PDUInventory PDUInventoryForSMD `json:"PDUInventory"`
|
||||||
|
}
|
||||||
|
|
||||||
|
mockPayload := PayloadForSMD{
|
||||||
|
ID: "x9999m0",
|
||||||
|
Type: "CabinetPDUController",
|
||||||
|
FQDN: "x9999m0-rts.mock:8083",
|
||||||
|
Hostname: "x9999m0-rts.mock:8083",
|
||||||
|
Enabled: true,
|
||||||
|
RediscoverOnUpdate: false,
|
||||||
|
PDUInventory: PDUInventoryForSMD{
|
||||||
|
Model: "MOCK-PRO2",
|
||||||
|
SerialNumber: "MOCK-SN-12345",
|
||||||
|
FirmwareVersion: "v9.9z",
|
||||||
|
Outlets: []any{
|
||||||
|
map[string]string{"id": "ZA01", "name": "Mock_Server_01", "state": "On", "socket_type": "Cx"},
|
||||||
|
map[string]string{"id": "ZA02", "name": "Mock_Server_02", "state": "Off", "socket_type": "Cx"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonData, err := json.MarshalIndent(mockPayload, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("Failed to marshal mock payload")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(jsonData))
|
||||||
|
return
|
||||||
|
}
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
log.Error().Msg("no PDU hosts provided")
|
log.Error().Msg("no PDU hosts provided")
|
||||||
return
|
return
|
||||||
|
|
@ -98,4 +145,5 @@ func init() {
|
||||||
|
|
||||||
pduCollectCmd.Flags().StringVarP(&username, "username", "u", "", "Set the PDU username")
|
pduCollectCmd.Flags().StringVarP(&username, "username", "u", "", "Set the PDU username")
|
||||||
pduCollectCmd.Flags().StringVarP(&password, "password", "p", "", "Set the PDU password")
|
pduCollectCmd.Flags().StringVarP(&password, "password", "p", "", "Set the PDU password")
|
||||||
|
pduCollectCmd.Flags().BoolVar(&mock, "mock", false, "Run in mock mode, sending hardcoded data to SMD")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue