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
33452c2d
Commit
33452c2d
authored
Dec 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: add more stuff to common
parent
d73844c3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
3 deletions
+130
-3
builder/vmware/common/step_configure_vmx.go
builder/vmware/common/step_configure_vmx.go
+1
-1
builder/vmware/common/step_configure_vmx_test.go
builder/vmware/common/step_configure_vmx_test.go
+1
-1
builder/vmware/common/step_test.go
builder/vmware/common/step_test.go
+17
-0
builder/vmware/common/vmx.go
builder/vmware/common/vmx.go
+70
-0
builder/vmware/common/vmx_test.go
builder/vmware/common/vmx_test.go
+39
-0
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+2
-1
No files found.
builder/vmware/
iso
/step_configure_vmx.go
→
builder/vmware/
common
/step_configure_vmx.go
View file @
33452c2d
package
iso
package
common
import
(
"fmt"
...
...
builder/vmware/
iso
/step_configure_vmx_test.go
→
builder/vmware/
common
/step_configure_vmx_test.go
View file @
33452c2d
package
iso
package
common
import
(
"io/ioutil"
...
...
builder/vmware/common/step_test.go
0 → 100644
View file @
33452c2d
package
common
import
(
"bytes"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"testing"
)
func
testState
(
t
*
testing
.
T
)
multistep
.
StateBag
{
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"ui"
,
&
packer
.
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
})
return
state
}
builder/vmware/common/vmx.go
0 → 100644
View file @
33452c2d
package
common
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/common/vmx_test.go
0 → 100644
View file @
33452c2d
package
common
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
)
}
}
builder/vmware/iso/builder.go
View file @
33452c2d
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io/ioutil"
...
...
@@ -405,7 +406,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
&
stepCreateDisk
{},
&
stepCreateVMX
{},
&
StepConfigureVMX
{
&
vmwcommon
.
StepConfigureVMX
{
CustomData
:
b
.
config
.
VMXData
,
},
&
stepSuppressMessages
{},
...
...
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