github.com/jmitchell/nomad@v0.1.3-0.20151007230021-7ab84c2862d8/client/fingerprint/fingerprint.go (about) 1 package fingerprint 2 3 import ( 4 "fmt" 5 "log" 6 7 "github.com/hashicorp/nomad/client/config" 8 "github.com/hashicorp/nomad/nomad/structs" 9 ) 10 11 // BuiltinFingerprints is a slice containing the key names of all regestered 12 // fingerprints available, to provided an ordered iteration 13 var BuiltinFingerprints = []string{ 14 "arch", 15 "cpu", 16 "host", 17 "memory", 18 "storage", 19 "network", 20 "env_aws", 21 } 22 23 // builtinFingerprintMap contains the built in registered fingerprints 24 // which are available, corresponding to a key found in BuiltinFingerprints 25 var builtinFingerprintMap = map[string]Factory{ 26 "arch": NewArchFingerprint, 27 "cpu": NewCPUFingerprint, 28 "host": NewHostFingerprint, 29 "memory": NewMemoryFingerprint, 30 "storage": NewStorageFingerprint, 31 "network": NewNetworkFingerprinter, 32 "env_aws": NewEnvAWSFingerprint, 33 } 34 35 // NewFingerprint is used to instantiate and return a new fingerprint 36 // given the name and a logger 37 func NewFingerprint(name string, logger *log.Logger) (Fingerprint, error) { 38 // Lookup the factory function 39 factory, ok := builtinFingerprintMap[name] 40 if !ok { 41 return nil, fmt.Errorf("unknown fingerprint '%s'", name) 42 } 43 44 // Instantiate the fingerprint 45 f := factory(logger) 46 return f, nil 47 } 48 49 // Factory is used to instantiate a new Fingerprint 50 type Factory func(*log.Logger) Fingerprint 51 52 // Fingerprint is used for doing "fingerprinting" of the 53 // host to automatically determine attributes, resources, 54 // and metadata about it. Each of these is a heuristic, and 55 // many of them can be applied on a particular host. 56 type Fingerprint interface { 57 // Fingerprint is used to update properties of the Node, 58 // and returns if the fingerprint was applicable and a potential error. 59 Fingerprint(*config.Config, *structs.Node) (bool, error) 60 }