From 89036bc5162e8c3ba8586591effe3753383d6eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Wed, 7 Nov 2018 10:21:23 +0100 Subject: [PATCH 1/8] add annotation option for clone/iso --- README.md | 1 + clone/step_clone.go | 6 ++++++ iso/step_create.go | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/README.md b/README.md index a5ce429..50beb1b 100644 --- a/README.md +++ b/README.md @@ -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. +* `annoation`(string) - Add some note. * `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. diff --git a/clone/step_clone.go b/clone/step_clone.go index ecec2ee..82f07ee 100644 --- a/clone/step_clone.go +++ b/clone/step_clone.go @@ -13,6 +13,7 @@ type CloneConfig struct { Template string `mapstructure:"template"` DiskSize int64 `mapstructure:"disk_size"` LinkedClone bool `mapstructure:"linked_clone"` + Annoation string `mapstructure:"annotation"` } func (c *CloneConfig) Prepare() []error { @@ -26,6 +27,10 @@ func (c *CloneConfig) Prepare() []error { errs = append(errs, fmt.Errorf("'linked_clone' and 'disk_size' cannot be used together")) } + if c.Annotation == "" { + c.Annotation = "generate by jetbrains-infra/packer-builder-vsphere" + } + return errs } @@ -54,6 +59,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.Annotation, }) if err != nil { state.Put("error", err) diff --git a/iso/step_create.go b/iso/step_create.go index 1a05a59..99288c9 100644 --- a/iso/step_create.go +++ b/iso/step_create.go @@ -21,6 +21,8 @@ type CreateConfig struct { Network string `mapstructure:"network"` NetworkCard string `mapstructure:"network_card"` USBController bool `mapstructure:"usb_controller"` + + Annotation string `mapstructure:"annotation"` } func (c *CreateConfig) Prepare() []error { @@ -38,6 +40,10 @@ func (c *CreateConfig) Prepare() []error { errs = append(errs, fmt.Errorf("'firmware' must be 'bios' or 'efi'")) } + if c.Annotation == "" { + c.Annotation = "generate by jetbrains-infra/packer-builder-vsphere" + } + return errs } @@ -67,6 +73,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.Annotation, }) if err != nil { state.Put("error", fmt.Errorf("error creating vm: %v", err)) From 897ecec1cef5ce3c570ee25758d775a358a1963c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Wed, 7 Nov 2018 10:22:28 +0100 Subject: [PATCH 2/8] run gofmt.sh --- clone/step_clone.go | 8 ++++---- iso/step_create.go | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clone/step_clone.go b/clone/step_clone.go index 82f07ee..c6722ac 100644 --- a/clone/step_clone.go +++ b/clone/step_clone.go @@ -27,9 +27,9 @@ func (c *CloneConfig) Prepare() []error { errs = append(errs, fmt.Errorf("'linked_clone' and 'disk_size' cannot be used together")) } - if c.Annotation == "" { - c.Annotation = "generate by jetbrains-infra/packer-builder-vsphere" - } + if c.Annotation == "" { + c.Annotation = "generate by jetbrains-infra/packer-builder-vsphere" + } return errs } @@ -59,7 +59,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.Annotation, + Annotation: s.Config.Annotation, }) if err != nil { state.Put("error", err) diff --git a/iso/step_create.go b/iso/step_create.go index 99288c9..ab27c5a 100644 --- a/iso/step_create.go +++ b/iso/step_create.go @@ -22,7 +22,7 @@ type CreateConfig struct { NetworkCard string `mapstructure:"network_card"` USBController bool `mapstructure:"usb_controller"` - Annotation string `mapstructure:"annotation"` + Annotation string `mapstructure:"annotation"` } func (c *CreateConfig) Prepare() []error { @@ -40,9 +40,9 @@ func (c *CreateConfig) Prepare() []error { errs = append(errs, fmt.Errorf("'firmware' must be 'bios' or 'efi'")) } - if c.Annotation == "" { - c.Annotation = "generate by jetbrains-infra/packer-builder-vsphere" - } + if c.Annotation == "" { + c.Annotation = "generate by jetbrains-infra/packer-builder-vsphere" + } return errs } @@ -73,7 +73,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.Annotation, + Annotation: s.Config.Annotation, }) if err != nil { state.Put("error", fmt.Errorf("error creating vm: %v", err)) From f1ef7a87dd9bf95c8f765a1570c560c005df70df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Wed, 7 Nov 2018 10:23:53 +0100 Subject: [PATCH 3/8] run gofmt.sh --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 50beb1b..15cdf9f 100644 --- a/README.md +++ b/README.md @@ -48,7 +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. -* `annoation`(string) - Add some note. +* `annotation`(string) - Add some note. * `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. From 1b9a132cbd96b8f25e1d74f16fd1d950d9bdecfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Wed, 7 Nov 2018 13:26:06 +0100 Subject: [PATCH 4/8] Update step_clone.go --- clone/step_clone.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/clone/step_clone.go b/clone/step_clone.go index c6722ac..1ebea51 100644 --- a/clone/step_clone.go +++ b/clone/step_clone.go @@ -27,10 +27,6 @@ func (c *CloneConfig) Prepare() []error { errs = append(errs, fmt.Errorf("'linked_clone' and 'disk_size' cannot be used together")) } - if c.Annotation == "" { - c.Annotation = "generate by jetbrains-infra/packer-builder-vsphere" - } - return errs } From 8ecb49626cb57ebc1cc29d9c523848c6a0e4e22d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Wed, 7 Nov 2018 14:25:47 +0100 Subject: [PATCH 5/8] rename annotation to notes, add annotation in driver code for clone --- README.md | 2 +- clone/step_clone.go | 4 ++-- driver/vm.go | 5 +++++ iso/step_create.go | 6 +----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 15cdf9f..9969283 100644 --- a/README.md +++ b/README.md @@ -48,7 +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. -* `annotation`(string) - Add some note. +* `notes`(string) - Add some note. * `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. diff --git a/clone/step_clone.go b/clone/step_clone.go index 1ebea51..07f65f2 100644 --- a/clone/step_clone.go +++ b/clone/step_clone.go @@ -13,7 +13,7 @@ type CloneConfig struct { Template string `mapstructure:"template"` DiskSize int64 `mapstructure:"disk_size"` LinkedClone bool `mapstructure:"linked_clone"` - Annoation string `mapstructure:"annotation"` + Notes string `mapstructure:"notes"` } func (c *CloneConfig) Prepare() []error { @@ -55,7 +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.Annotation, + Annotation: s.Config.Notes, }) if err != nil { state.Put("error", err) diff --git a/driver/vm.go b/driver/vm.go index 44ac69b..f0e5e2a 100644 --- a/driver/vm.go +++ b/driver/vm.go @@ -24,6 +24,7 @@ type CloneConfig struct { ResourcePool string Datastore string LinkedClone bool + Annotation string } type HardwareConfig struct { @@ -219,6 +220,10 @@ func (template *VirtualMachine) Clone(ctx context.Context, config *CloneConfig) cloneSpec.Snapshot = tpl.Snapshot.CurrentSnapshot } + if config.Annotation != "" { + cloneSpec.Config.Annotation = config.Annotation + } + task, err := template.vm.Clone(template.driver.ctx, folder.folder, config.Name, cloneSpec) if err != nil { return nil, err diff --git a/iso/step_create.go b/iso/step_create.go index ab27c5a..9bd9c50 100644 --- a/iso/step_create.go +++ b/iso/step_create.go @@ -22,7 +22,7 @@ type CreateConfig struct { NetworkCard string `mapstructure:"network_card"` USBController bool `mapstructure:"usb_controller"` - Annotation string `mapstructure:"annotation"` + Annotation string `mapstructure:"notes"` } func (c *CreateConfig) Prepare() []error { @@ -40,10 +40,6 @@ func (c *CreateConfig) Prepare() []error { errs = append(errs, fmt.Errorf("'firmware' must be 'bios' or 'efi'")) } - if c.Annotation == "" { - c.Annotation = "generate by jetbrains-infra/packer-builder-vsphere" - } - return errs } From 2aedb1e6ce628b1cc54c9b8bfb95f68d3c2e55e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Wed, 7 Nov 2018 15:00:15 +0100 Subject: [PATCH 6/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9969283..ac16d54 100644 --- a/README.md +++ b/README.md @@ -48,7 +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 note. +* `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. From 917612509d0e68f5d9618f496a4b5459fc76a717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Wed, 7 Nov 2018 15:04:50 +0100 Subject: [PATCH 7/8] rename annotation to notes --- iso/step_create.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iso/step_create.go b/iso/step_create.go index 9bd9c50..a580103 100644 --- a/iso/step_create.go +++ b/iso/step_create.go @@ -22,7 +22,7 @@ type CreateConfig struct { NetworkCard string `mapstructure:"network_card"` USBController bool `mapstructure:"usb_controller"` - Annotation string `mapstructure:"notes"` + Notes string `mapstructure:"notes"` } func (c *CreateConfig) Prepare() []error { @@ -69,7 +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.Annotation, + Annotation: s.Config.Notes, }) if err != nil { state.Put("error", fmt.Errorf("error creating vm: %v", err)) From 624e81dd77e377f2eea3564861e02d8dfc534a73 Mon Sep 17 00:00:00 2001 From: remijouannet Date: Thu, 8 Nov 2018 01:04:06 +0100 Subject: [PATCH 8/8] ugly segfault --- driver/vm.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/driver/vm.go b/driver/vm.go index f0e5e2a..286b951 100644 --- a/driver/vm.go +++ b/driver/vm.go @@ -221,7 +221,9 @@ func (template *VirtualMachine) Clone(ctx context.Context, config *CloneConfig) } if config.Annotation != "" { - cloneSpec.Config.Annotation = 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)