From 5caa54acd72b095d2164f69497c847290de5afb4 Mon Sep 17 00:00:00 2001 From: jasminSPC Date: Wed, 31 Aug 2016 13:55:11 +0200 Subject: [PATCH] Addressed all the comments --- .../profitbricks/{artifact.go => artefact.go} | 0 .../{artifact_test.go => artefact_test.go} | 0 builder/profitbricks/builder_acc_test.go | 6 +-- builder/profitbricks/builder_test.go | 38 +++++++++++++++++-- builder/profitbricks/step_create_server.go | 4 +- .../source/docs/builders/profitbricks.html.md | 25 ++++++------ 6 files changed, 51 insertions(+), 22 deletions(-) rename builder/profitbricks/{artifact.go => artefact.go} (100%) rename builder/profitbricks/{artifact_test.go => artefact_test.go} (100%) diff --git a/builder/profitbricks/artifact.go b/builder/profitbricks/artefact.go similarity index 100% rename from builder/profitbricks/artifact.go rename to builder/profitbricks/artefact.go diff --git a/builder/profitbricks/artifact_test.go b/builder/profitbricks/artefact_test.go similarity index 100% rename from builder/profitbricks/artifact_test.go rename to builder/profitbricks/artefact_test.go diff --git a/builder/profitbricks/builder_acc_test.go b/builder/profitbricks/builder_acc_test.go index 921dc9d73..c6ef0ed33 100644 --- a/builder/profitbricks/builder_acc_test.go +++ b/builder/profitbricks/builder_acc_test.go @@ -29,9 +29,9 @@ const testBuilderAccBasic = ` { "builders": [{ "image": "Ubuntu-16.04", - "password": "password", - "username": "username", - "snapshot_name": "packer", + "pbpassword": "password", + "pbusername": "username", + "servername": "packer", "type": "profitbricks" }] } diff --git a/builder/profitbricks/builder_test.go b/builder/profitbricks/builder_test.go index b1f74ff2a..50b72b1cd 100644 --- a/builder/profitbricks/builder_test.go +++ b/builder/profitbricks/builder_test.go @@ -9,9 +9,9 @@ import ( func testConfig() map[string]interface{} { return map[string]interface{}{ "image": "Ubuntu-16.04", - "password": "password", - "username": "username", - "snapshot_name": "packer", + "pbpassword": "password", + "pbusername": "username", + "servername": "packer", "type": "profitbricks", } } @@ -53,4 +53,34 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) { if err == nil { t.Fatal("should have error") } -} \ No newline at end of file +} + +func TestBuilderPrepare_Servername(t *testing.T) { + var b Builder + config := testConfig() + + delete(config, "servername") + warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err == nil { + t.Fatalf("should error") + } + + expected := "packer" + + config["servername"] = expected + 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.SnapshotName != expected { + t.Errorf("found %s, expected %s", b.config.SnapshotName, expected) + } +} diff --git a/builder/profitbricks/step_create_server.go b/builder/profitbricks/step_create_server.go index 4e96d73fc..9478c7842 100644 --- a/builder/profitbricks/step_create_server.go +++ b/builder/profitbricks/step_create_server.go @@ -130,7 +130,7 @@ func (s *stepCreateServer) Cleanup(state multistep.StateBag) { func (d *stepCreateServer) waitTillProvisioned(path string, config Config) error { d.setPB(config.PBUsername, config.PBPassword, config.PBUrl) - waitCount := 50 + waitCount := 120 if config.Timeout > 0 { waitCount = config.Timeout } @@ -142,7 +142,7 @@ func (d *stepCreateServer) waitTillProvisioned(path string, config Config) error if request.Metadata.Status == "FAILED" { return errors.New(request.Metadata.Message) } - time.Sleep(10 * time.Second) + time.Sleep(1 * time.Second) i++ } return nil diff --git a/website/source/docs/builders/profitbricks.html.md b/website/source/docs/builders/profitbricks.html.md index 923e4723e..0aea3b607 100644 --- a/website/source/docs/builders/profitbricks.html.md +++ b/website/source/docs/builders/profitbricks.html.md @@ -11,7 +11,7 @@ Type: `profitbricks` The ProfitBricks Builder is able to create virtual machines for [ProfitBricks](https://www.profitbricks.com). --> **Note:** This builder is not supported by HashiCorp. Please visit [ProfitBricks DevOps Central](https://devops.profitbricks.com/) for support. You may file issues on [GitHub](https://github.com/profitbricks/docker-machine-driver-profitbricks/issues). +-> **Note:** This builder is not supported by HashiCorp. Please visit [ProfitBricks DevOps Central](https://devops.profitbricks.com/) for support. You may file issues on [GitHub](https://github.com/profitbricks/packer-builder-profitbricks/issues). ## Configuration Reference @@ -25,33 +25,32 @@ builder. ### Required -- `username` (string) - ProfitBricks username. This can be specified via environment variable `PROFITBRICKS_USERNAME', if provided. The value definded in the config has precedence over environemnt variable. +- `image` (string) - ProfitBricks volume image - `password` (string) - ProfitBrucks password. This can be specified via environment variable `PROFITBRICKS_PASSWORD', if provided. The value definded in the config has precedence over environemnt variable. -- `image` (string) - ProfitBricks volume image +- `username` (string) - ProfitBricks username. This can be specified via environment variable `PROFITBRICKS_USERNAME', if provided. The value definded in the config has precedence over environemnt variable. + ### Optional -- `cores` (int) - Amount of CPU cores to use for this build. Defaults to `4`. +- `cores` (integer) - Amount of CPU cores to use for this build. Defaults to "4". -- `disk_size` (string) - Amount of disk space for this image. Defaults to `50gb` +- `disk_size` (string) - Amount of disk space for this image. Defaults to "50gb" -- `disktype` (string) - Type of disk to use for this image. Defaults to `HDD`. +- `disk_type` (string) - Type of disk to use for this image. Defaults to "HDD". -- `ram` (int) - Amount of RAM to use for this image. Defalts to `2048`. +- `location` (string) - Defaults to "us/las". -- `location` (string) - Defaults to `us/las`. +- `ram` (integer) - Amount of RAM to use for this image. Defalts to "2048". - `snapshot_name` (string) - If snapshot name is not provided Packer will generate it -- `snapshot_password` (string) - ???? - -- `ssh_key_path` (string) - Path to private SSHkey. If no path to the key is provided Packer will create one under the name [snapshot_name] +- `snapshot_password` (string) - Password for the snapshot. -- `url` (string) - Endpoint for the ProfitBricks REST API +- `timeout` (string) - An approximate limit on how long Packer will continue making status requests while waiting for the build to complete. Default value 120 seconds. -- `timeout` (string) - An approximate limit on how long packer will continue making status requests while waiting for the build to complete. Set this to an integer where 1 equals 10 seconds. Default value 50. +- `url` (string) - Endpoint for the ProfitBricks REST API. Default URL "https://api.profitbricks.com/rest/v2" ## Example