Remove dependency on identifier package, use time ordered UUID [GH-541]
This commit is contained in:
parent
7b09e24ac3
commit
697c91b0b0
|
@ -1,11 +1,10 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cgl.tideland.biz/identifier"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/goamz/ec2"
|
"github.com/mitchellh/goamz/ec2"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
"github.com/mitchellh/packer/common/uuid"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
@ -35,7 +34,7 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
|
||||||
// Create the group
|
// Create the group
|
||||||
ui.Say("Creating temporary security group for this instance...")
|
ui.Say("Creating temporary security group for this instance...")
|
||||||
groupName := fmt.Sprintf("packer %s", hex.EncodeToString(identifier.NewUUID().Raw()))
|
groupName := fmt.Sprintf("packer %s", uuid.TimeOrderedUUID())
|
||||||
log.Printf("Temporary group name: %s", groupName)
|
log.Printf("Temporary group name: %s", groupName)
|
||||||
group := ec2.SecurityGroup{
|
group := ec2.SecurityGroup{
|
||||||
Name: groupName,
|
Name: groupName,
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package digitalocean
|
package digitalocean
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cgl.tideland.biz/identifier"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
"github.com/mitchellh/packer/common/uuid"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +20,7 @@ func (s *stepCreateDroplet) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui.Say("Creating droplet...")
|
ui.Say("Creating droplet...")
|
||||||
|
|
||||||
// Some random droplet name as it's temporary
|
// Some random droplet name as it's temporary
|
||||||
name := fmt.Sprintf("packer-%s", hex.EncodeToString(identifier.NewUUID().Raw()))
|
name := fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
|
||||||
|
|
||||||
// Create the droplet based on configuration
|
// Create the droplet based on configuration
|
||||||
dropletId, err := client.CreateDroplet(name, c.SizeID, c.ImageID, c.RegionID, sshKeyId)
|
dropletId, err := client.CreateDroplet(name, c.SizeID, c.ImageID, c.RegionID, sshKeyId)
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package digitalocean
|
package digitalocean
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cgl.tideland.biz/identifier"
|
|
||||||
"code.google.com/p/go.crypto/ssh"
|
"code.google.com/p/go.crypto/ssh"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/hex"
|
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
"github.com/mitchellh/packer/common/uuid"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
@ -43,7 +42,7 @@ func (s *stepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
pub_sshformat := string(ssh.MarshalAuthorizedKey(pub))
|
pub_sshformat := string(ssh.MarshalAuthorizedKey(pub))
|
||||||
|
|
||||||
// The name of the public key on DO
|
// The name of the public key on DO
|
||||||
name := fmt.Sprintf("packer-%s", hex.EncodeToString(identifier.NewUUID().Raw()))
|
name := fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
|
||||||
|
|
||||||
// Create the key!
|
// Create the key!
|
||||||
keyId, err := client.CreateKey(name, pub_sshformat)
|
keyId, err := client.CreateKey(name, pub_sshformat)
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package openstack
|
package openstack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cgl.tideland.biz/identifier"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
"github.com/mitchellh/packer/common/uuid"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"github.com/rackspace/gophercloud"
|
"github.com/rackspace/gophercloud"
|
||||||
"log"
|
"log"
|
||||||
|
@ -19,7 +18,7 @@ func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
ui.Say("Creating temporary keypair for this instance...")
|
ui.Say("Creating temporary keypair for this instance...")
|
||||||
keyName := fmt.Sprintf("packer %s", hex.EncodeToString(identifier.NewUUID().Raw()))
|
keyName := fmt.Sprintf("packer %s", uuid.TimeOrderedUUID())
|
||||||
log.Printf("temporary keypair name: %s", keyName)
|
log.Printf("temporary keypair name: %s", keyName)
|
||||||
keyResp, err := csp.CreateKeyPair(gophercloud.NewKeyPair{Name: keyName})
|
keyResp, err := csp.CreateKeyPair(gophercloud.NewKeyPair{Name: keyName})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package uuid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generates a time ordered UUID. Top 32 bits are a timestamp,
|
||||||
|
// bottom 96 are random.
|
||||||
|
func TimeOrderedUUID() string {
|
||||||
|
unix := uint32(time.Now().UTC().Unix())
|
||||||
|
rand1 := rand.Uint32()
|
||||||
|
rand2 := rand.Uint32()
|
||||||
|
rand3 := rand.Uint32()
|
||||||
|
return fmt.Sprintf("%08x-%04x-%04x-%04x-%04x%08x",
|
||||||
|
unix,
|
||||||
|
uint16(rand1>>16),
|
||||||
|
uint16(rand1&0xffff),
|
||||||
|
uint16(rand2>>16),
|
||||||
|
uint16(rand2&0xffff),
|
||||||
|
rand3)
|
||||||
|
}
|
|
@ -2,9 +2,8 @@ package packer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"cgl.tideland.biz/identifier"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/mitchellh/packer/common/uuid"
|
||||||
"strconv"
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
@ -94,5 +93,5 @@ func templateTimestamp() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func templateUuid() string {
|
func templateUuid() string {
|
||||||
return hex.EncodeToString(identifier.NewUUID().Raw())
|
return hex.EncodeToString(uuid.TimeOrderedUUID())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue