From cb7b77cd9078d8e917462a4051680d3cf91ac9c8 Mon Sep 17 00:00:00 2001 From: Peter Pribula Date: Thu, 25 Apr 2019 19:25:00 +0200 Subject: [PATCH] Adds `qemu_agent` optional config parameter --- builder/proxmox/config.go | 6 ++++++ builder/proxmox/config_test.go | 4 ++++ builder/proxmox/step_start_vm.go | 2 +- website/source/docs/builders/proxmox.html.md | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/builder/proxmox/config.go b/builder/proxmox/config.go index 8b60c509f..acdc1636b 100644 --- a/builder/proxmox/config.go +++ b/builder/proxmox/config.go @@ -43,6 +43,7 @@ type Config struct { NICs []nicConfig `mapstructure:"network_adapters"` Disks []diskConfig `mapstructure:"disks"` ISOFile string `mapstructure:"iso_file"` + Agent string `mapstructure:"qemu_agent"` TemplateName string `mapstructure:"template_name"` TemplateDescription string `mapstructure:"template_description"` @@ -149,6 +150,11 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { c.Disks[idx].CacheMode = "none" } } + // Valid values: 0 - no agent, 1 - with agent; default is 1 + if c.Agent != "0" && c.Agent != "1" { + log.Printf("Agent '%s' is not valid, using default: 1", c.Agent) + c.Agent = "1" + } errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...) diff --git a/builder/proxmox/config_test.go b/builder/proxmox/config_test.go index e04f4a0d5..5f09588e4 100644 --- a/builder/proxmox/config_test.go +++ b/builder/proxmox/config_test.go @@ -93,6 +93,7 @@ func TestBasicExampleFromDocsIsValid(t *testing.T) { // OS not set, using default 'other' // NIC 0 model not set, using default 'e1000' // Disk 0 cache mode not set, using default 'none' + // Agent not set, default is 1 if b.config.Memory != 512 { t.Errorf("Expected Memory to be 512, got %d", b.config.Memory) @@ -112,4 +113,7 @@ func TestBasicExampleFromDocsIsValid(t *testing.T) { if b.config.Disks[0].CacheMode != "none" { t.Errorf("Expected disk cache mode to be 'none', got %s", b.config.Disks[0].CacheMode) } + if b.config.Agent != "1" { + t.Errorf("Expected Agent to be 1, got %s", b.config.Agent) + } } diff --git a/builder/proxmox/step_start_vm.go b/builder/proxmox/step_start_vm.go index 779394023..e47525e24 100644 --- a/builder/proxmox/step_start_vm.go +++ b/builder/proxmox/step_start_vm.go @@ -24,7 +24,7 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist ui.Say("Creating VM") config := proxmox.ConfigQemu{ Name: c.VMName, - Agent: "1", + Agent: c.Agent, Description: "Packer ephemeral build VM", Memory: c.Memory, QemuCores: c.Cores, diff --git a/website/source/docs/builders/proxmox.html.md b/website/source/docs/builders/proxmox.html.md index 2345c1911..cb133f76d 100644 --- a/website/source/docs/builders/proxmox.html.md +++ b/website/source/docs/builders/proxmox.html.md @@ -146,6 +146,10 @@ builder. - `unmount_iso` (bool) - If true, remove the mounted ISO from the template after finishing. Defaults to `false`. +- `qemu_agent` (string) - Enables (`1`) or disables (`0`) the QEMU Agent option + for this VM. When disabled, then Packer can't determine the guest's IP, + and `ssh_host` should be used. When enabled, then `qemu-guest-agent` + must be installed on the guest OS. Defaults to `1`. ## Example: Fedora with kickstart