From f048326300fc1d0eb778c96d25ad21314f35c998 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Tue, 22 Sep 2015 14:23:48 -0500 Subject: [PATCH] Rework client/fingerprint/fingerprint.go to use a slice and enforce ordering --- client/fingerprint/fingerprint.go | 32 ++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/client/fingerprint/fingerprint.go b/client/fingerprint/fingerprint.go index 3a4587105..b87c0d9db 100644 --- a/client/fingerprint/fingerprint.go +++ b/client/fingerprint/fingerprint.go @@ -8,21 +8,35 @@ import ( "github.com/hashicorp/nomad/nomad/structs" ) -// BuiltinFingerprints contains the built in registered fingerprints -// which are available -var BuiltinFingerprints = map[string]Factory{ - "arch": NewArchFingerprint, - "cpu": NewCPUFingerprint, - "host": NewHostFingerprint, - "memory": NewMemoryFingerprint, - "storage": NewStorageFingerprint, +// BuiltinFingerprints is a slice containing the key names of all regestered +// fingerprints available, to provided an ordered iteration +var BuiltinFingerprints = []string{ + "arch", + "cpu", + "host", + "memory", + "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 // given the name and a logger func NewFingerprint(name string, logger *log.Logger) (Fingerprint, error) { // Lookup the factory function - factory, ok := BuiltinFingerprints[name] + factory, ok := builtinFingerprintMap[name] if !ok { return nil, fmt.Errorf("unknown fingerprint '%s'", name) }