From 9c53df1e0e01a2c46cc29f7ddee41a573c594d4c Mon Sep 17 00:00:00 2001 From: Taliesin Sisson Date: Sun, 31 Jul 2016 19:18:11 +0100 Subject: [PATCH] Add special key modifiers to log output when used. Update documentation to include new key modifiers. --- .../hyperv/common/step_type_boot_command.go | 24 +- .../docs/builders/hyperv-iso.html.markdown | 245 ++++++++++-------- 2 files changed, 151 insertions(+), 118 deletions(-) diff --git a/builder/hyperv/common/step_type_boot_command.go b/builder/hyperv/common/step_type_boot_command.go index 8468d1115..e9a1bc4a4 100644 --- a/builder/hyperv/common/step_type_boot_command.go +++ b/builder/hyperv/common/step_type_boot_command.go @@ -2,7 +2,7 @@ package common import ( "fmt" - //"log" + "log" "strings" "unicode" "unicode/utf8" @@ -162,77 +162,89 @@ func scancodes(message string) []string { if strings.HasPrefix(message, "") { scancode = []string{"38"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: 38") } if strings.HasPrefix(message, "") { scancode = []string{"1d"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: 1d") } if strings.HasPrefix(message, "") { scancode = []string{"2a"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: 2a") } if strings.HasPrefix(message, "") { scancode = []string{"b8"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: b8") } if strings.HasPrefix(message, "") { scancode = []string{"9d"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: 9d") } if strings.HasPrefix(message, "") { scancode = []string{"aa"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: aa") } if strings.HasPrefix(message, "") { scancode = []string{"e038"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: e038") } if strings.HasPrefix(message, "") { scancode = []string{"e01d"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: e01d") } if strings.HasPrefix(message, "") { scancode = []string{"36"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: 36") } if strings.HasPrefix(message, "") { scancode = []string{"e0b8"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: e0b8") } if strings.HasPrefix(message, "") { scancode = []string{"e09d"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: e09d") } if strings.HasPrefix(message, "") { scancode = []string{"b6"} message = message[len(""):] + log.Printf("Special code '' found, replacing with: b6") } if strings.HasPrefix(message, "") { - //log.Printf("Special code found, will sleep 1 second at this point.") + log.Printf("Special code found, will sleep 1 second at this point.") scancode = []string{"wait"} message = message[len(""):] } if strings.HasPrefix(message, "") { - //log.Printf("Special code found, will sleep 5 seconds at this point.") + log.Printf("Special code found, will sleep 5 seconds at this point.") scancode = []string{"wait5"} message = message[len(""):] } if strings.HasPrefix(message, "") { - //log.Printf("Special code found, will sleep 10 seconds at this point.") + log.Printf("Special code found, will sleep 10 seconds at this point.") scancode = []string{"wait10"} message = message[len(""):] } @@ -240,7 +252,7 @@ func scancodes(message string) []string { if scancode == nil { for specialCode, specialValue := range special { if strings.HasPrefix(message, specialCode) { - //log.Printf("Special code '%s' found, replacing with: %s", specialCode, specialValue) + log.Printf("Special code '%s' found, replacing with: %s", specialCode, specialValue) scancode = specialValue message = message[len(specialCode):] break @@ -266,7 +278,7 @@ func scancodes(message string) []string { } scancode = append(scancode, fmt.Sprintf("%02x", scancodeInt+0x80)) - //log.Printf("Sending char '%c', code '%v', shift %v", r, scancode, keyShift) + log.Printf("Sending char '%c', code '%v', shift %v", r, scancode, keyShift) } result = append(result, scancode...) diff --git a/website/source/docs/builders/hyperv-iso.html.markdown b/website/source/docs/builders/hyperv-iso.html.markdown index ceb946136..2d030d7c3 100644 --- a/website/source/docs/builders/hyperv-iso.html.markdown +++ b/website/source/docs/builders/hyperv-iso.html.markdown @@ -1,8 +1,8 @@ --- -layout: "docs" -page_title: "HyperV Builder (from an ISO)" description: |- The HyperV Packer builder is able to create HyperV virtual machines and export them. +layout: "docs" +page_title: "HyperV Builder (from an ISO)" --- # HyperV Builder (from an ISO) @@ -59,126 +59,126 @@ can be configured for this builder. ### Required: -* `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO - files are so large, this is required and Packer will verify it prior - to booting a virtual machine with the ISO attached. The type of the - checksum is specified with `iso_checksum_type`, documented below. +- `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO + files are so large, this is required and Packer will verify it prior + to booting a virtual machine with the ISO attached. The type of the + checksum is specified with `iso_checksum_type`, documented below. -* `iso_checksum_type` (string) - The type of the checksum specified in - `iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or - "sha512" currently. While "none" will skip checksumming, this is not - recommended since ISO files are generally large and corruption does happen - from time to time. +- `iso_checksum_type` (string) - The type of the checksum specified in + `iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or + "sha512" currently. While "none" will skip checksumming, this is not + recommended since ISO files are generally large and corruption does happen + from time to time. -* `iso_url` (string) - A URL to the ISO containing the installation image. - This URL can be either an HTTP URL or a file URL (or path to a file). - If this is an HTTP URL, Packer will download it and cache it between - runs. +- `iso_url` (string) - A URL to the ISO containing the installation image. + This URL can be either an HTTP URL or a file URL (or path to a file). + If this is an HTTP URL, Packer will download it and cache it between + runs. ### Optional: -* `boot_command` (array of strings) - This is an array of commands to type - when the virtual machine is first booted. The goal of these commands should - be to type just enough to initialize the operating system installer. Special - keys can be typed as well, and are covered in the section below on the boot - command. If this is not specified, it is assumed the installer will start - itself. +- `boot_command` (array of strings) - This is an array of commands to type + when the virtual machine is first booted. The goal of these commands should + be to type just enough to initialize the operating system installer. Special + keys can be typed as well, and are covered in the section below on the boot + command. If this is not specified, it is assumed the installer will start + itself. -* `boot_wait` (string) - The time to wait after booting the initial virtual - machine before typing the `boot_command`. The value of this should be - a duration. Examples are "5s" and "1m30s" which will cause Packer to wait - five seconds and one minute 30 seconds, respectively. If this isn't specified, - the default is 10 seconds. +- `boot_wait` (string) - The time to wait after booting the initial virtual + machine before typing the `boot_command`. The value of this should be + a duration. Examples are "5s" and "1m30s" which will cause Packer to wait + five seconds and one minute 30 seconds, respectively. If this isn't specified, + the default is 10 seconds. -* `cpu` (int) - The number of cpus the virtual machine should use. If this isn't specified, - the default is 1 cpu. +- `cpu` (int) - The number of cpus the virtual machine should use. If this isn't specified, + the default is 1 cpu. -* `disk_size` (integer) - The size, in megabytes, of the hard disk to create - for the VM. By default, this is 40000 (about 40 GB). +- `disk_size` (integer) - The size, in megabytes, of the hard disk to create + for the VM. By default, this is 40000 (about 40 GB). -* `enable_secure_boot` (bool) - If true enable secure boot for virtual machine. - This defaults to false. +- `enable_secure_boot` (bool) - If true enable secure boot for virtual machine. + This defaults to false. -* `floppy_files` (array of strings) - A list of files to place onto a floppy - disk that is attached when the VM is booted. This is most useful - for unattended Windows installs, which look for an `Autounattend.xml` file - on removable media. By default, no floppy will be attached. All files - listed in this setting get placed into the root directory of the floppy - and the floppy is attached as the first floppy device. Currently, no - support exists for creating sub-directories on the floppy. Wildcard - characters (*, ?, and []) are allowed. Directory names are also allowed, - which will add all the files found in the directory to the floppy. +- `floppy_files` (array of strings) - A list of files to place onto a floppy + disk that is attached when the VM is booted. This is most useful + for unattended Windows installs, which look for an `Autounattend.xml` file + on removable media. By default, no floppy will be attached. All files + listed in this setting get placed into the root directory of the floppy + and the floppy is attached as the first floppy device. Currently, no + support exists for creating sub-directories on the floppy. Wildcard + characters (*, ?, and []) are allowed. Directory names are also allowed, + which will add all the files found in the directory to the floppy. -* `generation` (int) - The HyperV generation for the virtual machine. By - default, this is 1. Generation 2 HyperV virtual machines do not support - floppy drives. In this scenario use secondary_iso_images instead. Hard - drives and dvd drives will also be scsi and not ide. +- `generation` (int) - The HyperV generation for the virtual machine. By + default, this is 1. Generation 2 HyperV virtual machines do not support + floppy drives. In this scenario use secondary_iso_images instead. Hard + drives and dvd drives will also be scsi and not ide. -* `http_directory` (string) - Path to a directory to serve using an HTTP - server. The files in this directory will be available over HTTP that will - be requestable from the virtual machine. This is useful for hosting - kickstart files and so on. By default this is "", which means no HTTP - server will be started. The address and port of the HTTP server will be - available as variables in `boot_command`. This is covered in more detail - below. +- `http_directory` (string) - Path to a directory to serve using an HTTP + server. The files in this directory will be available over HTTP that will + be requestable from the virtual machine. This is useful for hosting + kickstart files and so on. By default this is "", which means no HTTP + server will be started. The address and port of the HTTP server will be + available as variables in `boot_command`. This is covered in more detail + below. -* `http_port_min` and `http_port_max` (integer) - These are the minimum and - maximum port to use for the HTTP server started to serve the `http_directory`. - Because Packer often runs in parallel, Packer will choose a randomly available - port in this range to run the HTTP server. If you want to force the HTTP - server to be on one port, make this minimum and maximum port the same. - By default the values are 8000 and 9000, respectively. +- `http_port_min` and `http_port_max` (integer) - These are the minimum and + maximum port to use for the HTTP server started to serve the `http_directory`. + Because Packer often runs in parallel, Packer will choose a randomly available + port in this range to run the HTTP server. If you want to force the HTTP + server to be on one port, make this minimum and maximum port the same. + By default the values are 8000 and 9000, respectively. -* `ip_address_timeout` (string) - The time to wait after creating the initial virtual - machine and waiting for an ip address before assuming there is an error in the process. - The value of this should be a duration. Examples are "5s" and "1m30s" which will cause Packer to wait - five seconds and one minute 30 seconds, respectively. If this isn't specified, - the default is 10 seconds. +- `ip_address_timeout` (string) - The time to wait after creating the initial virtual + machine and waiting for an ip address before assuming there is an error in the process. + The value of this should be a duration. Examples are "5s" and "1m30s" which will cause Packer to wait + five seconds and one minute 30 seconds, respectively. If this isn't specified, + the default is 10 seconds. -* `iso_urls` (array of strings) - Multiple URLs for the ISO to download. - Packer will try these in order. If anything goes wrong attempting to download - or while downloading a single URL, it will move on to the next. All URLs - must point to the same file (same checksum). By default this is empty - and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified. +- `iso_urls` (array of strings) - Multiple URLs for the ISO to download. + Packer will try these in order. If anything goes wrong attempting to download + or while downloading a single URL, it will move on to the next. All URLs + must point to the same file (same checksum). By default this is empty + and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified. -* `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` - is executed. This directory must not exist or be empty prior to running the builder. - By default this is "output-BUILDNAME" where "BUILDNAME" is the name - of the build. +- `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` + is executed. This directory must not exist or be empty prior to running the builder. + By default this is "output-BUILDNAME" where "BUILDNAME" is the name + of the build. * `secondary_iso_images` (array of strings) - A list of files to place onto a floppy - disk that is attached when the VM is booted. This is most useful - for unattended Windows installs, which look for an `Autounattend.xml` file - on removable media. By default, no floppy will be attached. All files - listed in this setting get placed into the root directory of the floppy - and the floppy is attached as the first floppy device. Currently, no - support exists for creating sub-directories on the floppy. Wildcard - characters (*, ?, and []) are allowed. Directory names are also allowed, - which will add all the files found in the directory to the floppy. + disk that is attached when the VM is booted. This is most useful + for unattended Windows installs, which look for an `Autounattend.xml` file + on removable media. By default, no floppy will be attached. All files + listed in this setting get placed into the root directory of the floppy + and the floppy is attached as the first floppy device. Currently, no + support exists for creating sub-directories on the floppy. Wildcard + characters (*, ?, and []) are allowed. Directory names are also allowed, + which will add all the files found in the directory to the floppy. -* `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 unless a shutdown command takes place inside script so this may - safely be omitted. If one or more scripts require a reboot it is suggested to leave this blank - since reboots may fail and specify the final shutdown command in your last script. +- `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 unless a shutdown command takes place inside script so this may + safely be omitted. If one or more scripts require a reboot it is suggested to leave this blank + since reboots may fail and specify the final shutdown command in your last script. -* `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. +- `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. -* `skip_compaction` (bool) - If true skip compacting the hard disk for virtual machine when - exporting. This defaults to false. +- `skip_compaction` (bool) - If true skip compacting the hard disk for virtual machine when + exporting. This defaults to false. -* `switch_name` (string) - The name of the switch to connect the virtual machine to. Be defaulting - this to an empty string, Packer will try to determine the switch to use by looking for - external switch that is up and running. +- `switch_name` (string) - The name of the switch to connect the virtual machine to. Be defaulting + this to an empty string, Packer will try to determine the switch to use by looking for + external switch that is up and running. -* `vm_name` (string) - This is the name of the virtua machine for the new virtual - machine, without the file extension. By default this is "packer-BUILDNAME", - where "BUILDNAME" is the name of the build. +- `vm_name` (string) - This is the name of the virtua machine for the new virtual + machine, without the file extension. By default this is "packer-BUILDNAME", + where "BUILDNAME" is the name of the build. ## Boot Command @@ -196,30 +196,51 @@ to the machine, simulating a human actually typing the keyboard. There are a set of special keys available. If these are in your boot command, they will be replaced by the proper key: -* `` - Backspace +- `` - Backspace -* `` - Delete +- `` - Delete -* `` and `` - Simulates an actual "enter" or "return" keypress. +- `` and `` - Simulates an actual "enter" or "return" keypress. -* `` - Simulates pressing the escape key. +- `` - Simulates pressing the escape key. -* `` - Simulates pressing the tab key. +- `` - Simulates pressing the tab key. -* `` - `` - Simulates pressing a function key. +- `` - `` - Simulates pressing a function key. -* `` `` `` `` - Simulates pressing an arrow key. +- `` `` `` `` - Simulates pressing an arrow key. -* `` - Simulates pressing the spacebar. +- `` - Simulates pressing the spacebar. -* `` - Simulates pressing the insert key. +- `` - Simulates pressing the insert key. -* `` `` - Simulates pressing the home and end keys. +- `` `` - Simulates pressing the home and end keys. -* `` `` - Simulates pressing the page up and page down keys. +- `` `` - Simulates pressing the page up and page down keys. -* `` `` `` - Adds a 1, 5 or 10 second pause before sending any additional keys. This - is useful if you have to generally wait for the UI to update before typing more. +- `` `` - Simulates pressing the alt key. + +- `` `` - Simulates pressing the ctrl key. + +- `` `` - Simulates pressing the shift key. + +- `` `` - Simulates pressing and holding the alt key. + +- `` `` - Simulates pressing and holding the ctrl key. + +- `` `` - Simulates pressing and holding the shift key. + +- `` `` - Simulates releasing a held alt key. + +- `` `` - Simulates releasing a held ctrl key. + +- `` `` - Simulates releasing a held shift key. + +- `` `` `` - Adds a 1, 5 or 10 second pause before + sending any additional keys. This is useful if you have to generally wait + for the UI to update before typing more. + +When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them, otherwise they will be held down until the machine reboots. Use lowercase characters as well inside modifiers. For example: to simulate ctrl+c use `c`. In addition to the special keys, each command to type is treated as a [configuration template](/docs/templates/configuration-templates.html).