diff --git a/builder/profitbricks/builder_test.go b/builder/profitbricks/builder_test.go index 06e6fb981..6fa2becb5 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", - "pbpassword": "password", - "pbusername": "username", - "servername": "packer", + "password": "password", + "username": "username", + "snapshot_name": "packer", "type": "profitbricks", } } @@ -54,34 +54,4 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) { if err == nil { t.Fatal("should have error") } -} - -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) - } } \ No newline at end of file diff --git a/builder/profitbricks/step_create_server.go b/builder/profitbricks/step_create_server.go index f65b02a9d..b0f8b924d 100644 --- a/builder/profitbricks/step_create_server.go +++ b/builder/profitbricks/step_create_server.go @@ -8,6 +8,7 @@ import ( "github.com/profitbricks/profitbricks-sdk-go" "strings" "time" + "github.com/profitbricks/profitbricks-sdk-go/model" ) const ( @@ -21,73 +22,56 @@ func (s *stepCreateServer) Run(state multistep.StateBag) multistep.StepAction { c := state.Get("config").(*Config) profitbricks.SetAuth(c.PBUsername, c.PBPassword) + profitbricks.SetDepth("5") + c.SSHKey = state.Get("publicKey").(string) ui.Say("Creating Virutal Data Center...") + img := s.getImageId(c.Image, c) - datacenter := profitbricks.CreateDatacenter(profitbricks.CreateDatacenterRequest{ - DCProperties: profitbricks.DCProperties{ - Name: c.SnapshotName, - Location: c.Region, + datacenter := model.Datacenter{ + Properties: model.DatacenterProperties{ + Name: c.SnapshotName, + Location:c.Region, }, - }) - - err := s.checkForErrors(datacenter.Resp) - if err != nil { - ui.Error(err.Error()) - return multistep.ActionHalt - } - - s.waitTillProvisioned(strings.Join(datacenter.Resp.Headers["Location"], ""), *c) - - state.Put("datacenter_id", datacenter.Id) - - ui.Say("Creating ProfitBricks server...") - - server := profitbricks.CreateServer(datacenter.Id, profitbricks.CreateServerRequest{ - ServerProperties: profitbricks.ServerProperties{ - Name: c.SnapshotName, - Ram: c.Ram, - Cores: c.Cores, + Entities:model.DatacenterEntities{ + Servers: &model.Servers{ + Items:[]model.Server{ + model.Server{ + Properties: model.ServerProperties{ + Name : c.SnapshotName, + Ram: c.Ram, + Cores: c.Cores, + }, + Entities:model.ServerEntities{ + Volumes: &model.AttachedVolumes{ + Items:[]model.Volume{ + model.Volume{ + Properties: model.VolumeProperties{ + Type_:c.DiskType, + Size:c.DiskSize, + Name:c.SnapshotName, + Image:img, + ImagePassword: "test1234", + SshKeys: []string{c.SSHKey}, + }, + }, + }, + }, + }, + }, + }, + }, }, - }) - - err = s.checkForErrors(server.Resp) - if err != nil { - ui.Error(err.Error()) - return multistep.ActionHalt } - s.waitTillProvisioned(strings.Join(server.Resp.Headers["Location"], ""), *c) - - ui.Say("Creating a volume...") - - c.SSHKey = state.Get("publicKey").(string) - - img := s.getImageId(c.Image, c) - - volume := profitbricks.CreateVolume(datacenter.Id, profitbricks.CreateVolumeRequest{ - VolumeProperties: profitbricks.VolumeProperties{ - Size: c.DiskSize, - Name: c.SnapshotName, - Image: img, - Type: c.DiskType, - SshKey: []string{c.SSHKey}, - ImagePassword: c.SnapshotPassword, - }, - }) - - err = s.checkForErrors(volume.Resp) - if err != nil { - ui.Error(err.Error()) + datacenter = profitbricks.CompositeCreateDatacenter(datacenter) + if datacenter.StatusCode > 299 { + ui.Error(datacenter.Response) return multistep.ActionHalt } + s.waitTillProvisioned(datacenter.Headers.Get("Location"), *c) - s.waitTillProvisioned(strings.Join(volume.Resp.Headers["Location"], ""), *c) - - attachresponse := profitbricks.AttachVolume(datacenter.Id, server.Id, volume.Id) - - s.waitTillProvisioned(strings.Join(attachresponse.Resp.Headers["Location"], ""), *c) - ui.Say("Creating a LAN...") + state.Put("datacenter_id", datacenter.Id) lan := profitbricks.CreateLan(datacenter.Id, profitbricks.CreateLanRequest{ LanProperties: profitbricks.LanProperties{ @@ -96,7 +80,7 @@ func (s *stepCreateServer) Run(state multistep.StateBag) multistep.StepAction { }, }) - err = s.checkForErrors(lan.Resp) + err := s.checkForErrors(lan.Resp) if err != nil { ui.Error(err.Error()) return multistep.ActionHalt @@ -104,12 +88,10 @@ func (s *stepCreateServer) Run(state multistep.StateBag) multistep.StepAction { s.waitTillProvisioned(strings.Join(lan.Resp.Headers["Location"], ""), *c) - ui.Say("Creating a NIC...") - - nic := profitbricks.CreateNic(datacenter.Id, server.Id, profitbricks.NicCreateRequest{ - NicProperties: profitbricks.NicProperties{ + nic := profitbricks.CreateNic(datacenter.Id, datacenter.Entities.Servers.Items[0].Id, profitbricks.NicCreateRequest{ + NicProperties : profitbricks.NicProperties{ Name: c.SnapshotName, - Lan: lan.Id, + Lan: lan.Id, Dhcp: true, }, }) @@ -122,29 +104,9 @@ func (s *stepCreateServer) Run(state multistep.StateBag) multistep.StepAction { s.waitTillProvisioned(strings.Join(nic.Resp.Headers["Location"], ""), *c) - bootVolume := profitbricks.Instance{ - Properties: nil, - Entities: nil, - MetaData: nil, - } - - bootVolume.Id = volume.Id - - serverpatchresponse := profitbricks.PatchServer(datacenter.Id, server.Id, profitbricks.ServerProperties{ - BootVolume: &bootVolume, - }) - - state.Put("volume_id", volume.Id) - - err = s.checkForErrors(serverpatchresponse.Resp) - if err != nil { - ui.Error(err.Error()) - return multistep.ActionHalt - } - - s.waitTillProvisioned(strings.Join(serverpatchresponse.Resp.Headers["Location"], ""), *c) + state.Put("volume_id", datacenter.Entities.Servers.Items[0].Entities.Volumes.Items[0].Id) - server = profitbricks.GetServer(datacenter.Id, server.Id) + server := profitbricks.GetServer(datacenter.Id, datacenter.Entities.Servers.Items[0].Id) state.Put("server_ip", server.Entities["nics"].Items[0].Properties["ips"].([]interface{})[0].(string)) diff --git a/website/source/docs/builders/profitbricks.html.md b/website/source/docs/builders/profitbricks.html.md index a923c3baf..a726cbe8e 100644 --- a/website/source/docs/builders/profitbricks.html.md +++ b/website/source/docs/builders/profitbricks.html.md @@ -117,6 +117,7 @@ Required parameters: "password" - ProfitiBricks password ``` + Optional parameters: ```shell