rename 'dc_name' to 'datacenter'

This commit is contained in:
Michael Kuzmin 2017-07-01 17:45:13 +03:00
parent b549e21e01
commit 172118bbe5
4 changed files with 9 additions and 9 deletions

View File

@ -52,7 +52,7 @@ This builder uses native vSphere API, and creates virtual machines remotely.
### Optional
Destination:
* `dc_name` - required if there are several datacenters.
* `datacenter` - required if there are several datacenters.
* `folder` - VM folder where target VM is created.
* `resource_pool` - by default a root of vSphere host.
* `datastore` - required if vSphere host has multiple datastores attached.
@ -80,7 +80,7 @@ Post-processing:
"type": "vsphere",
"vcenter_host": "vcenter.domain.com",
"dc_name": "dc1",
"datacenter": "dc1",
"username": "root",
"password": "{{user `vsphere_password`}}",

View File

@ -52,13 +52,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state.Put("client", client)
finder := find.NewFinder(client.Client, false)
dc, err := finder.DatacenterOrDefault(ctx, b.config.DCName)
datacenter, err := finder.DatacenterOrDefault(ctx, b.config.Datacenter)
if err != nil {
return nil, err
}
finder.SetDatacenter(dc)
finder.SetDatacenter(datacenter)
state.Put("finder", finder)
state.Put("dc", dc)
state.Put("datacenter", datacenter)
vmSrc, err := finder.VirtualMachine(ctx, b.config.Template)
if err != nil {

View File

@ -24,7 +24,7 @@ type Config struct {
Template string `mapstructure:"template"`
VMName string `mapstructure:"vm_name"`
FolderName string `mapstructure:"folder"`
DCName string `mapstructure:"dc_name"`
Datacenter string `mapstructure:"datacenter"`
Host string `mapstructure:"host"`
ResourcePool string `mapstructure:"resource_pool"`
Datastore string `mapstructure:"datastore"`

View File

@ -30,20 +30,20 @@ type StepCloneVM struct {
func (s *StepCloneVM) Run(state multistep.StateBag) multistep.StepAction {
ctx := state.Get("ctx").(context.Context)
finder := state.Get("finder").(*find.Finder)
dc := state.Get("dc").(*object.Datacenter)
datacenter := state.Get("datacenter").(*object.Datacenter)
vmSrc := state.Get("vmSrc").(*object.VirtualMachine)
ui := state.Get("ui").(packer.Ui)
ui.Say("start cloning...")
// Get folder
folder, err := finder.FolderOrDefault(ctx, fmt.Sprintf("/%v/vm/%v", dc.Name(), s.config.FolderName))
folder, err := finder.FolderOrDefault(ctx, fmt.Sprintf("/%v/vm/%v", datacenter.Name(), s.config.FolderName))
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
// Get resource pool
pool, err := finder.ResourcePoolOrDefault(ctx, fmt.Sprintf("/%v/host/%v/Resources/%v", dc.Name(), s.config.Host, s.config.ResourcePool))
pool, err := finder.ResourcePoolOrDefault(ctx, fmt.Sprintf("/%v/host/%v/Resources/%v", datacenter.Name(), s.config.Host, s.config.ResourcePool))
if err != nil {
state.Put("error", err)
return multistep.ActionHalt