Rework client/fingerprint/fingerprint.go to use a slice and enforce ordering
This commit is contained in:
parent
d11bd582f7
commit
f048326300
|
@ -8,21 +8,35 @@ import (
|
||||||
"github.com/hashicorp/nomad/nomad/structs"
|
"github.com/hashicorp/nomad/nomad/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BuiltinFingerprints contains the built in registered fingerprints
|
// BuiltinFingerprints is a slice containing the key names of all regestered
|
||||||
// which are available
|
// fingerprints available, to provided an ordered iteration
|
||||||
var BuiltinFingerprints = map[string]Factory{
|
var BuiltinFingerprints = []string{
|
||||||
"arch": NewArchFingerprint,
|
"arch",
|
||||||
"cpu": NewCPUFingerprint,
|
"cpu",
|
||||||
"host": NewHostFingerprint,
|
"host",
|
||||||
"memory": NewMemoryFingerprint,
|
"memory",
|
||||||
"storage": NewStorageFingerprint,
|
"storage",
|
||||||
|
"unix_network",
|
||||||
|
"aws_network",
|
||||||
|
}
|
||||||
|
|
||||||
|
// builtinFingerprintMap contains the built in registered fingerprints
|
||||||
|
// which are available, corresponding to a key found in BuiltinFingerprints
|
||||||
|
var builtinFingerprintMap = map[string]Factory{
|
||||||
|
"arch": NewArchFingerprint,
|
||||||
|
"cpu": NewCPUFingerprint,
|
||||||
|
"host": NewHostFingerprint,
|
||||||
|
"memory": NewMemoryFingerprint,
|
||||||
|
"storage": NewStorageFingerprint,
|
||||||
|
"unix_network": NewUnixNetworkFingerprinter,
|
||||||
|
"aws_network": NewAWSNetworkFingerprinter,
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFingerprint is used to instantiate and return a new fingerprint
|
// NewFingerprint is used to instantiate and return a new fingerprint
|
||||||
// given the name and a logger
|
// given the name and a logger
|
||||||
func NewFingerprint(name string, logger *log.Logger) (Fingerprint, error) {
|
func NewFingerprint(name string, logger *log.Logger) (Fingerprint, error) {
|
||||||
// Lookup the factory function
|
// Lookup the factory function
|
||||||
factory, ok := BuiltinFingerprints[name]
|
factory, ok := builtinFingerprintMap[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unknown fingerprint '%s'", name)
|
return nil, fmt.Errorf("unknown fingerprint '%s'", name)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue