Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions builder/proxmox/clone/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ func (*cloneVMCreator) Create(vmRef *proxmoxapi.VmRef, vmConfig proxmoxapi.Confi
}
}

storagePool := c.TargetStoragePool
if storagePool == "" && len(c.Disks) > 0 {
storagePool = c.Disks[0].StoragePool
}
if fullClone == 1 && storagePool != "" {
if vmConfig.QemuDisks == nil {
vmConfig.QemuDisks = proxmoxapi.QemuDevices{}
}
if vmConfig.QemuDisks[0] == nil {
vmConfig.QemuDisks[0] = make(map[string]interface{})
}
vmConfig.QemuDisks[0]["storage"] = storagePool
ui.Say(fmt.Sprintf("Using target storage pool: %s", storagePool))
}

err := vmConfig.CloneVm(sourceVmr, vmRef, client)
if err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions builder/proxmox/clone/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type Config struct {
CloneVMID int `mapstructure:"clone_vm_id" required:"true"`
// Whether to run a full or shallow clone from the base clone_vm. Defaults to `true`.
FullClone config.Trilean `mapstructure:"full_clone" required:"false"`
// Name of the Proxmox storage pool to store the cloned VM disks on.
// If not given, the source template's storage is used, or the storage_pool of the first defined disk.
// This setting only applies to full clones.
TargetStoragePool string `mapstructure:"target_storage_pool" required:"false"`

// Set nameserver IP address(es) via Cloud-Init.
// If not given, the same setting as on the host is used.
Expand Down Expand Up @@ -89,6 +93,9 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, []string, error) {
if c.CloneVMID != 0 && (c.CloneVMID < 100 || c.CloneVMID > 999999999) {
errs = packersdk.MultiErrorAppend(errs, errors.New("clone_vm_id must be in range 100-999999999"))
}
if c.FullClone.False() && c.TargetStoragePool != "" {
warnings = append(warnings, "target_storage_pool is only used for full clones and will be ignored when full_clone is false")
}

// Check validity of given IP addresses
if c.Nameserver != "" {
Expand Down
2 changes: 2 additions & 0 deletions builder/proxmox/clone/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions builder/proxmox/clone/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,37 @@ func TestIpconfig(t *testing.T) {
})
}
}

func TestTargetStoragePool(t *testing.T) {
t.Run("target_storage_pool with full clone", func(t *testing.T) {
cfg := mandatoryConfig(t)
cfg["target_storage_pool"] = "local-lvm"

var c Config
_, warnings, err := c.Prepare(&c, cfg)
if err != nil {
t.Fatalf("unexpected failure: %s", err)
}
if len(warnings) != 0 {
t.Fatalf("unexpected warnings: %v", warnings)
}
})

t.Run("target_storage_pool with linked clone warning", func(t *testing.T) {
cfg := mandatoryConfig(t)
cfg["target_storage_pool"] = "local-lvm"
cfg["full_clone"] = false

var c Config
_, warnings, err := c.Prepare(&c, cfg)
if err != nil {
t.Fatalf("unexpected failure: %s", err)
}
if len(warnings) != 1 {
t.Fatalf("expected one warning, got %d (%v)", len(warnings), warnings)
}
if !strings.Contains(warnings[0], "target_storage_pool") {
t.Fatalf("expected target_storage_pool warning, got %q", warnings[0])
}
})
}
4 changes: 4 additions & 0 deletions docs-partials/builder/proxmox/clone/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- `full_clone` (boolean) - Whether to run a full or shallow clone from the base clone_vm. Defaults to `true`.

- `target_storage_pool` (string) - Name of the Proxmox storage pool to store the cloned VM disks on.
If not given, the source template's storage is used.
This setting only applies to full clones.

- `nameserver` (string) - Set nameserver IP address(es) via Cloud-Init.
If not given, the same setting as on the host is used.

Expand Down