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
bfba7d2d
Commit
bfba7d2d
authored
Jun 27, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant: virtualbox output finds and sets up the mac addr
parent
42005959
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
4 deletions
+46
-4
post-processor/vagrant/virtualbox.go
post-processor/vagrant/virtualbox.go
+46
-4
No files found.
post-processor/vagrant/virtualbox.go
View file @
bfba7d2d
package
vagrant
import
(
"errors"
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
"strings"
"text/template"
)
...
...
@@ -34,8 +38,12 @@ func (p *VBoxBoxPostProcessor) Configure(raw interface{}) error {
}
func
(
p
*
VBoxBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
error
)
{
// TODO(mitchellh): Actually parse the base mac address
var
err
error
tplData
:=
&
VBoxVagrantfileTemplate
{}
tplData
.
BaseMacAddress
,
err
=
p
.
findBaseMacAddress
(
artifact
)
if
err
!=
nil
{
return
nil
,
err
}
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"virtualbox"
,
artifact
)
...
...
@@ -112,10 +120,44 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
return
NewArtifact
(
"virtualbox"
,
outputPath
),
nil
}
func
(
p
*
VBoxBoxPostProcessor
)
findBaseMacAddress
(
a
packer
.
Artifact
)
(
string
,
error
)
{
log
.
Println
(
"Looking for OVF for base mac address..."
)
var
ovf
string
for
_
,
f
:=
range
a
.
Files
()
{
if
strings
.
HasSuffix
(
f
,
".ovf"
)
{
log
.
Printf
(
"OVF found: %s"
,
f
)
ovf
=
f
break
}
}
if
ovf
==
""
{
return
""
,
errors
.
New
(
"ovf file couldn't be found"
)
}
f
,
err
:=
os
.
Open
(
ovf
)
if
err
!=
nil
{
return
""
,
err
}
defer
f
.
Close
()
data
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
return
""
,
err
}
re
:=
regexp
.
MustCompile
(
`<Adapter slot="0".+?MACAddress="(.+?)"`
)
matches
:=
re
.
FindSubmatch
(
data
)
if
matches
==
nil
{
return
""
,
errors
.
New
(
"can't find base mac address in OVF"
)
}
log
.
Printf
(
"Base mac address: %s"
,
string
(
matches
[
1
]))
return
string
(
matches
[
1
]),
nil
}
var
defaultVBoxVagrantfile
=
`
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
# TODO
end
config.vm.base_mac = "{{ .BaseMacAddress }}"
end
`
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