Skip to content

Commit

Permalink
copy_out_guest_install_log
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Jan 18, 2021
1 parent 3fa1587 commit a34ccac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions builder/anka/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions builder/anka/step_create_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
type StepCreateVM struct {
client *client.Client
vmName string
config *Config
}

const (
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit a34ccac

Please sign in to comment.