Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Broer committed Nov 2, 2015
2 parents 2891d9e + 41f2848 commit bcce25c
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions vultr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"text/template"
Expand Down Expand Up @@ -34,6 +35,7 @@ type Driver struct {
PrivateNetworking bool
ScriptID int
HasCustomScript bool
UserDataFile string
bucket *tokenbucket.Bucket
}

Expand Down Expand Up @@ -97,6 +99,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Name: "vultr-backups",
Usage: "Enable automatic backups for VPS",
},
mcnflag.StringFlag{
EnvVar: "VULTR_USERDATA",
Name: "vultr-userdata",
Usage: "path to file with cloud-init user-data",
},
}
}

Expand Down Expand Up @@ -132,6 +139,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.IPv6 = flags.Bool("vultr-ipv6")
d.PrivateNetworking = flags.Bool("vultr-private-networking")
d.Backups = flags.Bool("vultr-backups")
d.UserDataFile = flags.String("vultr-userdata")
d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery")
Expand All @@ -145,11 +153,19 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
}

func (d *Driver) PreCreateCheck() error {
if d.UserDataFile != "" {
if d.OSID == 159 {
return fmt.Errorf("passing user-data is not supported with custom OS (--vultr-os-id 159)")
}
if _, err := os.Stat(d.UserDataFile); os.IsNotExist(err) {
return fmt.Errorf("Unable to find user-data file at %s", d.UserDataFile)
}
}

log.Info("Validating Vultr VPS parameters...")

if d.ScriptID != 0 && d.OSID != 159 {
return fmt.Errorf("PXE boot script can only be used with custom OS (vultr-os-id=159)")
return fmt.Errorf("PXE boot script requires using custom OS (--vultr-os-id 159)")
}

if err := d.validateRegion(); err != nil {
Expand All @@ -168,19 +184,17 @@ func (d *Driver) PreCreateCheck() error {
}

func (d *Driver) Create() error {
var userdata string
log.Debug("Generating SSH key...")

key, err := d.createSSHKey()
if err != nil {
return err
}

d.SSHKeyID = key.ID

log.Info("Creating Vultr VPS...")
var userdata string

// iPXE deployment
if d.OSID == 159 {
log.Info("Using iPXE boot script for deployment")
if d.ScriptID != 0 {
Expand All @@ -198,7 +212,16 @@ func (d *Driver) Create() error {
if err != nil {
return err
}
log.Debugf("Using the following ec2 cloud-config:")
} else if d.UserDataFile != "" {
buf, err := ioutil.ReadFile(d.UserDataFile)
if err != nil {
return err
}
userdata = string(buf)
}

if userdata != "" {
log.Debugf("Using the following cloud-init user-data:")
log.Debugf("%s", userdata)
}

Expand Down

0 comments on commit bcce25c

Please # to comment.