Skip to content

Commit

Permalink
Update with some more options
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Stucki committed Mar 14, 2017
1 parent 0113ddb commit ba37427
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#VSphere Template Post Processor
VSphere Template Post Processor
===============================

This post-processor creates VSphere templates from Virtualbox packer builders. It expects the VBoxManage
output step to create OVF files.

##Compatibility
Compatibility
-------------

So far this has been tested with Virtualbox 5.1.6, VSphere running ESXI 5.5, and packer 0.10.1. I see no
reason why other combinations won't work as well.

##Installing
Installing
----------

Download your platform-specific binary from the [latest releases page](https://github.com/andrewstucki/packer-post-processor-vsphere-template/releases/latest). Either
put your binary somewhere accessible on your path or reference the absolute path to the binary in
Expand Down Expand Up @@ -48,4 +51,6 @@ The following attributes are available:
| datastore | The datastore to back the template disk | required |
| os_type | The VMWare os type to inject into the OVF (defaults to centos64Guest) | optional |
| os_id | The VMWare os id to inject into the OVF template (defaults to 107) | optional |
| os_version | The VMWare os version to inject into the OVF template (defaults to "") | optional |
| vm_name | The name of the OVF template to upload (defaults to the builder name) | optional |
| hardware_version | The VMWare hardware version to inject into the OVF (defaults to vmx-10) | optional |
13 changes: 12 additions & 1 deletion plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ type OVF struct {
Username string `mapstructure:"username"`
Folder string `mapstructure:"folder"`
ResourcePool string `mapstructure:"resource_pool"`
VmName string `mapstructure:"vm_name"`
OsType string `mapstructure:"os_type"`
OsVersion string `mapstructure:"os_version"`
OsID string `mapstructure:"os_id"`
HardwareVersion string `mapstructure:"hardware_version"`

Expand Down Expand Up @@ -76,7 +78,12 @@ func (o *OVF) normalizeOVF(content []byte) {
})
content = virtualboxVboxRe.ReplaceAll(content, []byte(""))
// make some of this stuff configurable
newOSSection := fmt.Sprintf(`<OperatingSystemSection ovf:id="%s" vmw:osType="%s">`, o.OsID, o.OsType)
var newOSSection string
if o.OsVersion == "" {
newOSSection = fmt.Sprintf(`<OperatingSystemSection ovf:id="%s" vmw:osType="%s">`, o.OsID, o.OsType)
} else {
newOSSection = fmt.Sprintf(`<OperatingSystemSection ovf:id="%s" ovf:version="%s" vmw:osType="%s">`, o.OsID, o.OsVersion, o.OsType)
}
content = virtualboxOSRe.ReplaceAll(content, []byte(newOSSection))
newHardwareSection := fmt.Sprintf("<vssd:VirtualSystemType>%s</vssd:VirtualSystemType>", o.HardwareVersion)
o.contents = virtualboxRe.ReplaceAll(content, []byte(newHardwareSection))
Expand Down Expand Up @@ -195,6 +202,10 @@ func (o *OVF) upload() (*types.ManagedObjectReference, error) {
}
}

if o.VmName != "" {
name = o.VmName
}

log.Printf("Configuring import location for '%s'", name)

finder := find.NewFinder(o.client, true)
Expand Down

0 comments on commit ba37427

Please sign in to comment.