Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
'notes' option (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
remijouannet authored and mkuzmin committed Nov 8, 2018
1 parent e21ff3f commit e929b19
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ See complete Ubuntu, Windows, and macOS templates in the [examples folder](https
### VM Location

* `vm_name`(string) - Name of the new VM to create.
* `notes`(string) - Add some notes.
* `folder`(string) - VM folder to create the VM in.
* `host`(string) - ESXi host where target VM is created. A full path must be specified if the host is in a folder. For example `folder/host`. See the `Specifying Clusters and Hosts` section above for more details.
* `cluster`(string) - ESXi cluster where target VM is created. See [Working with Clusters](#working-with-clusters) section.
Expand Down
2 changes: 2 additions & 0 deletions clone/step_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type CloneConfig struct {
Template string `mapstructure:"template"`
DiskSize int64 `mapstructure:"disk_size"`
LinkedClone bool `mapstructure:"linked_clone"`
Notes string `mapstructure:"notes"`
}

func (c *CloneConfig) Prepare() []error {
Expand Down Expand Up @@ -54,6 +55,7 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
ResourcePool: s.Location.ResourcePool,
Datastore: s.Location.Datastore,
LinkedClone: s.Config.LinkedClone,
Annotation: s.Config.Notes,
})
if err != nil {
state.Put("error", err)
Expand Down
7 changes: 7 additions & 0 deletions driver/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type CloneConfig struct {
ResourcePool string
Datastore string
LinkedClone bool
Annotation string
}

type HardwareConfig struct {
Expand Down Expand Up @@ -219,6 +220,12 @@ func (template *VirtualMachine) Clone(ctx context.Context, config *CloneConfig)
cloneSpec.Snapshot = tpl.Snapshot.CurrentSnapshot
}

if config.Annotation != "" {
var configSpec types.VirtualMachineConfigSpec
configSpec.Annotation = config.Annotation
cloneSpec.Config = &configSpec
}

task, err := template.vm.Clone(template.driver.ctx, folder.folder, config.Name, cloneSpec)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions iso/step_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type CreateConfig struct {
Network string `mapstructure:"network"`
NetworkCard string `mapstructure:"network_card"`
USBController bool `mapstructure:"usb_controller"`

Notes string `mapstructure:"notes"`
}

func (c *CreateConfig) Prepare() []error {
Expand Down Expand Up @@ -67,6 +69,7 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste
USBController: s.Config.USBController,
Version: s.Config.Version,
Firmware: s.Config.Firmware,
Annotation: s.Config.Notes,
})
if err != nil {
state.Put("error", fmt.Errorf("error creating vm: %v", err))
Expand Down

7 comments on commit e929b19

@jcoconnor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkuzmin Is this due for a release anytime soon ?
Its a really useful addition that I had put on my todo list to for having an attempt at doing.
Tx @remijouannet for doing this.

@mkuzmin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcoconnor
Copy link
Contributor

@jcoconnor jcoconnor commented on e929b19 Nov 26, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcoconnor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkuzmin I've just tried an initial build - I can briefly see the "notes" field being populated before the build fails with the following error:

20:32:11 ==> win-2019-x86_64-vmware-vcenter: Creating VM...
20:32:12 ==> win-2019-x86_64-vmware-vcenter: Customizing hardware...
20:32:12 ==> win-2019-x86_64-vmware-vcenter: Mount ISO images...
20:32:13 ==> win-2019-x86_64-vmware-vcenter: Adding configuration parameters...
20:32:13 ==> win-2019-x86_64-vmware-vcenter: Creating floppy disk...
20:32:13     win-2019-x86_64-vmware-vcenter: Copying files flatly from floppy_files
20:32:13     win-2019-x86_64-vmware-vcenter: Copying file: ./tmp/autounattend.xml
20:32:13     win-2019-x86_64-vmware-vcenter: Copying file: ./files/platform-packages.ps1
20:32:13     win-2019-x86_64-vmware-vcenter: Copying file: ../../common/scripts/common/windows-env.ps1
20:32:13     win-2019-x86_64-vmware-vcenter: Copying file: ../../common/scripts/bootstrap/bootstrap-base.bat
20:32:13     win-2019-x86_64-vmware-vcenter: Copying file: ../../common/scripts/bootstrap/bootstrap-packerbuild.ps1
20:32:13     win-2019-x86_64-vmware-vcenter: Copying file: ../../common/scripts/bootstrap/shutdown-packerbuild.ps1
20:32:13     win-2019-x86_64-vmware-vcenter: Copying file: ../../common/scripts/bootstrap/startup-profile.ps1
20:32:13     win-2019-x86_64-vmware-vcenter: Done copying files from floppy_files
20:32:13     win-2019-x86_64-vmware-vcenter: Collecting paths from floppy_dirs
20:32:13     win-2019-x86_64-vmware-vcenter: Resulting paths from floppy_dirs : []
20:32:13     win-2019-x86_64-vmware-vcenter: Done copying paths from floppy_dirs
20:32:13 ==> win-2019-x86_64-vmware-vcenter: Uploading created floppy image
20:32:13 ==> win-2019-x86_64-vmware-vcenter: Destroying VM...
20:32:13 Build 'win-2019-x86_64-vmware-vcenter' errored: host '' not found

Will do a bit more probing tomorrow to see if I can isolate the failure.

@jcoconnor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking aloud here - I'm not specifying the "host" field in the packer/json for the above build - using cluster name instead - this seems to be working fine with the latest plugin release, where the host is allocated to one of the hosts in the cluster - wonder if this is failing in the CI build, or perhaps it just worked as a fluke in the latest release (I'm not sure if we have DRS enabled on the cluster).

@mkuzmin
Copy link
Contributor

@mkuzmin mkuzmin commented on e929b19 Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably related to #183

@jcoconnor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes might be - the datastore and network are specified tho - you can see the packer file we are using at:
https://github.com/puppetlabs/puppetlabs-packer/blob/master/templates/win/common/vmware.vcenter.cygwin.json
(this one using the v2.1 release of the plugin)

Please sign in to comment.