Skip to content

Commit

Permalink
Merge pull request #2279 from hashicorp/f-windows-hostid
Browse files Browse the repository at this point in the history
Add durable HostID generation support to Windows.
  • Loading branch information
dadgar authored Feb 3, 2017
2 parents 2a166bf + 31333ee commit 52a4c92
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 19 deletions.
3 changes: 2 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/hashicorp/nomad/client/stats"
"github.com/hashicorp/nomad/client/vaultclient"
"github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/tlsutil"
"github.com/hashicorp/nomad/nomad"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -636,7 +637,7 @@ func (c *Client) getAllocRunners() map[string]*AllocRunner {
func (c *Client) nodeID() (id, secret string, err error) {
var hostID string
hostInfo, err := host.Info()
if err == nil && hostInfo.HostID != "" {
if err == nil && helper.IsUUID(hostInfo.HostID) {
hostID = hostInfo.HostID
} else {
// Generate a random hostID if no constant ID is available on
Expand Down
15 changes: 15 additions & 0 deletions helper/funcs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package helper

import "regexp"

// validUUID is used to check if a given string looks like a UUID
var validUUID = regexp.MustCompile(`(?i)^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$`)

// IsUUID returns true if the given string is a valid UUID.
func IsUUID(str string) bool {
const uuidLen = 36
if len(str) != uuidLen {
return false
}

return validUUID.MatchString(str)
}

// boolToPtr returns the pointer to a boolean
func BoolToPtr(b bool) *bool {
return &b
Expand Down
80 changes: 62 additions & 18 deletions vendor/github.com/shirou/gopsutil/host/host_windows.go

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

0 comments on commit 52a4c92

Please sign in to comment.