builder/digitalocean: add ability to specify api url

This is useful in case of using DigitalOcean compatibility api hosting.

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Vasiliy Tolstov 2016-02-05 12:57:43 +00:00
parent 2d749d8c55
commit ec4e95493d
3 changed files with 16 additions and 1 deletions

View File

@ -6,6 +6,7 @@ package digitalocean
import ( import (
"fmt" "fmt"
"log" "log"
"net/url"
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
@ -37,6 +38,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
client := godo.NewClient(oauth2.NewClient(oauth2.NoContext, &apiTokenSource{ client := godo.NewClient(oauth2.NewClient(oauth2.NoContext, &apiTokenSource{
AccessToken: b.config.APIToken, AccessToken: b.config.APIToken,
})) }))
if b.config.APIURL != "" {
u, err := url.Parse(b.config.APIURL)
if err != nil {
return nil, fmt.Errorf("DigitalOcean: Invalid API URL, %s.", err)
}
client.BaseURL = u
}
// Set up the state // Set up the state
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)

View File

@ -20,6 +20,7 @@ type Config struct {
Comm communicator.Config `mapstructure:",squash"` Comm communicator.Config `mapstructure:",squash"`
APIToken string `mapstructure:"api_token"` APIToken string `mapstructure:"api_token"`
APIURL string `mapstructure:"api_url"`
Region string `mapstructure:"region"` Region string `mapstructure:"region"`
Size string `mapstructure:"size"` Size string `mapstructure:"size"`
@ -57,7 +58,9 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
// Default to environment variable for api_token, if it exists // Default to environment variable for api_token, if it exists
c.APIToken = os.Getenv("DIGITALOCEAN_API_TOKEN") c.APIToken = os.Getenv("DIGITALOCEAN_API_TOKEN")
} }
if c.APIURL == "" {
c.APIURL = os.Getenv("DIGITALOCEAN_API_URL")
}
if c.SnapshotName == "" { if c.SnapshotName == "" {
def, err := interpolate.Render("packer-{{timestamp}}", nil) def, err := interpolate.Render("packer-{{timestamp}}", nil)
if err != nil { if err != nil {

View File

@ -55,6 +55,10 @@ builder.
### Optional: ### Optional:
- `api_url` (string) - Non standard api endpoint URL. Set this if you are
using a DigitalOcean API compatible service. It can also be specified via
environment variable `DIGITALOCEAN_API_URL`.
- `droplet_name` (string) - The name assigned to the droplet. DigitalOcean - `droplet_name` (string) - The name assigned to the droplet. DigitalOcean
sets the hostname of the machine to this value. sets the hostname of the machine to this value.