Merge pull request #9682 from hashicorp/qemu_hcl_examples

Add qemu hcl examples
This commit is contained in:
Megan Marsh 2020-07-31 10:20:09 -07:00 committed by GitHub
commit cce424fdab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 20 deletions

View File

@ -86,17 +86,17 @@ type Config struct {
// accelerator you specified. When no accelerator is specified, Packer will try // accelerator you specified. When no accelerator is specified, Packer will try
// to use `kvm` if it is available but will default to `tcg` otherwise. // to use `kvm` if it is available but will default to `tcg` otherwise.
// //
// -> The `hax` accelerator has issues attaching CDROM ISOs. This is an // ~> The `hax` accelerator has issues attaching CDROM ISOs. This is an
// upstream issue which can be tracked // upstream issue which can be tracked
// [here](https://github.com/intel/haxm/issues/20). // [here](https://github.com/intel/haxm/issues/20).
// //
// -> The `hvf` and `whpx` accelerator are new and experimental as of // ~> The `hvf` and `whpx` accelerator are new and experimental as of
// [QEMU 2.12.0](https://wiki.qemu.org/ChangeLog/2.12#Host_support). // [QEMU 2.12.0](https://wiki.qemu.org/ChangeLog/2.12#Host_support).
// You may encounter issues unrelated to Packer when using these. You may need to // You may encounter issues unrelated to Packer when using these. You may need to
// add [ "-global", "virtio-pci.disable-modern=on" ] to `qemuargs` depending on the // add [ "-global", "virtio-pci.disable-modern=on" ] to `qemuargs` depending on the
// guest operating system. // guest operating system.
// //
// -> For `whpx`, note that [Stefan Weil's QEMU for Windows distribution](https://qemu.weilnetz.de/w64/) // ~> For `whpx`, note that [Stefan Weil's QEMU for Windows distribution](https://qemu.weilnetz.de/w64/)
// does not include WHPX support and users may need to compile or source a // does not include WHPX support and users may need to compile or source a
// build of QEMU for Windows themselves with WHPX support. // build of QEMU for Windows themselves with WHPX support.
Accelerator string `mapstructure:"accelerator" required:"false"` Accelerator string `mapstructure:"accelerator" required:"false"`
@ -208,7 +208,7 @@ type Config struct {
// as an empty string is ignored. All values after the switch are // as an empty string is ignored. All values after the switch are
// concatenated with no separator. // concatenated with no separator.
// //
// ~> **Warning:** The qemu command line allows extreme flexibility, so // ~> **Warning:** The qemu command line allows extreme flexibility, so
// beware of conflicting arguments causing failures of your run. For // beware of conflicting arguments causing failures of your run. For
// instance, using --no-acpi could break the ability to send power signal // instance, using --no-acpi could break the ability to send power signal
// type commands (e.g., shutdown -P now) to the virtual machine, thus // type commands (e.g., shutdown -P now) to the virtual machine, thus
@ -218,8 +218,8 @@ type Config struct {
// //
// The following shows a sample usage: // The following shows a sample usage:
// //
// In JSON:
// ```json // ```json
//{
// "qemuargs": [ // "qemuargs": [
// [ "-m", "1024M" ], // [ "-m", "1024M" ],
// [ "--no-acpi", "" ], // [ "--no-acpi", "" ],
@ -231,7 +231,21 @@ type Config struct {
// ], // ],
// [ "-device", "virtio-net,netdev=mynet0" ] // [ "-device", "virtio-net,netdev=mynet0" ]
// ] // ]
// } // ```
//
// In HCL2:
// ```hcl
// qemuargs = [
// [ "-m", "1024M" ],
// [ "--no-acpi", "" ],
// [
// "-netdev",
// "user,id=mynet0,",
// "hostfwd=hostip:hostport-guestip:guestport",
// ""
// ],
// [ "-device", "virtio-net,netdev=mynet0" ]
// ]
// ``` // ```
// //
// would produce the following (not including other defaults supplied by // would produce the following (not including other defaults supplied by
@ -243,7 +257,7 @@ type Config struct {
// virtio-net,netdev=mynet0" // virtio-net,netdev=mynet0"
// ``` // ```
// //
// ~> **Windows Users:** [QEMU for Windows](https://qemu.weilnetz.de/) // ~> **Windows Users:** [QEMU for Windows](https://qemu.weilnetz.de/)
// builds are available though an environmental variable does need to be // builds are available though an environmental variable does need to be
// set for QEMU for Windows to redirect stdout to the console instead of // set for QEMU for Windows to redirect stdout to the console instead of
// stdout.txt. // stdout.txt.
@ -258,15 +272,21 @@ type Config struct {
// You can also use the `SSHHostPort` template variable to produce a packer // You can also use the `SSHHostPort` template variable to produce a packer
// template that can be invoked by `make` in parallel: // template that can be invoked by `make` in parallel:
// //
// In JSON:
// ```json // ```json
//{
// "qemuargs": [ // "qemuargs": [
// [ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"], // [ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
// [ "-device", "virtio-net,netdev=forward,id=net0"] // [ "-device", "virtio-net,netdev=forward,id=net0"]
// ] // ]
// }
// ``` // ```
// //
// In HCL2:
// ```hcl
// qemuargs = [
// [ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
// [ "-device", "virtio-net,netdev=forward,id=net0"]
// ]
//
// `make -j 3 my-awesome-packer-templates` spawns 3 packer processes, each // `make -j 3 my-awesome-packer-templates` spawns 3 packer processes, each
// of which will bind to their own SSH port as determined by each process. // of which will bind to their own SSH port as determined by each process.
// This will also work with WinRM, just change the port forward in // This will also work with WinRM, just change the port forward in

View File

@ -26,14 +26,16 @@ necessary to run the virtual machine on KVM or Xen.
Here is a basic example. This example is functional so long as you fixup paths Here is a basic example. This example is functional so long as you fixup paths
to files, URLS for ISOs and checksums. to files, URLS for ISOs and checksums.
<Tabs>
<Tab heading="JSON">
```json ```json
{ {
"builders": [ "builders": [
{ {
"type": "qemu", "type": "qemu",
"iso_url": "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso", "iso_url": "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso",
"iso_checksum": "af4a1640c0c6f348c6c41f1ea9e192a2", "iso_checksum": "md5:af4a1640c0c6f348c6c41f1ea9e192a2",
"iso_checksum_type": "md5",
"output_directory": "output_centos_tdhtest", "output_directory": "output_centos_tdhtest",
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now", "shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
"disk_size": "5000M", "disk_size": "5000M",
@ -55,6 +57,37 @@ to files, URLS for ISOs and checksums.
} }
``` ```
</Tab>
<Tab heading="HCL2">
```hcl
source "qemu" "example" {
iso_url = "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso"
iso_checksum = "md5:af4a1640c0c6f348c6c41f1ea9e192a2"
output_directory = "output_centos_tdhtest"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
disk_size = "5000M"
format = "qcow2"
accelerator = "kvm"
http_directory = "path/to/httpdir"
ssh_username = "root"
ssh_password = "s0m3password"
ssh_timeout = "20m"
vm_name = "tdhtest"
net_device = "virtio-net"
disk_interface = "virtio"
boot_wait = "10s"
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter><wait>"]
}
build {
sources = ["source.qemu.example"]
}
```
</Tab>
</Tabs>
This is an example only, and will time out waiting for SSH because we have not This is an example only, and will time out waiting for SSH because we have not
provided a kickstart file. You must add a valid kickstart file to the provided a kickstart file. You must add a valid kickstart file to the
"http_directory" and then provide the file in the "boot_command" in order for "http_directory" and then provide the file in the "boot_command" in order for

View File

@ -9,17 +9,17 @@
accelerator you specified. When no accelerator is specified, Packer will try accelerator you specified. When no accelerator is specified, Packer will try
to use `kvm` if it is available but will default to `tcg` otherwise. to use `kvm` if it is available but will default to `tcg` otherwise.
-&gt; The `hax` accelerator has issues attaching CDROM ISOs. This is an ~> The `hax` accelerator has issues attaching CDROM ISOs. This is an
upstream issue which can be tracked upstream issue which can be tracked
[here](https://github.com/intel/haxm/issues/20). [here](https://github.com/intel/haxm/issues/20).
-&gt; The `hvf` and `whpx` accelerator are new and experimental as of ~> The `hvf` and `whpx` accelerator are new and experimental as of
[QEMU 2.12.0](https://wiki.qemu.org/ChangeLog/2.12#Host_support). [QEMU 2.12.0](https://wiki.qemu.org/ChangeLog/2.12#Host_support).
You may encounter issues unrelated to Packer when using these. You may need to You may encounter issues unrelated to Packer when using these. You may need to
add [ "-global", "virtio-pci.disable-modern=on" ] to `qemuargs` depending on the add [ "-global", "virtio-pci.disable-modern=on" ] to `qemuargs` depending on the
guest operating system. guest operating system.
-&gt; For `whpx`, note that [Stefan Weil's QEMU for Windows distribution](https://qemu.weilnetz.de/w64/) ~> For `whpx`, note that [Stefan Weil's QEMU for Windows distribution](https://qemu.weilnetz.de/w64/)
does not include WHPX support and users may need to compile or source a does not include WHPX support and users may need to compile or source a
build of QEMU for Windows themselves with WHPX support. build of QEMU for Windows themselves with WHPX support.
@ -131,7 +131,7 @@
as an empty string is ignored. All values after the switch are as an empty string is ignored. All values after the switch are
concatenated with no separator. concatenated with no separator.
~&gt; **Warning:** The qemu command line allows extreme flexibility, so ~> **Warning:** The qemu command line allows extreme flexibility, so
beware of conflicting arguments causing failures of your run. For beware of conflicting arguments causing failures of your run. For
instance, using --no-acpi could break the ability to send power signal instance, using --no-acpi could break the ability to send power signal
type commands (e.g., shutdown -P now) to the virtual machine, thus type commands (e.g., shutdown -P now) to the virtual machine, thus
@ -141,8 +141,8 @@
The following shows a sample usage: The following shows a sample usage:
In JSON:
```json ```json
{
"qemuargs": [ "qemuargs": [
[ "-m", "1024M" ], [ "-m", "1024M" ],
[ "--no-acpi", "" ], [ "--no-acpi", "" ],
@ -154,7 +154,21 @@
], ],
[ "-device", "virtio-net,netdev=mynet0" ] [ "-device", "virtio-net,netdev=mynet0" ]
] ]
} ```
In HCL2:
```hcl
qemuargs = [
[ "-m", "1024M" ],
[ "--no-acpi", "" ],
[
"-netdev",
"user,id=mynet0,",
"hostfwd=hostip:hostport-guestip:guestport",
""
],
[ "-device", "virtio-net,netdev=mynet0" ]
]
``` ```
would produce the following (not including other defaults supplied by would produce the following (not including other defaults supplied by
@ -166,7 +180,7 @@
virtio-net,netdev=mynet0" virtio-net,netdev=mynet0"
``` ```
~&gt; **Windows Users:** [QEMU for Windows](https://qemu.weilnetz.de/) ~> **Windows Users:** [QEMU for Windows](https://qemu.weilnetz.de/)
builds are available though an environmental variable does need to be builds are available though an environmental variable does need to be
set for QEMU for Windows to redirect stdout to the console instead of set for QEMU for Windows to redirect stdout to the console instead of
stdout.txt. stdout.txt.
@ -181,15 +195,21 @@
You can also use the `SSHHostPort` template variable to produce a packer You can also use the `SSHHostPort` template variable to produce a packer
template that can be invoked by `make` in parallel: template that can be invoked by `make` in parallel:
In JSON:
```json ```json
{
"qemuargs": [ "qemuargs": [
[ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"], [ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
[ "-device", "virtio-net,netdev=forward,id=net0"] [ "-device", "virtio-net,netdev=forward,id=net0"]
] ]
}
``` ```
In HCL2:
```hcl
qemuargs = [
[ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
[ "-device", "virtio-net,netdev=forward,id=net0"]
]
`make -j 3 my-awesome-packer-templates` spawns 3 packer processes, each `make -j 3 my-awesome-packer-templates` spawns 3 packer processes, each
of which will bind to their own SSH port as determined by each process. of which will bind to their own SSH port as determined by each process.
This will also work with WinRM, just change the port forward in This will also work with WinRM, just change the port forward in