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
6d83ef54
Commit
6d83ef54
authored
Dec 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware/iso: move VMX methods out to the common
parent
33452c2d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
10 additions
and
115 deletions
+10
-115
builder/vmware/iso/ssh.go
builder/vmware/iso/ssh.go
+2
-1
builder/vmware/iso/step_clean_vmx.go
builder/vmware/iso/step_clean_vmx.go
+3
-2
builder/vmware/iso/step_configure_vnc.go
builder/vmware/iso/step_configure_vnc.go
+3
-2
builder/vmware/iso/step_create_vmx.go
builder/vmware/iso/step_create_vmx.go
+2
-1
builder/vmware/iso/vmx.go
builder/vmware/iso/vmx.go
+0
-70
builder/vmware/iso/vmx_test.go
builder/vmware/iso/vmx_test.go
+0
-39
No files found.
builder/vmware/iso/ssh.go
View file @
6d83ef54
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/communicator/ssh"
"io/ioutil"
"io/ioutil"
"log"
"log"
...
@@ -28,7 +29,7 @@ func sshAddress(state multistep.StateBag) (string, error) {
...
@@ -28,7 +29,7 @@ func sshAddress(state multistep.StateBag) (string, error) {
return
""
,
err
return
""
,
err
}
}
vmxData
:=
ParseVMX
(
string
(
vmxBytes
))
vmxData
:=
vmwcommon
.
ParseVMX
(
string
(
vmxBytes
))
var
ok
bool
var
ok
bool
macAddress
:=
""
macAddress
:=
""
...
...
builder/vmware/iso/step_clean_vmx.go
View file @
6d83ef54
...
@@ -3,6 +3,7 @@ package iso
...
@@ -3,6 +3,7 @@ package iso
import
(
import
(
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"io/ioutil"
"log"
"log"
...
@@ -66,7 +67,7 @@ func (s stepCleanVMX) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -66,7 +67,7 @@ func (s stepCleanVMX) Run(state multistep.StateBag) multistep.StepAction {
}
}
// Rewrite the VMX
// Rewrite the VMX
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
if
err
:=
vmwcommon
.
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error writing VMX: %s"
,
err
))
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error writing VMX: %s"
,
err
))
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
...
@@ -88,5 +89,5 @@ func (stepCleanVMX) readVMX(vmxPath string) (map[string]string, error) {
...
@@ -88,5 +89,5 @@ func (stepCleanVMX) readVMX(vmxPath string) (map[string]string, error) {
return
nil
,
err
return
nil
,
err
}
}
return
ParseVMX
(
string
(
vmxBytes
)),
nil
return
vmwcommon
.
ParseVMX
(
string
(
vmxBytes
)),
nil
}
}
builder/vmware/iso/step_configure_vnc.go
View file @
6d83ef54
...
@@ -3,6 +3,7 @@ package iso
...
@@ -3,6 +3,7 @@ package iso
import
(
import
(
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"io/ioutil"
"log"
"log"
...
@@ -84,11 +85,11 @@ func (s *stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -84,11 +85,11 @@ func (s *stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
log
.
Printf
(
"Found available VNC port: %d"
,
vncPort
)
log
.
Printf
(
"Found available VNC port: %d"
,
vncPort
)
vmxData
:=
ParseVMX
(
string
(
vmxBytes
))
vmxData
:=
vmwcommon
.
ParseVMX
(
string
(
vmxBytes
))
vmxData
[
"remotedisplay.vnc.enabled"
]
=
"TRUE"
vmxData
[
"remotedisplay.vnc.enabled"
]
=
"TRUE"
vmxData
[
"remotedisplay.vnc.port"
]
=
fmt
.
Sprintf
(
"%d"
,
vncPort
)
vmxData
[
"remotedisplay.vnc.port"
]
=
fmt
.
Sprintf
(
"%d"
,
vncPort
)
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
if
err
:=
vmwcommon
.
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error writing VMX data: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error writing VMX data: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
...
...
builder/vmware/iso/step_create_vmx.go
View file @
6d83ef54
...
@@ -3,6 +3,7 @@ package iso
...
@@ -3,6 +3,7 @@ package iso
import
(
import
(
"fmt"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"io/ioutil"
"os"
"os"
...
@@ -90,7 +91,7 @@ func (s *stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -90,7 +91,7 @@ func (s *stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
}
}
vmxPath
:=
filepath
.
Join
(
vmxDir
,
config
.
VMName
+
".vmx"
)
vmxPath
:=
filepath
.
Join
(
vmxDir
,
config
.
VMName
+
".vmx"
)
if
err
:=
WriteVMX
(
vmxPath
,
ParseVMX
(
vmxContents
));
err
!=
nil
{
if
err
:=
vmwcommon
.
WriteVMX
(
vmxPath
,
vmwcommon
.
ParseVMX
(
vmxContents
));
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating VMX file: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error creating VMX file: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
...
...
builder/vmware/iso/vmx.go
deleted
100644 → 0
View file @
33452c2d
package
iso
import
(
"bytes"
"fmt"
"io"
"log"
"os"
"regexp"
"sort"
"strings"
)
// ParseVMX parses the keys and values from a VMX file and returns
// them as a Go map.
func
ParseVMX
(
contents
string
)
map
[
string
]
string
{
results
:=
make
(
map
[
string
]
string
)
lineRe
:=
regexp
.
MustCompile
(
`^(.+?)\s*=\s*"(.*?)"\s*$`
)
for
_
,
line
:=
range
strings
.
Split
(
contents
,
"
\n
"
)
{
matches
:=
lineRe
.
FindStringSubmatch
(
line
)
if
matches
==
nil
{
continue
}
key
:=
strings
.
ToLower
(
matches
[
1
])
results
[
key
]
=
matches
[
2
]
}
return
results
}
// EncodeVMX takes a map and turns it into valid VMX contents.
func
EncodeVMX
(
contents
map
[
string
]
string
)
string
{
var
buf
bytes
.
Buffer
i
:=
0
keys
:=
make
([]
string
,
len
(
contents
))
for
k
,
_
:=
range
contents
{
keys
[
i
]
=
k
i
++
}
sort
.
Strings
(
keys
)
for
_
,
k
:=
range
keys
{
buf
.
WriteString
(
fmt
.
Sprintf
(
"%s =
\"
%s
\"\n
"
,
k
,
contents
[
k
]))
}
return
buf
.
String
()
}
// WriteVMX takes a path to a VMX file and contents in the form of a
// map and writes it out.
func
WriteVMX
(
path
string
,
data
map
[
string
]
string
)
(
err
error
)
{
log
.
Printf
(
"Writing VMX to: %s"
,
path
)
f
,
err
:=
os
.
Create
(
path
)
if
err
!=
nil
{
return
}
defer
f
.
Close
()
var
buf
bytes
.
Buffer
buf
.
WriteString
(
EncodeVMX
(
data
))
if
_
,
err
=
io
.
Copy
(
f
,
&
buf
);
err
!=
nil
{
return
}
return
}
builder/vmware/iso/vmx_test.go
deleted
100644 → 0
View file @
33452c2d
package
iso
import
"testing"
func
TestParseVMX
(
t
*
testing
.
T
)
{
contents
:=
`
.encoding = "UTF-8"
config.version = "8"
`
results
:=
ParseVMX
(
contents
)
if
len
(
results
)
!=
2
{
t
.
Fatalf
(
"not correct number of results: %d"
,
len
(
results
))
}
if
results
[
".encoding"
]
!=
"UTF-8"
{
t
.
Errorf
(
"invalid .encoding: %s"
,
results
[
".encoding"
])
}
if
results
[
"config.version"
]
!=
"8"
{
t
.
Errorf
(
"invalid config.version: %s"
,
results
[
"config.version"
])
}
}
func
TestEncodeVMX
(
t
*
testing
.
T
)
{
contents
:=
map
[
string
]
string
{
".encoding"
:
"UTF-8"
,
"config.version"
:
"8"
,
}
expected
:=
`.encoding = "UTF-8"
config.version = "8"
`
result
:=
EncodeVMX
(
contents
)
if
result
!=
expected
{
t
.
Errorf
(
"invalid results: %s"
,
result
)
}
}
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