From 2104fcec691e5083818f8d1ac60fd5d9a56136c8 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 29 Jan 2016 21:47:36 +0000 Subject: [PATCH] builder/qemu: allow to specify time.Duration in special command Signed-off-by: Vasiliy Tolstov --- builder/qemu/step_type_boot_command.go | 14 ++++++++++++++ website/source/docs/builders/qemu.html.markdown | 3 +++ 2 files changed, 17 insertions(+) diff --git a/builder/qemu/step_type_boot_command.go b/builder/qemu/step_type_boot_command.go index cd1cd05ec..8b599e13f 100644 --- a/builder/qemu/step_type_boot_command.go +++ b/builder/qemu/step_type_boot_command.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net" + "regexp" "strings" "time" "unicode" @@ -154,6 +155,19 @@ func vncSendString(c *vnc.ClientConn, original string) { continue } + if strings.HasPrefix(original, "") { + re := regexp.MustCompile(`$`) + dstr := re.FindStringSubmatch(original) + if len(dstr) > 1 { + log.Printf("Special code %s found, sleeping", dstr[0]) + if dt, err := time.ParseDuration(dstr[1]); err == nil { + time.Sleep(dt) + original = original[len(dstr[0]):] + continue + } + } + } + for specialCode, specialValue := range special { if strings.HasPrefix(original, specialCode) { log.Printf("Special code '%s' found, replacing with: %d", specialCode, specialValue) diff --git a/website/source/docs/builders/qemu.html.markdown b/website/source/docs/builders/qemu.html.markdown index bc257efcf..4a6ce7c95 100644 --- a/website/source/docs/builders/qemu.html.markdown +++ b/website/source/docs/builders/qemu.html.markdown @@ -310,6 +310,9 @@ by the proper key: sending any additional keys. This is useful if you have to generally wait for the UI to update before typing more. +- ` ` - Add user defined time.Duration pause before sending any + additional keys. For example `` or `` + In addition to the special keys, each command to type is treated as a [configuration template](/docs/templates/configuration-templates.html). The available variables are: