Skip to content

Commit

Permalink
Merge pull request #2277 from hashicorp/f-durable-uuid
Browse files Browse the repository at this point in the history
Reproducible Node ID
  • Loading branch information
dadgar committed Feb 2, 2017
2 parents ae0b342 + b07a622 commit df2c9cc
Show file tree
Hide file tree
Showing 112 changed files with 3,813 additions and 1,941 deletions.
25 changes: 18 additions & 7 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/hashicorp/nomad/nomad/structs"
vaultapi "github.com/hashicorp/vault/api"
"github.com/mitchellh/hashstructure"
"github.com/shirou/gopsutil/host"
)

const (
Expand Down Expand Up @@ -629,12 +630,23 @@ func (c *Client) getAllocRunners() map[string]*AllocRunner {
return runners
}

// nodeIDs restores the nodes persistent unique ID and SecretID or generates new
// ones
func (c *Client) nodeID() (id string, secret string, err error) {
// nodeID restores, or generates if necessary, a unique node ID and SecretID.
// The node ID is, if available, a persistent unique ID. The secret ID is a
// high-entropy random UUID.
func (c *Client) nodeID() (id, secret string, err error) {
var hostID string
hostInfo, err := host.Info()
if err == nil && hostInfo.HostID != "" {
hostID = hostInfo.HostID
} else {
// Generate a random hostID if no constant ID is available on
// this platform.
hostID = structs.GenerateUUID()
}

// Do not persist in dev mode
if c.config.DevMode {
return structs.GenerateUUID(), structs.GenerateUUID(), nil
return hostID, structs.GenerateUUID(), nil
}

// Attempt to read existing ID
Expand All @@ -655,8 +667,7 @@ func (c *Client) nodeID() (id string, secret string, err error) {
if len(idBuf) != 0 {
id = string(idBuf)
} else {
// Generate new ID
id = structs.GenerateUUID()
id = hostID

// Persist the ID
if err := ioutil.WriteFile(idPath, []byte(id), 0700); err != nil {
Expand Down Expand Up @@ -686,7 +697,7 @@ func (c *Client) setupNode() error {
node = &structs.Node{}
c.config.Node = node
}
// Generate an iD for the node
// Generate an ID and secret for the node
id, secretID, err := c.nodeID()
if err != nil {
return fmt.Errorf("node ID setup failed: %v", err)
Expand Down
59 changes: 44 additions & 15 deletions vendor/github.com/StackExchange/wmi/wmi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions vendor/github.com/go-ole/go-ole/.travis.yml

This file was deleted.

49 changes: 0 additions & 49 deletions vendor/github.com/go-ole/go-ole/ChangeLog.md

This file was deleted.

46 changes: 0 additions & 46 deletions vendor/github.com/go-ole/go-ole/README.md

This file was deleted.

63 changes: 0 additions & 63 deletions vendor/github.com/go-ole/go-ole/appveyor.yml

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/github.com/go-ole/go-ole/build/compile-go.bat

This file was deleted.

This file was deleted.

Binary file not shown.
31 changes: 0 additions & 31 deletions vendor/github.com/go-ole/go-ole/example/excel/excel.go

This file was deleted.

Loading

0 comments on commit df2c9cc

Please sign in to comment.