Compare commits

..

No commits in common. "main" and "remote_ssh_port" have entirely different histories.

10 changed files with 1316 additions and 82 deletions

View File

@ -19,6 +19,6 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: "1.20" go-version: 1.17
- name: Run go tests - name: Run go tests
run: go test -race -count 1 ./... -timeout=3m run: go test -race -count 1 ./... -timeout=3m

View File

@ -25,7 +25,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: "1.20" go-version: 1.17
- name: Describe plugin - name: Describe plugin
id: plugin_describe id: plugin_describe
run: echo "::set-output name=api_version::$(go run . describe | jq -r '.api_version')" run: echo "::set-output name=api_version::$(go run . describe | jq -r '.api_version')"
@ -36,10 +36,10 @@ jobs:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }} passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Run GoReleaser - name: Run GoReleaser
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0 uses: goreleaser/goreleaser-action@v2
with: with:
version: latest version: latest
args: release --clean args: release --rm-dist
env: env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1 +0,0 @@
1.20.11

View File

@ -1,4 +1,3 @@
version: 2
# This is an example goreleaser.yaml file with some sane defaults. # This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com # Make sure to check the documentation at http://goreleaser.com
env: env:
@ -71,4 +70,4 @@ release:
draft: false draft: false
changelog: changelog:
disable: true skip: true

View File

