mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
refactor: added optional secrets file parameter and lookup in collect
This commit is contained in:
parent
9396de11c2
commit
f9059c50a1
1 changed files with 39 additions and 16 deletions
|
|
@ -41,6 +41,7 @@ type CollectParams struct {
|
||||||
OutputPath string // set the path to save output with 'output' flag
|
OutputPath string // set the path to save output with 'output' flag
|
||||||
ForceUpdate bool // set whether to force updating SMD with 'force-update' flag
|
ForceUpdate bool // set whether to force updating SMD with 'force-update' flag
|
||||||
AccessToken string // set the access token to include in request with 'access-token' flag
|
AccessToken string // set the access token to include in request with 'access-token' flag
|
||||||
|
SecretsFile string // set the path to secrets file
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the main function used to collect information from the BMC nodes via Redfish.
|
// This is the main function used to collect information from the BMC nodes via Redfish.
|
||||||
|
|
@ -60,15 +61,18 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
|
||||||
|
|
||||||
// collect bmc information asynchronously
|
// collect bmc information asynchronously
|
||||||
var (
|
var (
|
||||||
offset = 0
|
offset = 0
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
collection = make([]map[string]any, 0)
|
collection = make([]map[string]any, 0)
|
||||||
found = make([]string, 0, len(*assets))
|
found = make([]string, 0, len(*assets))
|
||||||
done = make(chan struct{}, params.Concurrency+1)
|
done = make(chan struct{}, params.Concurrency+1)
|
||||||
chanAssets = make(chan RemoteAsset, params.Concurrency+1)
|
chanAssets = make(chan RemoteAsset, params.Concurrency+1)
|
||||||
outputPath = path.Clean(params.OutputPath)
|
outputPath = path.Clean(params.OutputPath)
|
||||||
smdClient = &client.SmdClient{Client: &http.Client{}}
|
smdClient = &client.SmdClient{Client: &http.Client{}}
|
||||||
|
initialStore secrets.SecretStore = store
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
// set the client's params from CLI
|
// set the client's params from CLI
|
||||||
// NOTE: temporary solution until client.NewClient() is fixed
|
// NOTE: temporary solution until client.NewClient() is fixed
|
||||||
smdClient.URI = params.URI
|
smdClient.URI = params.URI
|
||||||
|
|
@ -103,27 +107,46 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use initial store to check for creds for specific node
|
||||||
|
store = initialStore
|
||||||
|
|
||||||
// generate custom xnames for bmcs
|
// generate custom xnames for bmcs
|
||||||
// TODO: add xname customization via CLI
|
// TODO: add xname customization via CLI
|
||||||
node := xnames.Node{
|
var (
|
||||||
Cabinet: 1000,
|
uri = fmt.Sprintf("%s:%d", sr.Host, sr.Port)
|
||||||
Chassis: 1,
|
node = xnames.Node{
|
||||||
ComputeModule: 7,
|
Cabinet: 1000,
|
||||||
NodeBMC: offset,
|
Chassis: 1,
|
||||||
}
|
ComputeModule: 7,
|
||||||
|
NodeBMC: offset,
|
||||||
|
}
|
||||||
|
)
|
||||||
offset += 1
|
offset += 1
|
||||||
|
|
||||||
|
// determine if local store exists and has credentials for
|
||||||
|
// the provided secretID...
|
||||||
|
// if it does not, create a static store and use the username
|
||||||
|
// and password provided instead
|
||||||
|
_, err = store.GetSecretByID(uri)
|
||||||
|
if store == nil || err != nil {
|
||||||
|
log.Warn().Err(err).Msgf("could not retrieve secrets for %s...falling back to default provided credentials", uri)
|
||||||
|
store = secrets.NewStaticStore(params.Username, params.Password)
|
||||||
|
}
|
||||||
|
|
||||||
// crawl BMC node to fetch inventory data via Redfish
|
// crawl BMC node to fetch inventory data via Redfish
|
||||||
var (
|
var (
|
||||||
systems []crawler.InventoryDetail
|
systems []crawler.InventoryDetail
|
||||||
managers []crawler.Manager
|
managers []crawler.Manager
|
||||||
config = crawler.CrawlerConfig{
|
config = crawler.CrawlerConfig{
|
||||||
URI: fmt.Sprintf("%s:%d", sr.Host, sr.Port),
|
URI: uri,
|
||||||
CredentialStore: store,
|
CredentialStore: store,
|
||||||
Insecure: true,
|
Insecure: true,
|
||||||
}
|
}
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
systems, err := crawler.CrawlBMCForSystems(config)
|
|
||||||
|
// crawl for node and BMC information
|
||||||
|
systems, err = crawler.CrawlBMCForSystems(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to crawl BMC for systems")
|
log.Error().Err(err).Msg("failed to crawl BMC for systems")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue