diff options
Diffstat (limited to 'vendor/github.com/mitchellh/packer/builder/lxd/step_lxd_launch.go')
-rw-r--r-- | vendor/github.com/mitchellh/packer/builder/lxd/step_lxd_launch.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/packer/builder/lxd/step_lxd_launch.go b/vendor/github.com/mitchellh/packer/builder/lxd/step_lxd_launch.go new file mode 100644 index 00000000..1ec573b1 --- /dev/null +++ b/vendor/github.com/mitchellh/packer/builder/lxd/step_lxd_launch.go @@ -0,0 +1,50 @@ +package lxd + +import ( + "fmt" + "github.com/hashicorp/packer/packer" + "github.com/mitchellh/multistep" + "time" +) + +type stepLxdLaunch struct{} + +func (s *stepLxdLaunch) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*Config) + ui := state.Get("ui").(packer.Ui) + + name := config.ContainerName + image := config.Image + + args := []string{ + "launch", "--ephemeral=false", image, name, + } + + ui.Say("Creating container...") + _, err := LXDCommand(args...) + if err != nil { + err := fmt.Errorf("Error creating container: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + // TODO: Should we check `lxc info <container>` for "Running"? + // We have to do this so /tmp doens't get cleared and lose our provisioner scripts. + time.Sleep(1 * time.Second) + + return multistep.ActionContinue +} + +func (s *stepLxdLaunch) Cleanup(state multistep.StateBag) { + config := state.Get("config").(*Config) + ui := state.Get("ui").(packer.Ui) + + args := []string{ + "delete", "--force", config.ContainerName, + } + + ui.Say("Unregistering and deleting deleting container...") + if _, err := LXDCommand(args...); err != nil { + ui.Error(fmt.Sprintf("Error deleting container: %s", err)) + } +} |