run go fmt

This commit is contained in:
Jeff Wong 2020-09-14 11:58:50 -07:00
parent aa5eb770d0
commit 99c3872a48
4 changed files with 42 additions and 42 deletions

View File

@ -2,14 +2,14 @@ package proxmoxclone
import (
"context"
"time"
"fmt"
"fmt"
"time"
proxmoxapi "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/packer/builder/proxmox/common"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
@ -34,15 +34,15 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
state := new(multistep.BasicStateBag)
state.Put("clone-config", &b.config)
state.Put("comm", &b.config.Comm)
state.Put("comm", &b.config.Comm)
preSteps := []multistep.Step{
&StepSshKeyPair{
Debug: b.config.PackerDebug,
&StepSshKeyPair{
Debug: b.config.PackerDebug,
DebugKeyPath: fmt.Sprintf("%s.pem", b.config.PackerBuildName),
Comm: &b.config.Comm,
},
}
},
}
postSteps := []multistep.Step{}
sb := proxmox.NewSharedBuilder(BuilderID, b.config.Config, preSteps, postSteps, &cloneVMCreator{})
@ -53,29 +53,29 @@ type cloneVMCreator struct{}
func (*cloneVMCreator) Create(vmRef *proxmoxapi.VmRef, config proxmoxapi.ConfigQemu, state multistep.StateBag) error {
client := state.Get("proxmoxClient").(*proxmoxapi.Client)
c := state.Get("clone-config").(*Config)
comm := state.Get("comm").(*communicator.Config)
c := state.Get("clone-config").(*Config)
comm := state.Get("comm").(*communicator.Config)
fullClone := 1
if c.FullClone {
fullClone = 0
}
fullClone := 1
if c.FullClone {
fullClone = 0
}
config.FullClone = &fullClone
config.CIuser = comm.SSHUsername
config.Sshkeys = string(comm.SSHPublicKey)
sourceVmr, err := client.GetVmRefByName(c.CloneVM)
if err != nil {
return err
}
err = config.CloneVm(sourceVmr, vmRef, client)
if err != nil {
return err
}
err = config.UpdateConfig(vmRef, client)
if err != nil {
return err
}
time.Sleep(time.Duration(15) * time.Second)
config.FullClone = &fullClone
config.CIuser = comm.SSHUsername
config.Sshkeys = string(comm.SSHPublicKey)
sourceVmr, err := client.GetVmRefByName(c.CloneVM)
if err != nil {
return err
}
err = config.CloneVm(sourceVmr, vmRef, client)
if err != nil {
return err
}
err = config.UpdateConfig(vmRef, client)
if err != nil {
return err
}
time.Sleep(time.Duration(15) * time.Second)
return nil
}

View File

@ -10,8 +10,8 @@ import (
type Config struct {
proxmox.Config `mapstructure:",squash"`
CloneVM string `mapstructure:"clone_vm"`
FullClone bool `mapstructure:"full_clone"`
CloneVM string `mapstructure:"clone_vm"`
FullClone bool `mapstructure:"full_clone"`
}
func (c *Config) Prepare(raws ...interface{}) ([]string, []string, error) {

View File

@ -19,7 +19,7 @@ func NewSharedBuilder(id string, config Config, preSteps []multistep.Step, postS
config: config,
preSteps: preSteps,
postSteps: postSteps,
vmCreator: vmCreator,
vmCreator: vmCreator,
}
}
@ -30,7 +30,7 @@ type Builder struct {
postSteps []multistep.Step
runner multistep.Runner
proxmoxClient *proxmox.Client
vmCreator ProxmoxVMCreator
vmCreator ProxmoxVMCreator
}
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook, state multistep.StateBag) (packer.Artifact, error) {
@ -54,16 +54,16 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook, state
state.Put("hook", hook)
state.Put("ui", ui)
comm := &b.config.Comm
if(state.Get("comm") != nil) {
comm = state.Get("comm").(*communicator.Config)
}
comm := &b.config.Comm
if state.Get("comm") != nil {
comm = state.Get("comm").(*communicator.Config)
}
// Build the steps
coreSteps := []multistep.Step{
&stepStartVM{
vmCreator: b.vmCreator,
},
vmCreator: b.vmCreator,
},
&common.StepHTTPServer{
HTTPDir: b.config.HTTPDir,
HTTPPortMin: b.config.HTTPPortMin,

View File

@ -15,8 +15,8 @@ import (
//
// It sets the vmRef state which is used throughout the later steps to reference the VM
// in API calls.
type stepStartVM struct{
vmCreator ProxmoxVMCreator
type stepStartVM struct {
vmCreator ProxmoxVMCreator
}
type ProxmoxVMCreator interface {