Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
aefb947f
Commit
aefb947f
authored
Jun 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: Support <wait>, send proper keycodes
parent
6d610f1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
3 deletions
+33
-3
builder/vmware/step_type_boot_command.go
builder/vmware/step_type_boot_command.go
+33
-3
No files found.
builder/vmware/step_type_boot_command.go
View file @
aefb947f
package
vmware
import
(
"bytes"
"fmt"
"github.com/mitchellh/go-vnc"
"github.com/mitchellh/multistep"
...
...
@@ -8,6 +9,7 @@ import (
"log"
"net"
"strings"
"text/template"
"time"
"unicode"
"unicode/utf8"
...
...
@@ -15,10 +17,17 @@ import (
const
KeyLeftShift
uint32
=
0xFFE1
type
bootCommandTemplateData
struct
{
HTTPIP
string
HTTPPort
int
Name
string
}
// This step "types" the boot command into the VM over VNC.
//
// Uses:
// config *config
// http_port int
// ui packer.Ui
// vnc_port uint
//
...
...
@@ -28,6 +37,7 @@ type stepTypeBootCommand struct{}
func
(
s
*
stepTypeBootCommand
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
httpPort
:=
state
[
"http_port"
]
.
(
int
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vncPort
:=
state
[
"vnc_port"
]
.
(
uint
)
...
...
@@ -46,10 +56,21 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
}
defer
c
.
Close
()
log
.
Printf
(
"Connecting to VNC desktop: %s"
,
c
.
DesktopName
)
log
.
Printf
(
"Connected to VNC desktop: %s"
,
c
.
DesktopName
)
tplData
:=
&
bootCommandTemplateData
{
"127.0.0.1"
,
httpPort
,
config
.
VMName
,
}
ui
.
Say
(
"Typing the boot command over VNC..."
)
for
_
,
command
:=
range
config
.
BootCommand
{
vncSendString
(
c
,
command
)
var
buf
bytes
.
Buffer
t
:=
template
.
Must
(
template
.
New
(
"boot"
)
.
Parse
(
command
))
t
.
Execute
(
&
buf
,
tplData
)
vncSendString
(
c
,
buf
.
String
())
}
return
multistep
.
ActionContinue
...
...
@@ -63,11 +84,20 @@ func vncSendString(c *vnc.ClientConn, original string) {
special
[
"<return>"
]
=
0xFF0D
special
[
"<esc>"
]
=
0xFF1B
shiftedChars
:=
"~!@#$%^&*()_+{}|:
\"
<>?"
// TODO(mitchellh): Ripe for optimizations of some point, perhaps.
for
len
(
original
)
>
0
{
var
keyCode
uint32
keyShift
:=
false
if
strings
.
HasPrefix
(
original
,
"<wait>"
)
{
log
.
Printf
(
"Special code '<wait>' found, sleeping one second"
)
time
.
Sleep
(
1
*
time
.
Second
)
original
=
original
[
len
(
"<wait>"
)
:
]
continue
}
for
specialCode
,
specialValue
:=
range
special
{
if
strings
.
HasPrefix
(
original
,
specialCode
)
{
log
.
Printf
(
"Special code '%s' found, replacing with: %d"
,
specialCode
,
specialValue
)
...
...
@@ -81,7 +111,7 @@ func vncSendString(c *vnc.ClientConn, original string) {
r
,
size
:=
utf8
.
DecodeRuneInString
(
original
)
original
=
original
[
size
:
]
keyCode
=
uint32
(
r
)
keyShift
=
unicode
.
IsUpper
(
r
)
keyShift
=
unicode
.
IsUpper
(
r
)
||
strings
.
ContainsRune
(
shiftedChars
,
r
)
log
.
Printf
(
"Sending char '%c', code %d, shift %v"
,
r
,
keyCode
,
keyShift
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment