Skip to content

Commit

Permalink
support retry on first ssh commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Gongaware committed Feb 15, 2017
1 parent 28dbb40 commit 39a47f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
18 changes: 15 additions & 3 deletions proxmox/preprovision.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"strconv"
"strings"
"time"
)

const eth0Payload = "echo $'%s' > /tmp/tf_eth0_payload"
Expand Down Expand Up @@ -59,9 +60,20 @@ func preProvisionUbuntu(d *schema.ResourceData) error {
}

log.Print("[DEBUG] sending os_network_config")
err = runCommand(comm, fmt.Sprintf(eth0Payload, strings.Trim(strconv.Quote(d.Get("os_network_config").(string)), "\"")))
if err != nil {
return err

// on this first one allow some retries to connect
rr := 0
for {
rr++
err = runCommand(comm, fmt.Sprintf(eth0Payload, strings.Trim(strconv.Quote(d.Get("os_network_config").(string)), "\"")))
if err != nil {
if rr > 3 {
return err
}
time.Sleep(2 * time.Second)
continue
}
break
}

hostname := d.Get("name").(string)
Expand Down
1 change: 1 addition & 0 deletions proxmox/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func Provider() *schema.Provider {
Required: true,
DefaultFunc: schema.EnvDefaultFunc("PM_PASS", nil),
Description: "secret",
Sensitive: true,
},
"pm_api_url": {
Type: schema.TypeString,
Expand Down
7 changes: 4 additions & 3 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ func resourceVmQemu() *schema.Resource {
ForceNew: true,
},
"ssh_private_key": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Sensitive: true,
},
},
}
Expand Down

0 comments on commit 39a47f7

Please sign in to comment.