Allow having a template or a full VM

This commit is contained in:
Cécile MORANGE 2023-08-07 11:56:14 +02:00
parent 6af6320f8a
commit 8fe24bddcd
No known key found for this signature in database
GPG Key ID: 7D0BB77551B490D9
3 changed files with 16 additions and 8 deletions

View File

@ -34,6 +34,7 @@ type Config struct {
SourcePath string `mapstructure:"source_path"` SourcePath string `mapstructure:"source_path"`
Firmware string `mapstructure:"firmware"` Firmware string `mapstructure:"firmware"`
SetTemplate string `mapstructure:"set_template"`
ctx interpolate.Context ctx interpolate.Context
} }

View File

@ -109,6 +109,7 @@ type FlatConfig struct {
RawInstallTimeout *string `mapstructure:"install_timeout" cty:"install_timeout" hcl:"install_timeout"` RawInstallTimeout *string `mapstructure:"install_timeout" cty:"install_timeout" hcl:"install_timeout"`
SourcePath *string `mapstructure:"source_path" cty:"source_path" hcl:"source_path"` SourcePath *string `mapstructure:"source_path" cty:"source_path" hcl:"source_path"`
Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"` Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"`
SetTemplate *string `mapstructure:"set_template" cty:"set_template" hcl:"set_template"`
} }
// FlatMapstructure returns a new FlatConfig. // FlatMapstructure returns a new FlatConfig.
@ -222,6 +223,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"install_timeout": &hcldec.AttrSpec{Name: "install_timeout", Type: cty.String, Required: false}, "install_timeout": &hcldec.AttrSpec{Name: "install_timeout", Type: cty.String, Required: false},
"source_path": &hcldec.AttrSpec{Name: "source_path", Type: cty.String, Required: false}, "source_path": &hcldec.AttrSpec{Name: "source_path", Type: cty.String, Required: false},
"firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false}, "firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false},
"set_template": &hcldec.AttrSpec{Name: "set_template", Type: cty.String, Required: false},
} }
return s return s
} }

View File

@ -186,11 +186,10 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p
Url: self.config.ISOUrls, Url: self.config.ISOUrls,
}, },
} }
steps := []multistep.Step{ steps := []multistep.Step{&xscommon.StepPrepareOutputDir{
&xscommon.StepPrepareOutputDir{ Force: self.config.PackerForce,
Force: self.config.PackerForce, Path: self.config.OutputDir,
Path: self.config.OutputDir, },
},
&commonsteps.StepCreateFloppy{ &commonsteps.StepCreateFloppy{
Files: self.config.FloppyFiles, Files: self.config.FloppyFiles,
Label: "cidata", Label: "cidata",
@ -286,7 +285,14 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p
}, },
new(commonsteps.StepProvision), new(commonsteps.StepProvision),
new(xscommon.StepShutdown), new(xscommon.StepShutdown),
new(xscommon.StepSetVmToTemplate), }
if self.config.SetTemplate == "True" {
steps = append(steps,
new(xscommon.StepSetVmToTemplate))
}
steps = append(steps,
&xscommon.StepDetachVdi{ &xscommon.StepDetachVdi{
VdiUuidKey: "iso_vdi_uuid", VdiUuidKey: "iso_vdi_uuid",
}, },
@ -299,8 +305,7 @@ func (self *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (p
&xscommon.StepDetachVdi{ &xscommon.StepDetachVdi{
VdiUuidKey: "floppy_vdi_uuid", VdiUuidKey: "floppy_vdi_uuid",
}, },
new(xscommon.StepExport), new(xscommon.StepExport))
}
if self.config.ISOName == "" { if self.config.ISOName == "" {
steps = append(download_steps, steps...) steps = append(download_steps, steps...)