From a34ccacb0c55b09cab65c0a1996c384969f36f95 Mon Sep 17 00:00:00 2001 From: Nathan Pierce Date: Mon, 18 Jan 2021 08:54:57 -0500 Subject: [PATCH] copy_out_guest_install_log --- builder/anka/config.go | 1 + builder/anka/step_create_vm.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/builder/anka/config.go b/builder/anka/config.go index 5d52c9ed..067c40f5 100644 --- a/builder/anka/config.go +++ b/builder/anka/config.go @@ -39,6 +39,7 @@ type Config struct { BootDelay string `mapstructure:"boot_delay"` EnableHtt bool `mapstructure:"enable_htt"` DisableHtt bool `mapstructure:"disable_htt"` + CopyOutGuestInstallLog bool `mapstructure:"copy_out_guest_install_log"` ctx interpolate.Context } diff --git a/builder/anka/step_create_vm.go b/builder/anka/step_create_vm.go index 76a34660..b0a3d885 100644 --- a/builder/anka/step_create_vm.go +++ b/builder/anka/step_create_vm.go @@ -26,6 +26,7 @@ func init() { type StepCreateVM struct { client *client.Client vmName string + config *Config } const ( @@ -154,11 +155,14 @@ func (s *StepCreateVM) modifyVMProperties(describeResponse client.DescribeRespon func (s *StepCreateVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { config := state.Get("config").(*Config) + ui := state.Get("ui").(packer.Ui) s.client = state.Get("client").(*client.Client) sourceVMName := config.SourceVMName + s.config = config + onError := func(err error) multistep.StepAction { return stepError(ui, state, err) } @@ -305,6 +309,19 @@ func (s *StepCreateVM) Cleanup(state multistep.StateBag) { case *common.VMNotFoundException: return default: + if s.config.CopyOutGuestInstallLog { + dir, dir_err := os.Getwd() + if dir_err == nil { + err = s.client.Copy(client.CopyParams{ + Src: s.vmName + ":/var/log/install.log", + Dst: dir + "/install-" + s.vmName + ".log", + }) + if err != nil { + log.Println("Error downloading install log from VM") + } + ui.Say(fmt.Sprintf("Saved install.log from %s to ./install-%s.log", s.vmName, s.vmName)) + } + } if halted || canceled { ui.Say(fmt.Sprintf("Deleting VM %s", s.vmName)) err = s.client.Delete(client.DeleteParams{VMName: s.vmName})