From 65ae17abd3c349424f35e4cf636d59b7d865ef9f Mon Sep 17 00:00:00 2001 From: Chris Hillery Date: Sat, 15 Jun 2024 04:24:02 -0700 Subject: [PATCH] Add support for `cd_files` in addition to `floppy_files` At least the Ubuntu 24.04 server ISO hangs for 5 minutes when booting with a Xen-provided floppy drive. The primary purpose of floppy_files is to provide the autoinstall config files, and cloud-init is happy to find those files on an inserted CD instead. Add the ability for packer-plugin-xenserver to create such a CD. --- builder/xenserver/common/common_config.go | 1 + builder/xenserver/common/config.hcl2spec.go | 2 ++ builder/xenserver/iso/builder.go | 23 +++++++++++++++++++ builder/xenserver/xva/builder.go | 23 +++++++++++++++++++ docs/builders/iso/xenserver-iso.html.markdown | 10 ++++++++ 5 files changed, 59 insertions(+) diff --git a/builder/xenserver/common/common_config.go b/builder/xenserver/common/common_config.go index c49c544..1be0a8d 100644 --- a/builder/xenserver/common/common_config.go +++ b/builder/xenserver/common/common_config.go @@ -22,6 +22,7 @@ type CommonConfig struct { VMDescription string `mapstructure:"vm_description"` SrName string `mapstructure:"sr_name"` SrISOName string `mapstructure:"sr_iso_name" required:"false"` + CDFiles []string `mapstructure:"cd_files"` FloppyFiles []string `mapstructure:"floppy_files"` NetworkNames []string `mapstructure:"network_names"` ExportNetworkNames []string `mapstructure:"export_network_names"` diff --git a/builder/xenserver/common/config.hcl2spec.go b/builder/xenserver/common/config.hcl2spec.go index 80d8ce8..ea3c16d 100644 --- a/builder/xenserver/common/config.hcl2spec.go +++ b/builder/xenserver/common/config.hcl2spec.go @@ -26,6 +26,7 @@ type FlatConfig struct { VMDescription *string `mapstructure:"vm_description" cty:"vm_description" hcl:"vm_description"` SrName *string `mapstructure:"sr_name" cty:"sr_name" hcl:"sr_name"` SrISOName *string `mapstructure:"sr_iso_name" required:"false" cty:"sr_iso_name" hcl:"sr_iso_name"` + CDFiles []string `mapstructure:"cd_files" cty:"cd_files" hcl:"cd_files"` FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files" hcl:"floppy_files"` NetworkNames []string `mapstructure:"network_names" cty:"network_names" hcl:"network_names"` ExportNetworkNames []string `mapstructure:"export_network_names" cty:"export_network_names" hcl:"export_network_names"` @@ -142,6 +143,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "vm_description": &hcldec.AttrSpec{Name: "vm_description", Type: cty.String, Required: false}, "sr_name": &hcldec.AttrSpec{Name: "sr_name", Type: cty.String, Required: false}, "sr_iso_name": &hcldec.AttrSpec{Name: "sr_iso_name", Type: cty.String, Required: false}, + "cd_files": &hcldec.AttrSpec{Name: "cd_files", Type: cty.List(cty.String), Required: false}, "floppy_files": &hcldec.AttrSpec{Name: "floppy_files", Type: cty.List(cty.String), Required: false}, "network_names": &hcldec.AttrSpec{Name: "network_names", Type: cty.List(cty.String), Required: false}, "export_network_names": &hcldec.AttrSpec{Name: "export_network_names", Type: cty.List(cty.String), Required: false}, diff --git a/builder/xenserver/iso/builder.go b/builder/xenserver/iso/builder.go index 725ebf3..29c07bf 100644 --- a/builder/xenserver/iso/builder.go +++ b/builder/xenserver/iso/builder.go @@ -195,6 +195,10 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p Force: self.config.PackerForce, Path: self.config.OutputDir, }, + &commonsteps.StepCreateCD{ + Files: self.config.CDFiles, + Label: "cidata", + }, &commonsteps.StepCreateFloppy{ Files: self.config.FloppyFiles, Label: "cidata", @@ -202,6 +206,18 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p &xscommon.StepHTTPServer{ Chan: httpReqChan, }, + &xscommon.StepUploadVdi{ + VdiNameFunc: func() string { + return "Packer-CD" + }, + ImagePathFunc: func() string { + if cdPath, ok := state.GetOk("cd_path"); ok { + return cdPath.(string) + } + return "" + }, + VdiUuidKey: "cd_vdi_uuid", + }, &xscommon.StepUploadVdi{ VdiNameFunc: func() string { return "Packer-floppy-disk" @@ -258,6 +274,10 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p VdiUuidKey: "tools_vdi_uuid", VdiType: xsclient.VbdTypeCD, }, + &xscommon.StepAttachVdi{ + VdiUuidKey: "cd_vdi_uuid", + VdiType: xsclient.VbdTypeCD, + }, new(xscommon.StepStartVmPaused), new(xscommon.StepSetVmHostSshAddress), // &xscommon.StepForwardPortOverSSH{ @@ -307,6 +327,9 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p &xscommon.StepDetachVdi{ VdiUuidKey: "tools_vdi_uuid", }, + &xscommon.StepDetachVdi{ + VdiUuidKey: "cd_vdi_uuid", + }, &xscommon.StepDetachVdi{ VdiUuidKey: "floppy_vdi_uuid", }, diff --git a/builder/xenserver/xva/builder.go b/builder/xenserver/xva/builder.go index e948413..42439b9 100644 --- a/builder/xenserver/xva/builder.go +++ b/builder/xenserver/xva/builder.go @@ -118,6 +118,10 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p Force: self.config.PackerForce, Path: self.config.OutputDir, }, + &commonsteps.StepCreateCD{ + Files: self.config.CDFiles, + Label: "cidata", + }, &commonsteps.StepCreateFloppy{ Files: self.config.FloppyFiles, Label: "cidata", @@ -125,6 +129,18 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p &xscommon.StepHTTPServer{ Chan: httpReqChan, }, + &xscommon.StepUploadVdi{ + VdiNameFunc: func() string { + return "Packer-CD" + }, + ImagePathFunc: func() string { + if cdPath, ok := state.GetOk("cd_path"); ok { + return cdPath.(string) + } + return "" + }, + VdiUuidKey: "cd_vdi_uuid", + }, &xscommon.StepUploadVdi{ VdiNameFunc: func() string { return "Packer-floppy-disk" @@ -153,6 +169,10 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p VdiUuidKey: "tools_vdi_uuid", VdiType: xsclient.VbdTypeCD, }, + &xscommon.StepAttachVdi{ + VdiUuidKey: "cd_vdi_uuid", + VdiType: xsclient.VbdTypeCD, + }, new(xscommon.StepStartVmPaused), new(xscommon.StepSetVmHostSshAddress), new(xscommon.StepBootWait), @@ -182,6 +202,9 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p &xscommon.StepDetachVdi{ VdiUuidKey: "tools_vdi_uuid", }, + &xscommon.StepDetachVdi{ + VdiUuidKey: "cd_vdi_uuid", + }, &xscommon.StepDetachVdi{ VdiUuidKey: "floppy_vdi_uuid", }, diff --git a/docs/builders/iso/xenserver-iso.html.markdown b/docs/builders/iso/xenserver-iso.html.markdown index 8272d78..51542e8 100644 --- a/docs/builders/iso/xenserver-iso.html.markdown +++ b/docs/builders/iso/xenserver-iso.html.markdown @@ -83,6 +83,16 @@ each category, the available options are alphabetized and described. five seconds and one minute 30 seconds, respectively. If this isn't specified, the default is 10 seconds. +* `cd_files` (array of strings) - A list of files to place onto a CD + that is attached when the VM is booted. This is most useful + for unattended Windows installs, which look for an `Autounattend.xml` file + on removable media. By default, no CD will be attached. All files + listed in this setting get placed into the root directory of the CD + and the CD is attached as the first CD device. Currently, no + support exists for creating sub-directories on the CD. Wildcard + characters (\*, ?, and []) are allowed. Directory names are also allowed, + which will add all the files found in the directory to the CD. + * `clone_template` (string) - The template to clone. Defaults to "Other install media", this is "other", but you can get _dramatic_ performance improvements by setting this to the proper value. To view all available values for this