builder/linode: move commHost() out of orphaned ssh.go

This commit is contained in:
Lars Lehtonen 2019-11-01 19:02:52 -07:00
parent 9dad09b9d3
commit af1e41793d
No known key found for this signature in database
GPG Key ID: 8137D474EBCB04F2
2 changed files with 16 additions and 24 deletions

View File

@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"log"
"github.com/hashicorp/packer/common"
"github.com/linode/linodego"
@ -96,3 +97,18 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (ret
return artifact, nil
}
func commHost(host string) func(multistep.StateBag) (string, error) {
return func(state multistep.StateBag) (string, error) {
if host != "" {
log.Printf("Using ssh_host value: %s", host)
return host, nil
}
instance := state.Get("instance").(*linodego.Instance)
if len(instance.IPv4) == 0 {
return "", fmt.Errorf("Linode instance %d has no IPv4 addresses!", instance.ID)
}
return instance.IPv4[0].String(), nil
}
}

View File

@ -1,24 +0,0 @@
package linode
import (
"fmt"
"log"
"github.com/hashicorp/packer/helper/multistep"
"github.com/linode/linodego"
)
func commHost(host string) func(multistep.StateBag) (string, error) {
return func(state multistep.StateBag) (string, error) {
if host != "" {
log.Printf("Using ssh_host value: %s", host)
return host, nil
}
instance := state.Get("instance").(*linodego.Instance)
if len(instance.IPv4) == 0 {
return "", fmt.Errorf("Linode instance %d has no IPv4 addresses!", instance.ID)
}
return instance.IPv4[0].String(), nil
}
}