Working Debian install

This commit is contained in:
2023-04-14 17:16:54 +02:00
parent 6dba571338
commit fcd72ffa7a
12 changed files with 237 additions and 283 deletions

View File

@@ -8,7 +8,7 @@ import (
)
// This is the common builder ID to all of these artifacts.
const BuilderId = "packer.xenserver"
const BuilderId = "packer.xcp-ng"
type LocalArtifact struct {
dir string

View File

@@ -76,7 +76,7 @@ func (c *CommonConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig
}
if c.ToolsIsoName == "" {
c.ToolsIsoName = "xs-tools.iso"
c.ToolsIsoName = ""
}
if c.HTTPPortMin == 0 {
@@ -271,17 +271,17 @@ func (config CommonConfig) GetISOSR(c *Connection) (xenapi.SRRef, error) {
} else {
// Use the provided name label to find the SR to use
srs, err := c.GetClient().SR.GetByNameLabel(c.session, config.SrName)
srs, err := c.GetClient().SR.GetByNameLabel(c.session, config.SrISOName)
if err != nil {
return srRef, err
}
switch {
case len(srs) == 0:
return srRef, fmt.Errorf("Couldn't find a SR with the specified name-label '%s'", config.SrName)
return srRef, fmt.Errorf("Couldn't find a SR with the specified name-label '%s'", config.SrISOName)
case len(srs) > 1:
return srRef, fmt.Errorf("Found more than one SR with the name '%s'. The name must be unique", config.SrName)
return srRef, fmt.Errorf("Found more than one SR with the name '%s'. The name must be unique", config.SrISOName)
}
return srs[0], nil

View File

@@ -0,0 +1,44 @@
package common
import (
"context"
"fmt"
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/packer"
)
type StepFindOrUploadVdi struct {
StepUploadVdi
}
func (self *StepFindOrUploadVdi) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
c := state.Get("client").(*Connection)
vdiName := self.VdiNameFunc()
ui.Say(fmt.Sprintf("Attemping to find VDI '%s'", vdiName))
vdis, err := c.client.VDI.GetByNameLabel(c.session, vdiName)
if err != nil {
ui.Error(fmt.Sprintf("Failed to find VDI '%s' by name label: %s", vdiName, err.Error()))
return multistep.ActionHalt
}
if len(vdis) > 1 {
ui.Error(fmt.Sprintf("Found more than one VDI with name '%s'. Name must be unique", vdiName))
return multistep.ActionHalt
} else if len(vdis) == 1 {
vdi := vdis[0]
vdiUuid, err := c.client.VDI.GetUUID(c.session, vdi)
if err != nil {
ui.Error(fmt.Sprintf("Unable to get UUID of VDI '%s': %s", vdiName, err.Error()))
return multistep.ActionHalt
}
state.Put(self.VdiUuidKey, vdiUuid)
return multistep.ActionContinue
}
return self.uploadVdi(ctx, state)
}

View File

@@ -18,7 +18,7 @@ type StepUploadVdi struct {
VdiUuidKey string
}
func (self *StepUploadVdi) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
func (self *StepUploadVdi) uploadVdi(ctx context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("commonconfig").(CommonConfig)
ui := state.Get("ui").(packer.Ui)
c := state.Get("client").(*Connection)
@@ -33,10 +33,8 @@ func (self *StepUploadVdi) Run(ctx context.Context, state multistep.StateBag) mu
ui.Say(fmt.Sprintf("Step: Upload VDI '%s'", vdiName))
// Create VDI for the image
srs, err := c.client.SR.GetAll(c.session)
ui.Say(fmt.Sprintf("Step: Found SRs '%v'", srs))
sr, err := config.GetISOSR(c)
ui.Say(fmt.Sprintf("Step: Found SR for upload '%v'", sr))
if err != nil {
ui.Error(fmt.Sprintf("Unable to get SR: %v", err))
@@ -96,6 +94,10 @@ func (self *StepUploadVdi) Run(ctx context.Context, state multistep.StateBag) mu
return multistep.ActionContinue
}
func (self *StepUploadVdi) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
return self.uploadVdi(ctx, state)
}
func (self *StepUploadVdi) Cleanup(state multistep.StateBag) {
config := state.Get("commonconfig").(CommonConfig)
ui := state.Get("ui").(packer.Ui)