ddelnano / packer-plugin-xenserver

A builder plugin for Packer.IO to support building XenServer images.
Mozilla Public License 2.0
72 stars 37 forks source link

Fix cloudinit ready template generation #51

Closed BMeach closed 1 year ago

BMeach commented 1 year ago

Adds a line of code that should fix the issues decribed here on the XCP-NG Forum

The following fix calls the xapi VM.remove_from_other_config hook to remove any "disks" entries from the vm that will be turned into a template via Packer. Currently this fix has only been tested with the Xen Orchestra "Ubuntu Focal Fossa 20.04" default template.

ddelnano commented 1 year ago

@BryceTech122 thanks for getting this PR open. I feel confident that this is the fix, but I'd like to test this PR end to end myself. Once I validate the testing you've done, I'll merge and release a bugfix version of the packer plugin.

BMeach commented 1 year ago

@ddelnano sounds good, let me know if I can help in testing at all. Currently im using this fix 10x times a day only on ubuntu 20.04 though

ddelnano commented 1 year ago

@BryceTech122 apologies for the wait. My normal development environment (homelab) has been unstable and hindered my ability to test this. I was able to use the environment that the Xen Orchestra terraform provider is tested in after completing some setup.

I was able to create 2 templates: one on master and one with this branch. The former is unable to use cloud init (as seen in the screenshot below) due to its other-config property having a disks: key. The latter works as expected and doesn't have a disks: key in its other-config.

Screenshot_20230120_235943 Screenshot_20230120_235926

[09:00 R620-1 ~]# xe template-list | grep -B 1 packer
uuid ( RO)                : f5d5d36c-b0bd-8474-7266-5ffa176432ff
          name-label ( RW): packer-ubuntu-2004-20230121073403
--
uuid ( RO)                : 05320e0a-39db-8d76-d98b-d8dbc42d823a
          name-label ( RW): packer-ubuntu-2004-broken-20230121065103

# Verify the non "broken" named template doesn't contain "disks:"
[09:00 R620-1 ~]# xe template-param-list uuid=f5d5d36c-b0bd-8474-7266-5ffa176432ff | grep other-config
                          other-config (MRW): base_template_name: Ubuntu Focal Fossa 20.04; import_task: OpaqueRef:13a80d23-9058-40cc-bc09-3df8844e1f5f; mac_seed: 98ac2c4e-f097-a12a-d415-d6ae467f9ce0; install-methods: cdrom,nfs,http,ftp; linux_template: true

# Verify the broken named template does include a "disks:" key
[09:00 R620-1 ~]# xe template-param-list uuid=05320e0a-39db-8d76-d98b-d8dbc42d823a | grep other-config
                          other-config (MRW): base_template_name: Ubuntu Focal Fossa 20.04; import_task: OpaqueRef:13a80d23-9058-40cc-bc09-3df8844e1f5f; mac_seed: 434b259e-d5fd-b4ce-7bb1-647462925c1a; disks: <provision><disk bootable="true" device="0" size="10737418240" sr="" type="system"/></provision>; install-methods: cdrom,nfs,http,ftp; linux_template: true
ddelnano commented 1 year ago

I'll be creating a bugfix release now and you should be able to packer init it once the artifacts are uploaded to the github release from the CI job.

BMeach commented 1 year ago

Thank you for your and Oliver's help in resolving this issue!