From 7a956e1a11792a682fc809bd12afcafc88f1c4d8 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Fri, 27 Dec 2013 10:26:27 -0800 Subject: [PATCH 1/2] builder/digitalocean: add private_networking option for droplets --- builder/digitalocean/api.go | 3 +- builder/digitalocean/builder.go | 9 +++--- builder/digitalocean/builder_test.go | 33 +++++++++++++++++++++ builder/digitalocean/step_create_droplet.go | 2 +- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/builder/digitalocean/api.go b/builder/digitalocean/api.go index 769caf926..7aca1c14f 100644 --- a/builder/digitalocean/api.go +++ b/builder/digitalocean/api.go @@ -90,13 +90,14 @@ func (d DigitalOceanClient) DestroyKey(id uint) error { } // Creates a droplet and returns it's id -func (d DigitalOceanClient) CreateDroplet(name string, size uint, image uint, region uint, keyId uint) (uint, error) { +func (d DigitalOceanClient) CreateDroplet(name string, size uint, image uint, region uint, keyId uint, privateNetworking bool) (uint, error) { params := url.Values{} params.Set("name", name) params.Set("size_id", fmt.Sprintf("%v", size)) params.Set("image_id", fmt.Sprintf("%v", image)) params.Set("region_id", fmt.Sprintf("%v", region)) params.Set("ssh_key_ids", fmt.Sprintf("%v", keyId)) + params.Set("private_networking", fmt.Sprintf("%v", privateNetworking)) body, err := NewRequest(d, "droplets/new", params) if err != nil { diff --git a/builder/digitalocean/builder.go b/builder/digitalocean/builder.go index a98efee81..833706c1a 100644 --- a/builder/digitalocean/builder.go +++ b/builder/digitalocean/builder.go @@ -30,10 +30,11 @@ type config struct { SizeID uint `mapstructure:"size_id"` ImageID uint `mapstructure:"image_id"` - SnapshotName string `mapstructure:"snapshot_name"` - DropletName string `mapstructure:"droplet_name"` - SSHUsername string `mapstructure:"ssh_username"` - SSHPort uint `mapstructure:"ssh_port"` + PrivateNetworking bool `mapstructure:"private_networking"` + SnapshotName string `mapstructure:"snapshot_name"` + DropletName string `mapstructure:"droplet_name"` + SSHUsername string `mapstructure:"ssh_username"` + SSHPort uint `mapstructure:"ssh_port"` RawSSHTimeout string `mapstructure:"ssh_timeout"` RawStateTimeout string `mapstructure:"state_timeout"` diff --git a/builder/digitalocean/builder_test.go b/builder/digitalocean/builder_test.go index 2ccf20df4..751cd1301 100644 --- a/builder/digitalocean/builder_test.go +++ b/builder/digitalocean/builder_test.go @@ -356,6 +356,39 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) { } +func TestBuilderPrepare_PrivateNetworking(t *testing.T) { + var b Builder + config := testConfig() + + // Test default + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.PrivateNetworking != false { + t.Errorf("invalid: %s", b.config.PrivateNetworking) + } + + // Test set + config["private_networking"] = true + b = Builder{} + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.PrivateNetworking != true { + t.Errorf("invalid: %s", b.config.PrivateNetworking) + } +} + func TestBuilderPrepare_SnapshotName(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/digitalocean/step_create_droplet.go b/builder/digitalocean/step_create_droplet.go index 73e025f86..f46e7fd3c 100644 --- a/builder/digitalocean/step_create_droplet.go +++ b/builder/digitalocean/step_create_droplet.go @@ -19,7 +19,7 @@ func (s *stepCreateDroplet) Run(state multistep.StateBag) multistep.StepAction { ui.Say("Creating droplet...") // Create the droplet based on configuration - dropletId, err := client.CreateDroplet(c.DropletName, c.SizeID, c.ImageID, c.RegionID, sshKeyId) + dropletId, err := client.CreateDroplet(c.DropletName, c.SizeID, c.ImageID, c.RegionID, sshKeyId, c.PrivateNetworking) if err != nil { err := fmt.Errorf("Error creating droplet: %s", err) From 00fe97cae3fe77cb5a144112402d8c588a2ce4a6 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Fri, 27 Dec 2013 10:28:16 -0800 Subject: [PATCH 2/2] website: add private_networking docs for digitalocean --- website/source/docs/builders/digitalocean.html.markdown | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/source/docs/builders/digitalocean.html.markdown b/website/source/docs/builders/digitalocean.html.markdown index 10eed2c4e..a2525a840 100644 --- a/website/source/docs/builders/digitalocean.html.markdown +++ b/website/source/docs/builders/digitalocean.html.markdown @@ -46,6 +46,9 @@ Optional: * `size_id` (int) - The ID of the droplet size to use. This defaults to "66," which is the 512MB droplet. +* `private_networking` (bool) - Set to `true` to enable private networking + for the droplet being created. This defaults to `false`, or not enabled. + * `snapshot_name` (string) - The name of the resulting snapshot that will appear in your account. This must be unique. To help make this unique, use a function like `timestamp` (see