github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/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  	"env_gce",
    22  }
    23  
    24  // builtinFingerprintMap contains the built in registered fingerprints
    25  // which are available, corresponding to a key found in BuiltinFingerprints
    26  var builtinFingerprintMap = map[string]Factory{
    27  	"arch":    NewArchFingerprint,
    28  	"cpu":     NewCPUFingerprint,
    29  	"host":    NewHostFingerprint,
    30  	"memory":  NewMemoryFingerprint,
    31  	"storage": NewStorageFingerprint,
    32  	"network": NewNetworkFingerprinter,
    33  	"env_aws": NewEnvAWSFingerprint,
    34  	"env_gce": NewEnvGCEFingerprint,
    35  }
    36  
    37  // NewFingerprint is used to instantiate and return a new fingerprint
    38  // given the name and a logger
    39  func NewFingerprint(name string, logger *log.Logger) (Fingerprint, error) {
    40  	// Lookup the factory function
    41  	factory, ok := builtinFingerprintMap[name]
    42  	if !ok {
    43  		return nil, fmt.Errorf("unknown fingerprint '%s'", name)
    44  	}
    45  
    46  	// Instantiate the fingerprint
    47  	f := factory(logger)
    48  	return f, nil
    49  }
    50  
    51  // Factory is used to instantiate a new Fingerprint
    52  type Factory func(*log.Logger) Fingerprint
    53  
    54  // Fingerprint is used for doing "fingerprinting" of the
    55  // host to automatically determine attributes, resources,
    56  // and metadata about it. Each of these is a heuristic, and
    57  // many of them can be applied on a particular host.
    58  type Fingerprint interface {
    59  	// Fingerprint is used to update properties of the Node,
    60  	// and returns if the fingerprint was applicable and a potential error.
    61  	Fingerprint(*config.Config, *structs.Node) (bool, error)
    62  }