Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instance_id to state so ID is usable in provisioners #84

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions builder/lxd/step_lxd_launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ func (s *stepLxdLaunch) Run(ctx context.Context, state multistep.StateBag) multi
launch_args = append(launch_args, "--config", fmt.Sprintf("%s=%s", k, v))
}

ui.Say("Creating container...")
_, err := LXDCommand(launch_args...)
sleep_seconds, err := strconv.Atoi(config.InitSleep)
if err != nil {
err := fmt.Errorf("Error creating container: %s", err)
err := fmt.Errorf("Error parsing InitSleep into int: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
sleep_seconds, err := strconv.Atoi(config.InitSleep)

ui.Say("Creating container...")
_, err = LXDCommand(launch_args...)
if err != nil {
err := fmt.Errorf("Error parsing InitSleep into int: %s", err)
err := fmt.Errorf("Error creating container: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -52,8 +53,13 @@ func (s *stepLxdLaunch) Run(ctx context.Context, state multistep.StateBag) multi
// TODO: Should we check `lxc info <container>` for "Running"?
// We have to do this so /tmp doesn't get cleared and lose our provisioner scripts.

time.Sleep(time.Duration(sleep_seconds) * time.Second)
log.Printf("Sleeping for %d seconds...", sleep_seconds)
time.Sleep(time.Duration(sleep_seconds) * time.Second)

// instance_id is the generic term used so that users can have access to the
// instance id inside the provisioners, used in step_provision.
state.Put("instance_id", name)
ui.Message(fmt.Sprintf("Instance Name: %s", name))
return multistep.ActionContinue
}

Expand Down
Loading