From 4632737bdc9a2b482bc78bb552abe7aa1616f882 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Mon, 8 Mar 2021 23:55:10 -0800 Subject: [PATCH 01/21] Update goreleaser with the packer template --- .goreleaser.yml | 90 ++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index b6fa2f6..9b41c25 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,55 +1,77 @@ -# Visit https://goreleaser.com for documentation on how to customize this -# behavior. + +# This is an example goreleaser.yaml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +env: + - CGO_ENABLED=0 before: hooks: - # this is just an example and not a requirement for provider building/publishing - - go mod tidy + # We strongly recommend running tests to catch any regression before release. + # Even though, this an optional step. + - go test ./... + builds: -- env: - # goreleaser does not work with CGO, it could also complicate - # usage by users in CI/CD systems like Terraform Cloud where - # they are unable to install libraries. - - CGO_ENABLED=0 - main: plugin/builder-xenserver-iso/main.go - mod_timestamp: '{{ .CommitTimestamp }}' - flags: - - -trimpath - ldflags: - - '-X main.version={{.Version}} -X main.commit={{.Commit}}' - goos: - - freebsd - - windows - - linux - - darwin - goarch: - - amd64 - - '386' - - arm - - arm64 - ignore: - - goos: darwin - goarch: '386' - binary: '{{ .ProjectName }}_v{{ .Version }}' + # A separated build to run the packer-plugins-check only once for a linux_amd64 binary + - + id: plugin-check + mod_timestamp: '{{ .CommitTimestamp }}' + hooks: + post: + # This will check plugin compatibility against latest version of Packer + - cmd: | + go install github.com/hashicorp/packer/cmd/packer-plugins-check@latest && + packer-plugins-check -load={{ .Name }} + dir: "{{ dir .Path}}" + flags: + - -trimpath #removes all file system paths from the compiled executable + ldflags: + - '-s -w -X main.Version={{.Version}} -X main.VersionPrerelease= ' + goos: + - linux + goarch: + - amd64 + binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}' + - + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath #removes all file system paths from the compiled executable + ldflags: + - '-s -w -X main.version={{.Version}} -X main.VersionPrerelease= ' + goos: + - freebsd + - windows + - linux + - darwin + goarch: + - amd64 + - '386' + - arm + - arm64 + ignore: + - goos: darwin + goarch: '386' + - goos: linux + goarch: amd64 + binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}' archives: - format: zip - name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' + name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}' checksum: - name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' + name_template: '{{ .ProjectName }}_v{{ .Version }}_SHA256SUMS' algorithm: sha256 signs: - artifacts: checksum args: - # if you are using this is a GitHub action or some other automated pipeline, you + # if you are using this is in a GitHub action or some other automated pipeline, you # need to pass the batch flag to indicate its not interactive. - "--batch" - "--local-user" - - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key + - "{{ .Env.GPG_FINGERPRINT }}" - "--output" - "${signature}" - "--detach-sign" - "${artifact}" release: - # Visit your project's GitHub Releases page to publish this release. + # If you want to manually examine the release before its live, uncomment this line: draft: true changelog: skip: true From a0c3a738038fcfbeb168d98b2e557f212fd2acf1 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Mon, 8 Mar 2021 23:59:41 -0800 Subject: [PATCH 02/21] Don't run unit test on goreleaser --- .goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 9b41c25..ec9fbd6 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -7,7 +7,7 @@ before: hooks: # We strongly recommend running tests to catch any regression before release. # Even though, this an optional step. - - go test ./... + # - go test ./... builds: # A separated build to run the packer-plugins-check only once for a linux_amd64 binary From 705baaa47646501aabb89232bf68085ef97a1ba8 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 00:03:23 -0800 Subject: [PATCH 03/21] Another fix --- .goreleaser.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index ec9fbd6..aa6830e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -49,8 +49,6 @@ builds: ignore: - goos: darwin goarch: '386' - - goos: linux - goarch: amd64 binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}' archives: - format: zip From f71febe2e141900f0e076e763ba6ac650405686e Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 20:50:20 -0800 Subject: [PATCH 04/21] Add github workflow on release --- .github/workflows/release.yml | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b538565 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +# This GitHub action can publish assets for release when a tag is created. +# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). +# +# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your +# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` +# secret. If you would rather own your own GPG handling, please fork this action +# or use an alternative one for key handling. +# +# You will need to pass the `--batch` flag to `gpg` in your signing step +# in `goreleaser` to indicate this is being used in a non-interactive mode. +# +name: release +on: + push: + tags: + - 'v*' +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Unshallow + run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - name: Describe plugin + id: plugin_describe + run: echo "::set-output name=api_version::$(go run . describe | jq -r '.api_version')" + - name: Import GPG key + id: import_gpg + uses: paultyng/ghaction-import-gpg@v2.1.0 + env: + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + PASSPHRASE: ${{ secrets.PASSPHRASE }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + API_VERSION: ${{ steps.plugin_describe.outputs.api_version }} \ No newline at end of file From 51ed1d7c5ae89bef7164dff65d72e4ff44a16560 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 20:52:02 -0800 Subject: [PATCH 05/21] Use go 1.14 --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b538565..ad46c23 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.14 - name: Describe plugin id: plugin_describe run: echo "::set-output name=api_version::$(go run . describe | jq -r '.api_version')" @@ -43,4 +43,4 @@ jobs: env: GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - API_VERSION: ${{ steps.plugin_describe.outputs.api_version }} \ No newline at end of file + API_VERSION: ${{ steps.plugin_describe.outputs.api_version }} From 63821d62e03a2178376eec85f846f8977bdd7e18 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 20:52:39 -0800 Subject: [PATCH 06/21] Add github workflow to master for #10: --- .github/workflows/release.yml | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ad46c23 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +# This GitHub action can publish assets for release when a tag is created. +# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). +# +# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your +# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` +# secret. If you would rather own your own GPG handling, please fork this action +# or use an alternative one for key handling. +# +# You will need to pass the `--batch` flag to `gpg` in your signing step +# in `goreleaser` to indicate this is being used in a non-interactive mode. +# +name: release +on: + push: + tags: + - 'v*' +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Unshallow + run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.14 + - name: Describe plugin + id: plugin_describe + run: echo "::set-output name=api_version::$(go run . describe | jq -r '.api_version')" + - name: Import GPG key + id: import_gpg + uses: paultyng/ghaction-import-gpg@v2.1.0 + env: + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + PASSPHRASE: ${{ secrets.PASSPHRASE }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + API_VERSION: ${{ steps.plugin_describe.outputs.api_version }} From ce98892ce2d2714c8ce26e38bd3e21abffa98caa Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 21:13:18 -0800 Subject: [PATCH 07/21] Use go 1.16 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad46c23..cf894d3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.14 + go-version: 1.16 - name: Describe plugin id: plugin_describe run: echo "::set-output name=api_version::$(go run . describe | jq -r '.api_version')" From f8545871167efb3559c19e51a2e3778001aae036 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 21:16:49 -0800 Subject: [PATCH 08/21] Use go 1.16 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad46c23..cf894d3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,7 +25,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.14 + go-version: 1.16 - name: Describe plugin id: plugin_describe run: echo "::set-output name=api_version::$(go run . describe | jq -r '.api_version')" From 4f96ba4badfe720e2566ab1c8c75b3b9797040c7 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 21:30:51 -0800 Subject: [PATCH 09/21] Adjust goreleaser file to align with upstream and update docs about go1.16 upgrade --- .goreleaser.yml | 3 +++ README.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index aa6830e..0357ebb 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -49,6 +49,9 @@ builds: ignore: - goos: darwin goarch: '386' + - goos: linux + goarch: amd64 + binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}' archives: - format: zip diff --git a/README.md b/README.md index 97f178b..b32d4a7 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Download the relevant release from the project's [releases page](https://github. ### Dependencies * Packer >= v1.7.0 (https://packer.io) * XenServer / Citrix Hypervisor > 7.6 -* Golang 1.14 +* Golang 1.16 ## Compile the plugin From 794e5834ebb657b8e2e599713db576ba7eaaedc8 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 21:49:53 -0800 Subject: [PATCH 10/21] Update release version in main.go --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 73edeff..ac2de3d 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ var ( // 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" + VersionPrerelease = "dev8" // PluginVersion is used by the plugin set to allow Packer to recognize // what version this plugin is. From ea75b25c5ea2af2e01b02c43812afad8fd374f3b Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 22:08:44 -0800 Subject: [PATCH 11/21] Add v prefix to version number --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index ac2de3d..59ae425 100644 --- a/main.go +++ b/main.go @@ -13,12 +13,12 @@ import ( var ( // Version is the main version number that is being run at the moment. - Version = "0.3.0" + Version = "v0.3.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 = "dev8" + VersionPrerelease = "dev9" // PluginVersion is used by the plugin set to allow Packer to recognize // what version this plugin is. From 870a6d1475ff2b146451bc8a3b3285adff9052ce Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 22:29:34 -0800 Subject: [PATCH 12/21] Remove prerelease suffix --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 59ae425..9a39fd0 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ var ( // 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 = "dev9" + VersionPrerelease = "" // PluginVersion is used by the plugin set to allow Packer to recognize // what version this plugin is. From 33cca1ae7dbac4855dfa491cf81972f1ec8229cc Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 9 Mar 2021 23:31:01 -0800 Subject: [PATCH 13/21] Fix issues with ubuntu example --- examples/ubuntu-2004.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/ubuntu-2004.json b/examples/ubuntu-2004.json index b06b3b3..0b0418a 100644 --- a/examples/ubuntu-2004.json +++ b/examples/ubuntu-2004.json @@ -35,9 +35,8 @@ "ssh_password": "ubuntu", "ssh_wait_timeout": "60000s", "ssh_timeout": "60000s", - "vm_name": "packer-ubuntu-2004-x86_64", + "vm_name": "packer-ubuntu-2004-x86_64 {{isotime}}", "vm_description": "Build time: {{isotime}}", - "disk_size": "20000", "vm_memory": "4096", "keep_vm": "always", "ssh_handshake_attempts": "10000" From dbff7f1ada173339100df3fa1b4dfaae066bd8ba Mon Sep 17 00:00:00 2001 From: Ariel Sandor Date: Mon, 15 Mar 2021 10:00:20 -0300 Subject: [PATCH 14/21] Replace conn master host > instance host --- builder/xenserver/common/step_type_boot_command.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/builder/xenserver/common/step_type_boot_command.go b/builder/xenserver/common/step_type_boot_command.go index d74f785..de04085 100644 --- a/builder/xenserver/common/step_type_boot_command.go +++ b/builder/xenserver/common/step_type_boot_command.go @@ -68,13 +68,15 @@ func (self *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB } location, err := c.client.Console.GetLocation(c.session, consoles[0]) + ui.Say(fmt.Sprintf("LOCATION: %s", location)) if err != nil { ui.Error(err.Error()) return multistep.ActionHalt } - + locationPieces := strings.SplitAfter(location, "/") + consoleHost := strings.TrimSuffix(locationPieces[2], "/") ui.Say("Connecting to the VM console VNC over xapi") - conn, err := net.Dial("tcp", fmt.Sprintf("%s:443", config.HostIp)) + conn, err := net.Dial("tcp", fmt.Sprintf("%s:443", consoleHost)) if err != nil { err := fmt.Errorf("Error connecting to VNC: %s", err) @@ -90,9 +92,9 @@ func (self *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB } tlsConn := tls.Client(conn, tlsConfig) - locationPieces := strings.SplitAfter(location, "/") + ui.Say(fmt.Sprintf("%s", strings.TrimSuffix(locationPieces[2], "/"))) consoleLocation := strings.TrimSpace(fmt.Sprintf("/%s", locationPieces[len(locationPieces)-1])) - httpReq := fmt.Sprintf("CONNECT %s HTTP/1.0\r\nCookie: session_id=%s\r\n\r\n", consoleLocation, 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) ui.Say(fmt.Sprintf("Making HTTP request to initiate VNC connection: %s", httpReq)) @@ -269,4 +271,4 @@ func vncSendString(c *vnc.ClientConn, original string) { // no matter what, wait a small period time.Sleep(50 * time.Millisecond) } -} +} \ No newline at end of file From fb1d23ca8e5c0e9bdddbc35e0dfbac21fb92b1e7 Mon Sep 17 00:00:00 2001 From: Ariel Sandor Date: Tue, 16 Mar 2021 09:09:39 -0300 Subject: [PATCH 15/21] Update step_type_boot_command.go --- builder/xenserver/common/step_type_boot_command.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builder/xenserver/common/step_type_boot_command.go b/builder/xenserver/common/step_type_boot_command.go index de04085..f169b20 100644 --- a/builder/xenserver/common/step_type_boot_command.go +++ b/builder/xenserver/common/step_type_boot_command.go @@ -68,14 +68,13 @@ func (self *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB } location, err := c.client.Console.GetLocation(c.session, consoles[0]) - ui.Say(fmt.Sprintf("LOCATION: %s", location)) if err != nil { ui.Error(err.Error()) return multistep.ActionHalt } locationPieces := strings.SplitAfter(location, "/") consoleHost := strings.TrimSuffix(locationPieces[2], "/") - ui.Say("Connecting to the VM console VNC over xapi") + ui.Say(fmt.Sprintf("Connecting to the VM console VNC over xapi via %s", consoleHost)) conn, err := net.Dial("tcp", fmt.Sprintf("%s:443", consoleHost)) if err != nil { @@ -271,4 +270,4 @@ func vncSendString(c *vnc.ClientConn, original string) { // no matter what, wait a small period time.Sleep(50 * time.Millisecond) } -} \ No newline at end of file +} From 64fb82b190799efe36813521a0b6e0e00adb6506 Mon Sep 17 00:00:00 2001 From: Ariel Sandor Date: Tue, 16 Mar 2021 09:13:24 -0300 Subject: [PATCH 16/21] Update step_type_boot_command.go --- builder/xenserver/common/step_type_boot_command.go | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/xenserver/common/step_type_boot_command.go b/builder/xenserver/common/step_type_boot_command.go index f169b20..00689ac 100644 --- a/builder/xenserver/common/step_type_boot_command.go +++ b/builder/xenserver/common/step_type_boot_command.go @@ -91,7 +91,6 @@ func (self *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateB } tlsConn := tls.Client(conn, tlsConfig) - ui.Say(fmt.Sprintf("%s", strings.TrimSuffix(locationPieces[2], "/"))) consoleLocation := strings.TrimSpace(fmt.Sprintf("/%s", locationPieces[len(locationPieces)-1])) 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) From aec4d8e24ca6a87d657cf3d8f3324f6f73eada18 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 23 Mar 2021 22:42:26 -0700 Subject: [PATCH 17/21] Add documentation for the network_names configuration option --- docs/builders/xenserver-iso.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/builders/xenserver-iso.html.markdown b/docs/builders/xenserver-iso.html.markdown index 270b364..69ad051 100644 --- a/docs/builders/xenserver-iso.html.markdown +++ b/docs/builders/xenserver-iso.html.markdown @@ -124,6 +124,10 @@ each category, the available options are alphabetized and described. regardless of success. "on_success" requests that the VM only be cleaned up if an artifact was produced. The latter is useful for debugging templates that fail. +* `network_names` (list) - A list of networks identified by their name label which + will be used for the VM during creation. The first network will correspond to the VM's + first network interface (VIF), the second will corespond to the second VIF and so on. + * `output_directory` (string) - This is the path to the directory where the resulting virtual machine will be created. This may be relative or absolute. If relative, the path is relative to the working directory when `packer` From 30f276e4da06335d598f74457aa24c75bf6b7799 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 23 Mar 2021 22:44:10 -0700 Subject: [PATCH 18/21] Use consistent naming for variable types --- docs/builders/xenserver-iso.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/builders/xenserver-iso.html.markdown b/docs/builders/xenserver-iso.html.markdown index 69ad051..1f8c0b3 100644 --- a/docs/builders/xenserver-iso.html.markdown +++ b/docs/builders/xenserver-iso.html.markdown @@ -124,7 +124,7 @@ each category, the available options are alphabetized and described. regardless of success. "on_success" requests that the VM only be cleaned up if an artifact was produced. The latter is useful for debugging templates that fail. -* `network_names` (list) - A list of networks identified by their name label which +* `network_names` (array of strings) - A list of networks identified by their name label which will be used for the VM during creation. The first network will correspond to the VM's first network interface (VIF), the second will corespond to the second VIF and so on. From 5a484e08d0db1f6ce4a31aa3ff82f6ad9d110e79 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 23 Mar 2021 23:36:34 -0700 Subject: [PATCH 19/21] Add a shared vm cleanup struct and function and ensure that the wait for ip step uses it --- .../xenserver/common/step_start_vm_paused.go | 26 ++-------------- builder/xenserver/common/step_wait_for_ip.go | 3 +- builder/xenserver/common/vm_cleanup.go | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 builder/xenserver/common/vm_cleanup.go diff --git a/builder/xenserver/common/step_start_vm_paused.go b/builder/xenserver/common/step_start_vm_paused.go index e046651..d383878 100644 --- a/builder/xenserver/common/step_start_vm_paused.go +++ b/builder/xenserver/common/step_start_vm_paused.go @@ -3,13 +3,14 @@ package common import ( "context" "fmt" - "log" "github.com/hashicorp/packer-plugin-sdk/multistep" "github.com/hashicorp/packer-plugin-sdk/packer" ) -type StepStartVmPaused struct{} +type StepStartVmPaused struct { + VmCleanup +} func (self *StepStartVmPaused) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { @@ -54,24 +55,3 @@ func (self *StepStartVmPaused) Run(ctx context.Context, state multistep.StateBag return multistep.ActionContinue } - -func (self *StepStartVmPaused) Cleanup(state multistep.StateBag) { - config := state.Get("commonconfig").(CommonConfig) - c := state.Get("client").(*Connection) - - if config.ShouldKeepVM(state) { - return - } - - uuid := state.Get("instance_uuid").(string) - instance, err := c.client.VM.GetByUUID(c.session, uuid) - if err != nil { - log.Printf(fmt.Sprintf("Unable to get VM from UUID '%s': %s", uuid, err.Error())) - return - } - - err = c.client.VM.HardShutdown(c.session, instance) - if err != nil { - log.Printf(fmt.Sprintf("Unable to force shutdown VM '%s': %s", uuid, err.Error())) - } -} diff --git a/builder/xenserver/common/step_wait_for_ip.go b/builder/xenserver/common/step_wait_for_ip.go index eedea3b..5272094 100644 --- a/builder/xenserver/common/step_wait_for_ip.go +++ b/builder/xenserver/common/step_wait_for_ip.go @@ -10,6 +10,7 @@ import ( ) type StepWaitForIP struct { + VmCleanup Chan <-chan string Timeout time.Duration } @@ -84,8 +85,6 @@ func (self *StepWaitForIP) Run(ctx context.Context, state multistep.StateBag) mu return multistep.ActionContinue } -func (self *StepWaitForIP) Cleanup(state multistep.StateBag) {} - func InstanceSSHIP(state multistep.StateBag) (string, error) { ip := state.Get("instance_ssh_address").(string) return ip, nil diff --git a/builder/xenserver/common/vm_cleanup.go b/builder/xenserver/common/vm_cleanup.go new file mode 100644 index 0000000..0c2c59c --- /dev/null +++ b/builder/xenserver/common/vm_cleanup.go @@ -0,0 +1,31 @@ +package common + +import ( + "fmt" + "log" + + "github.com/hashicorp/packer-plugin-sdk/multistep" +) + +type VmCleanup struct{} + +func (self *VmCleanup) Cleanup(state multistep.StateBag) { + config := state.Get("commonconfig").(CommonConfig) + c := state.Get("client").(*Connection) + + if config.ShouldKeepVM(state) { + return + } + + uuid := state.Get("instance_uuid").(string) + instance, err := c.client.VM.GetByUUID(c.session, uuid) + if err != nil { + log.Printf(fmt.Sprintf("Unable to get VM from UUID '%s': %s", uuid, err.Error())) + return + } + + err = c.client.VM.HardShutdown(c.session, instance) + if err != nil { + log.Printf(fmt.Sprintf("Unable to force shutdown VM '%s': %s", uuid, err.Error())) + } +} From fd4034839ff71a63f4e10768e9bed0eedb772eed Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 23 Mar 2021 23:36:50 -0700 Subject: [PATCH 20/21] Update go.mod to reflect currently supported go version --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2561521..e5166a2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/xenserver/packer-builder-xenserver -go 1.14 +go 1.16 require ( github.com/amfranz/go-xmlrpc-client v0.0.0-20190612172737-76858463955d From 8835d6069f534ffe9f0639b8b298d5e8caa86204 Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Tue, 30 Mar 2021 22:46:14 -0700 Subject: [PATCH 21/21] Update docs on and remove it from the examples in favor of the default behavior --- docs/builders/xenserver-iso.html.markdown | 10 +++------- examples/centos8.json | 1 - examples/ubuntu-2004.json | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/docs/builders/xenserver-iso.html.markdown b/docs/builders/xenserver-iso.html.markdown index 1f8c0b3..9c62c3f 100644 --- a/docs/builders/xenserver-iso.html.markdown +++ b/docs/builders/xenserver-iso.html.markdown @@ -150,13 +150,9 @@ each category, the available options are alphabetized and described. ``` * `shutdown_command` (string) - The command to use to gracefully shut down - the machine once all the provisioning is done. By default this is an empty - string, which tells Packer to just forcefully shut down the machine. - -* `shutdown_timeout` (string) - The amount of time to wait after executing - the `shutdown_command` for the virtual machine to actually shut down. - If it doesn't shut down in this time, it is an error. By default, the timeout - is "5m", or five minutes. + the machine once all the provisioning is done. If this is omitted, packer + will shut down the VM gracefully through the Xen api's vm shutdown command. Unless + you have special requirements this should typically be left to its default. * `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and maximum port to use for the SSH port on the host machine which is forwarded diff --git a/examples/centos8.json b/examples/centos8.json index ba3231e..ff8423b 100644 --- a/examples/centos8.json +++ b/examples/centos8.json @@ -30,7 +30,6 @@ "conversionvm":"true" }, "output_directory": "packer-centos-8.3-x86_64-xenserver", - "shutdown_command": "/sbin/shutdown", "ssh_username": "vagrant", "ssh_password": "vagrant", "ssh_wait_timeout": "10000s", diff --git a/examples/ubuntu-2004.json b/examples/ubuntu-2004.json index 0b0418a..0e45f27 100644 --- a/examples/ubuntu-2004.json +++ b/examples/ubuntu-2004.json @@ -30,7 +30,6 @@ "conversionvm":"true" }, "output_directory": "packer-ubuntu-2004-x86_64-xenserver", - "shutdown_command": "/sbin/shutdown", "ssh_username": "testuser", "ssh_password": "ubuntu", "ssh_wait_timeout": "60000s",