@ -45,7 +45,7 @@ If you are using an older version of packer or are still using json templates yo
### Dependencies ### Dependencies
* Packer >= v1.7.1 (https://packer.io) * Packer >= v1.7.1 (https://packer.io)
* XenServer / Citrix Hypervisor > 7.6 * XenServer / Citrix Hypervisor > 7.6
* Golang 1.20 * Golang 1.17
## Compile the plugin ## Compile the plugin

View File

@ -32,8 +32,8 @@ type StepTypeBootCommand struct {
Ctx interpolate.Context Ctx interpolate.Context
} }
func (step *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { func (self *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(Config) config := state.Get("commonconfig").(CommonConfig)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
c := state.Get("client").(*Connection) c := state.Get("client").(*Connection)
httpPort := state.Get("http_port").(int) httpPort := state.Get("http_port").(int)
@ -74,8 +74,7 @@ func (step *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB
} }
locationPieces := strings.SplitAfter(location, "/") locationPieces := strings.SplitAfter(location, "/")
consoleHost := strings.TrimSuffix(locationPieces[2], "/") consoleHost := strings.TrimSuffix(locationPieces[2], "/")
ui.Say("Connecting to VNC over XAPI...") ui.Say(fmt.Sprintf("Connecting to the VM console VNC over xapi via %s", consoleHost))
log.Printf("Connecting to host: %s", consoleHost)
conn, err := net.Dial("tcp", fmt.Sprintf("%s:443", consoleHost)) conn, err := net.Dial("tcp", fmt.Sprintf("%s:443", consoleHost))
if err != nil { if err != nil {
@ -96,7 +95,7 @@ func (step *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB
httpReq := fmt.Sprintf("CONNECT %s HTTP/1.0\r\nHost: %s\r\nCookie: session_id=%s\r\n\r\n", consoleLocation, consoleHost, c.session) httpReq := fmt.Sprintf("CONNECT %s HTTP/1.0\r\nHost: %s\r\nCookie: session_id=%s\r\n\r\n", consoleLocation, consoleHost, c.session)
fmt.Printf("Sending the follow http req: %v", httpReq) fmt.Printf("Sending the follow http req: %v", httpReq)
ui.Message(fmt.Sprintf("Making HTTP request to initiate VNC connection: %s", httpReq)) ui.Say(fmt.Sprintf("Making HTTP request to initiate VNC connection: %s", httpReq))
_, err = io.WriteString(tlsConn, httpReq) _, err = io.WriteString(tlsConn, httpReq)
if err != nil { if err != nil {
@ -115,9 +114,9 @@ func (step *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB
return multistep.ActionHalt return multistep.ActionHalt
} }
ui.Message(fmt.Sprintf("Received response: %s", string(buffer))) ui.Say(fmt.Sprintf("Received response: %s", string(buffer)))
vncClient, err := vnc.Client(tlsConn, &vnc.ClientConfig{Exclusive: !config.PackerDebug}) vncClient, err := vnc.Client(tlsConn, &vnc.ClientConfig{Exclusive: true})
if err != nil { if err != nil {
err := fmt.Errorf("Error establishing VNC session: %s", err) err := fmt.Errorf("Error establishing VNC session: %s", err)
@ -143,7 +142,7 @@ func (step *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB
localIp := strings.Split(envVar, " ")[0] localIp := strings.Split(envVar, " ")[0]
ui.Message(fmt.Sprintf("Found local IP: %s", localIp)) ui.Message(fmt.Sprintf("Found local IP: %s", localIp))
step.Ctx.Data = &bootCommandTemplateData{ self.Ctx.Data = &bootCommandTemplateData{
config.VMName, config.VMName,
localIp, localIp,
uint(httpPort), uint(httpPort),
@ -152,7 +151,7 @@ func (step *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB
ui.Say("Typing boot commands over VNC...") ui.Say("Typing boot commands over VNC...")
for _, command := range config.BootCommand { for _, command := range config.BootCommand {
command, err := interpolate.Render(command, &step.Ctx) command, err := interpolate.Render(command, &self.Ctx)
if err != nil { if err != nil {
err := fmt.Errorf("Error preparing boot command: %s", err) err := fmt.Errorf("Error preparing boot command: %s", err)
state.Put("error", err) state.Put("error", err)
@ -168,10 +167,12 @@ func (step *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB
vncSendString(vncClient, command) vncSendString(vncClient, command)
} }
ui.Say("Finished typing.")
return multistep.ActionContinue return multistep.ActionContinue
} }
func (step *StepTypeBootCommand) Cleanup(multistep.StateBag) {} func (self *StepTypeBootCommand) Cleanup(multistep.StateBag) {}
// Taken from qemu's builder plugin - not an exported function. // Taken from qemu's builder plugin - not an exported function.
func vncSendString(c *vnc.ClientConn, original string) { func vncSendString(c *vnc.ClientConn, original string) {

27
go.mod
View File

@ -1,15 +1,15 @@
module github.com/xenserver/packer-builder-xenserver module github.com/xenserver/packer-builder-xenserver
go 1.20 go 1.17
require ( require (
github.com/amfranz/go-xmlrpc-client v0.0.0-20190612172737-76858463955d github.com/amfranz/go-xmlrpc-client v0.0.0-20190612172737-76858463955d
github.com/hashicorp/hcl/v2 v2.20.1 github.com/hashicorp/hcl/v2 v2.12.0
github.com/hashicorp/packer-plugin-sdk v0.3.0 github.com/hashicorp/packer-plugin-sdk v0.3.0
github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed
github.com/terra-farm/go-xen-api-client v0.0.2 github.com/terra-farm/go-xen-api-client v0.0.2
github.com/zclconf/go-cty v1.14.4 github.com/zclconf/go-cty v1.10.0
golang.org/x/crypto v0.24.0 golang.org/x/crypto v0.18.0
) )
require ( require (
@ -22,7 +22,6 @@ require (
github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect
github.com/agext/levenshtein v1.2.3 // indirect github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/armon/go-metrics v0.3.9 // indirect github.com/armon/go-metrics v0.3.9 // indirect
github.com/aws/aws-sdk-go v1.40.34 // indirect github.com/aws/aws-sdk-go v1.40.34 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
@ -34,7 +33,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.1 // indirect github.com/googleapis/gax-go/v2 v2.7.1 // indirect
@ -81,24 +80,20 @@ require (
github.com/ugorji/go/codec v1.2.6 // indirect github.com/ugorji/go/codec v1.2.6 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect github.com/ulikunitz/xz v0.5.10 // indirect
go.opencensus.io v0.24.0 // indirect go.opencensus.io v0.24.0 // indirect
golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.7.0 // indirect golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.21.0 // indirect golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.21.0 // indirect golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.114.0 // indirect google.golang.org/api v0.114.0 // indirect
google.golang.org/appengine v1.6.7 // indirect google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.3 // indirect google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
) )
replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.13.3 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187

1299
go.sum

File diff suppressed because it is too large Load Diff

18
main.go
View File

@ -6,16 +6,30 @@ import (
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/iso" "github.com/xenserver/packer-builder-xenserver/builder/xenserver/iso"
"github.com/xenserver/packer-builder-xenserver/builder/xenserver/xva" "github.com/xenserver/packer-builder-xenserver/builder/xenserver/xva"
"github.com/xenserver/packer-builder-xenserver/version"
"github.com/hashicorp/packer-plugin-sdk/plugin" "github.com/hashicorp/packer-plugin-sdk/plugin"
"github.com/hashicorp/packer-plugin-sdk/version"
)
var (
// Version is the main version number that is being run at the moment.
Version = "v0.6.0"
// VersionPrerelease is A pre-release marker for the Version. If this is ""
// (empty string) then it means that it is a final release. Otherwise, this
// is a pre-release such as "dev" (in development), "beta", "rc1", etc.
VersionPrerelease = ""
// PluginVersion is used by the plugin set to allow Packer to recognize
// what version this plugin is.
PluginVersion = version.InitializePluginVersion(Version, VersionPrerelease)
) )
func main() { func main() {
pps := plugin.NewSet() pps := plugin.NewSet()
pps.RegisterBuilder("iso", new(iso.Builder)) pps.RegisterBuilder("iso", new(iso.Builder))
pps.RegisterBuilder("xva", new(xva.Builder)) pps.RegisterBuilder("xva", new(xva.Builder))
pps.SetVersion(version.PluginVersion) pps.SetVersion(PluginVersion)
err := pps.Run() err := pps.Run()
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err.Error()) fmt.Fprintln(os.Stderr, err.Error())

View File

@ -1,19 +0,0 @@
package version
import (
"github.com/hashicorp/packer-plugin-sdk/version"
)
var (
// Version is the main version number that is being run at the moment.
Version = "v0.6.0"
// VersionPrerelease is A pre-release marker for the Version. If this is ""
// (empty string) then it means that it is a final release. Otherwise, this
// is a pre-release such as "dev" (in development), "beta", "rc1", etc.
VersionPrerelease = "dev"
// PluginVersion is used by the plugin set to allow Packer to recognize
// what version this plugin is.
PluginVersion = version.InitializePluginVersion(Version, VersionPrerelease)
)