Encapsulate config
This commit is contained in:
parent
f24ca7f84d
commit
d9f981e4f3
@ -1,4 +1,4 @@
|
||||
package common
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package common
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
@ -1,5 +1,5 @@
|
||||
//go:generate packer-sdc mapstructure-to-hcl2 -type Config
|
||||
package common
|
||||
package config
|
||||
|
||||
import (
|
||||
"time"
|
@ -1,6 +1,6 @@
|
||||
// Code generated by "packer-sdc mapstructure-to-hcl2"; DO NOT EDIT.
|
||||
|
||||
package common
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/proxy"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"log"
|
||||
@ -44,12 +45,12 @@ func ExecuteSSHCmd(host string, port int, username, password, cmd string) (stdou
|
||||
}
|
||||
|
||||
func ExecuteApiHostSSHCmd(state multistep.StateBag, cmd string) (stdout string, err error) {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
return ExecuteSSHCmd(config.HostIp, config.HostSSHPort, config.Username, config.Password, cmd)
|
||||
}
|
||||
|
||||
func ExecuteHostSSHCmd(state multistep.StateBag, cmd string) (stdout string, err error) {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
xenProxy := state.Get("xen_proxy").(proxy.XenProxy)
|
||||
|
||||
host := state.Get("vm_host_address").(string)
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"log"
|
||||
|
||||
@ -57,7 +58,7 @@ func (self *StepAttachVdi) Run(ctx context.Context, state multistep.StateBag) mu
|
||||
}
|
||||
|
||||
func (self *StepAttachVdi) Cleanup(state multistep.StateBag) {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
if config.ShouldKeepVM(state) {
|
||||
return
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
@ -13,7 +14,7 @@ type StepBootWait struct{}
|
||||
|
||||
func (self *StepBootWait) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
instance, _ := c.GetClient().VM.GetByUUID(c.GetSessionRef(), state.Get("instance_uuid").(string))
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/proxy"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"log"
|
||||
@ -17,7 +18,7 @@ type StepCreateProxy struct {
|
||||
}
|
||||
|
||||
func (self *StepCreateProxy) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
var err error
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"io"
|
||||
"net"
|
||||
@ -84,7 +85,7 @@ func downloadFile(url, filename string, ui packer.Ui) (err error) {
|
||||
}
|
||||
|
||||
func (StepExport) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
instance_uuid := state.Get("instance_uuid").(string)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
"github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/proxy"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"net"
|
||||
@ -19,7 +20,7 @@ func (self *StepGetVNCPort) Run(ctx context.Context, state multistep.StateBag) m
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
xenClient := state.Get("client").(*xen.Connection)
|
||||
xenProxy := state.Get("xen_proxy").(proxy.XenProxy)
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
|
||||
if config.VNCConfig.DisableVNC {
|
||||
return multistep.ActionContinue
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"log"
|
||||
"time"
|
||||
@ -15,7 +16,7 @@ import (
|
||||
type StepShutdown struct{}
|
||||
|
||||
func (StepShutdown) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
instance_uuid := state.Get("instance_uuid").(string)
|
||||
|
@ -2,6 +2,7 @@ package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"log"
|
||||
"time"
|
||||
@ -134,6 +135,6 @@ func HimnSSHIP(state multistep.StateBag) (string, error) {
|
||||
}
|
||||
|
||||
func HimnSSHPort(state multistep.StateBag) (int, error) {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
return config.Comm.SSHPort, nil
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
@ -17,7 +18,7 @@ func (self *StepStartVmPaused) Run(ctx context.Context, state multistep.StateBag
|
||||
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
config := state.Get("config").(Config)
|
||||
config := state.Get("config").(config2.Config)
|
||||
|
||||
ui.Say("Step: Start VM Paused")
|
||||
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
"github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"log"
|
||||
)
|
||||
|
||||
@ -25,7 +26,7 @@ type StepTypeBootCommand struct {
|
||||
}
|
||||
|
||||
func (self *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
httpPort := state.Get("http_port").(int)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"log"
|
||||
"net"
|
||||
@ -22,7 +23,7 @@ type StepUploadVdi struct {
|
||||
}
|
||||
|
||||
func (self *StepUploadVdi) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
|
||||
@ -100,7 +101,7 @@ func (self *StepUploadVdi) Run(ctx context.Context, state multistep.StateBag) mu
|
||||
}
|
||||
|
||||
func (self *StepUploadVdi) Cleanup(state multistep.StateBag) {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"time"
|
||||
|
||||
@ -19,7 +20,7 @@ type StepWaitForIP struct {
|
||||
func (self *StepWaitForIP) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
|
||||
// Respect static configuration
|
||||
if config.Comm.Host() != "" {
|
||||
@ -98,6 +99,6 @@ func InstanceCommIP(state multistep.StateBag) (string, error) {
|
||||
}
|
||||
|
||||
func InstanceCommPort(state multistep.StateBag) (int, error) {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
return config.Comm.Port(), nil
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"log"
|
||||
|
||||
@ -11,7 +12,7 @@ import (
|
||||
type VmCleanup struct{}
|
||||
|
||||
func (self *VmCleanup) Cleanup(state multistep.StateBag) {
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
|
||||
if config.ShouldKeepVM(state) {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
"github.com/mitchellh/go-vnc"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/proxy"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"io"
|
||||
@ -18,7 +19,7 @@ import (
|
||||
|
||||
func GetVNCConsoleLocation(state multistep.StateBag) (string, error) {
|
||||
xenClient := state.Get("client").(*xen.Connection)
|
||||
config := state.Get("commonconfig").(CommonConfig)
|
||||
config := state.Get("commonconfig").(config2.CommonConfig)
|
||||
|
||||
vmRef, err := xenClient.GetClient().VM.GetByNameLabel(xenClient.GetSessionRef(), config.VMName)
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"path"
|
||||
"strings"
|
||||
@ -21,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
type Builder struct {
|
||||
config xscommon.Config
|
||||
config config2.Config
|
||||
runner multistep.Runner
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package iso
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
xscommon "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"log"
|
||||
|
||||
@ -10,7 +11,6 @@ import (
|
||||
"github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
xenapi "github.com/terra-farm/go-xen-api-client"
|
||||
xsclient "github.com/terra-farm/go-xen-api-client"
|
||||
xscommon "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common"
|
||||
)
|
||||
|
||||
type stepCreateInstance struct {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"time"
|
||||
|
||||
@ -19,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
type Builder struct {
|
||||
config xscommon.Config
|
||||
config config2.Config
|
||||
runner multistep.Runner
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package xva
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
config2 "github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/config"
|
||||
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/common/xen"
|
||||
"net"
|
||||
"os"
|
||||
@ -22,7 +23,7 @@ type stepImportInstance struct {
|
||||
func (self *stepImportInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
||||
c := state.Get("client").(*xen.Connection)
|
||||
config := state.Get("config").(xscommon.Config)
|
||||
config := state.Get("config").(config2.Config)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
ui.Say("Step: Import Instance")
|
||||
|
Loading…
Reference in New Issue
Block a user