Merge pull request #1479 from jasonberanek/esxi-remote-cache
buidler/vmware-esxi: Add configuration options for the remote location to cache ISO and floppy files
This commit is contained in:
commit
00543fe582
@ -46,12 +46,14 @@ type config struct {
|
|||||||
SkipCompaction bool `mapstructure:"skip_compaction"`
|
SkipCompaction bool `mapstructure:"skip_compaction"`
|
||||||
VMXTemplatePath string `mapstructure:"vmx_template_path"`
|
VMXTemplatePath string `mapstructure:"vmx_template_path"`
|
||||||
|
|
||||||
RemoteType string `mapstructure:"remote_type"`
|
RemoteType string `mapstructure:"remote_type"`
|
||||||
RemoteDatastore string `mapstructure:"remote_datastore"`
|
RemoteDatastore string `mapstructure:"remote_datastore"`
|
||||||
RemoteHost string `mapstructure:"remote_host"`
|
RemoteCacheDatastore string `mapstructure:"remote_cache_datastore"`
|
||||||
RemotePort uint `mapstructure:"remote_port"`
|
RemoteCacheDirectory string `mapstructure:"remote_cache_directory"`
|
||||||
RemoteUser string `mapstructure:"remote_username"`
|
RemoteHost string `mapstructure:"remote_host"`
|
||||||
RemotePassword string `mapstructure:"remote_password"`
|
RemotePort uint `mapstructure:"remote_port"`
|
||||||
|
RemoteUser string `mapstructure:"remote_username"`
|
||||||
|
RemotePassword string `mapstructure:"remote_password"`
|
||||||
|
|
||||||
RawSingleISOUrl string `mapstructure:"iso_url"`
|
RawSingleISOUrl string `mapstructure:"iso_url"`
|
||||||
|
|
||||||
@ -123,24 +125,34 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||||||
b.config.RemoteDatastore = "datastore1"
|
b.config.RemoteDatastore = "datastore1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.RemoteCacheDatastore == "" {
|
||||||
|
b.config.RemoteCacheDatastore = b.config.RemoteDatastore
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.config.RemoteCacheDirectory == "" {
|
||||||
|
b.config.RemoteCacheDirectory = "packer_cache"
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.RemotePort == 0 {
|
if b.config.RemotePort == 0 {
|
||||||
b.config.RemotePort = 22
|
b.config.RemotePort = 22
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
templates := map[string]*string{
|
templates := map[string]*string{
|
||||||
"disk_name": &b.config.DiskName,
|
"disk_name": &b.config.DiskName,
|
||||||
"guest_os_type": &b.config.GuestOSType,
|
"guest_os_type": &b.config.GuestOSType,
|
||||||
"iso_checksum": &b.config.ISOChecksum,
|
"iso_checksum": &b.config.ISOChecksum,
|
||||||
"iso_checksum_type": &b.config.ISOChecksumType,
|
"iso_checksum_type": &b.config.ISOChecksumType,
|
||||||
"iso_url": &b.config.RawSingleISOUrl,
|
"iso_url": &b.config.RawSingleISOUrl,
|
||||||
"vm_name": &b.config.VMName,
|
"vm_name": &b.config.VMName,
|
||||||
"vmx_template_path": &b.config.VMXTemplatePath,
|
"vmx_template_path": &b.config.VMXTemplatePath,
|
||||||
"remote_type": &b.config.RemoteType,
|
"remote_type": &b.config.RemoteType,
|
||||||
"remote_host": &b.config.RemoteHost,
|
"remote_host": &b.config.RemoteHost,
|
||||||
"remote_datastore": &b.config.RemoteDatastore,
|
"remote_datastore": &b.config.RemoteDatastore,
|
||||||
"remote_user": &b.config.RemoteUser,
|
"remote_cache_datastore": &b.config.RemoteCacheDatastore,
|
||||||
"remote_password": &b.config.RemotePassword,
|
"remote_cache_directory": &b.config.RemoteCacheDirectory,
|
||||||
|
"remote_user": &b.config.RemoteUser,
|
||||||
|
"remote_password": &b.config.RemotePassword,
|
||||||
}
|
}
|
||||||
|
|
||||||
for n, ptr := range templates {
|
for n, ptr := range templates {
|
||||||
|
@ -17,11 +17,13 @@ func NewDriver(config *config) (vmwcommon.Driver, error) {
|
|||||||
|
|
||||||
drivers = []vmwcommon.Driver{
|
drivers = []vmwcommon.Driver{
|
||||||
&ESX5Driver{
|
&ESX5Driver{
|
||||||
Host: config.RemoteHost,
|
Host: config.RemoteHost,
|
||||||
Port: config.RemotePort,
|
Port: config.RemotePort,
|
||||||
Username: config.RemoteUser,
|
Username: config.RemoteUser,
|
||||||
Password: config.RemotePassword,
|
Password: config.RemotePassword,
|
||||||
Datastore: config.RemoteDatastore,
|
Datastore: config.RemoteDatastore,
|
||||||
|
CacheDatastore: config.RemoteCacheDatastore,
|
||||||
|
CacheDirectory: config.RemoteCacheDirectory,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ type ESX5Driver struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Datastore string
|
Datastore string
|
||||||
|
CacheDatastore string
|
||||||
|
CacheDirectory string
|
||||||
|
|
||||||
comm packer.Communicator
|
comm packer.Communicator
|
||||||
outputDir string
|
outputDir string
|
||||||
@ -84,13 +86,7 @@ func (d *ESX5Driver) Unregister(vmxPathLocal string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType string) (string, error) {
|
func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType string) (string, error) {
|
||||||
cacheRoot, _ := filepath.Abs(".")
|
finalPath := d.cachePath(localPath)
|
||||||
targetFile, err := filepath.Rel(cacheRoot, localPath)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
finalPath := d.datastorePath(targetFile)
|
|
||||||
if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil {
|
if err := d.mkdir(filepath.ToSlash(filepath.Dir(finalPath))); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -300,6 +296,10 @@ func (d *ESX5Driver) datastorePath(path string) string {
|
|||||||
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.Datastore, baseDir, filepath.Base(path)))
|
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.Datastore, baseDir, filepath.Base(path)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *ESX5Driver) cachePath(path string) string {
|
||||||
|
return filepath.ToSlash(filepath.Join("/vmfs/volumes", d.CacheDatastore, d.CacheDirectory, filepath.Base(path)))
|
||||||
|
}
|
||||||
|
|
||||||
func (d *ESX5Driver) connect() error {
|
func (d *ESX5Driver) connect() error {
|
||||||
address := fmt.Sprintf("%s:%d", d.Host, d.Port)
|
address := fmt.Sprintf("%s:%d", d.Host, d.Port)
|
||||||
|
|
||||||
|
@ -151,6 +151,16 @@ each category, the available options are alphabetized and described.
|
|||||||
By default this is "output-BUILDNAME" where "BUILDNAME" is the name
|
By default this is "output-BUILDNAME" where "BUILDNAME" is the name
|
||||||
of the build.
|
of the build.
|
||||||
|
|
||||||
|
* `remote_cache_datastore` (string) - The path to the datastore where
|
||||||
|
supporting files will be stored during the build on the remote machine.
|
||||||
|
By default this is the same as the `remote_datastore` option. This only
|
||||||
|
has an effect if `remote_type` is enabled.
|
||||||
|
|
||||||
|
* `remote_cache_directory` (string) - The path where the ISO and/or floppy
|
||||||
|
files will be stored during the build on the remote machine. The path is
|
||||||
|
relative to the `remote_cache_datastore` on the remote machine. By default
|
||||||
|
this is "packer_cache". This only has an effect if `remote_type` is enabled.
|
||||||
|
|
||||||
* `remote_datastore` (string) - The path to the datastore where the resulting
|
* `remote_datastore` (string) - The path to the datastore where the resulting
|
||||||
VM will be stored when it is built on the remote machine. By default this
|
VM will be stored when it is built on the remote machine. By default this
|
||||||
is "datastore1". This only has an effect if `remote_type` is enabled.
|
is "datastore1". This only has an effect if `remote_type` is enabled.
|
||||||
@ -375,6 +385,13 @@ have to modify as well:
|
|||||||
* `remote_datastore` - The path to the datastore where the VM will be
|
* `remote_datastore` - The path to the datastore where the VM will be
|
||||||
stored on the ESXi machine.
|
stored on the ESXi machine.
|
||||||
|
|
||||||
|
* `remote_cache_datastore` - The path to the datastore where
|
||||||
|
supporting files will be stored during the build on the remote machine.
|
||||||
|
|
||||||
|
* `remote_cache_directory` - The path where the ISO and/or floppy
|
||||||
|
files will be stored during the build on the remote machine. The path is
|
||||||
|
relative to the `remote_cache_datastore` on the remote machine.
|
||||||
|
|
||||||
* `remote_username` - The SSH username used to access the remote machine.
|
* `remote_username` - The SSH username used to access the remote machine.
|
||||||
|
|
||||||
* `remote_password` - The SSH password for access to the remote machine.
|
* `remote_password` - The SSH password for access to the remote machine.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user