Move proxmox builder out + vendor it (#10930)
* use vendored proxmox builders * Update docs-nav-data.json remove proxmox ref * Update docs-remote-plugins.json * remove builder/proxmox dir * remove website/content/docs/builders/proxmox/ * up vendors * Update modules.txt * Update HTTPConfig-not-required.mdx * Update HTTPConfig-not-required.mdx * tidy mod * fmt * Update modules.txt
This commit is contained in:
parent
20faaef05c
commit
9eaad88ac0
|
@ -1,5 +0,0 @@
|
|||
package proxmox
|
||||
|
||||
import proxmoxiso "github.com/hashicorp/packer/builder/proxmox/iso"
|
||||
|
||||
type Builder = proxmoxiso.Builder
|
|
@ -1,91 +0,0 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTokenAuth(t *testing.T) {
|
||||
mockAPI := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Header.Get("Authorization") != "PVEAPIToken=dummy@vmhost!test-token=ac5293bf-15e2-477f-b04c-a6dfa7a46b80" {
|
||||
rw.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}))
|
||||
defer mockAPI.Close()
|
||||
|
||||
pmURL, _ := url.Parse(mockAPI.URL)
|
||||
config := Config{
|
||||
proxmoxURL: pmURL,
|
||||
SkipCertValidation: false,
|
||||
Username: "dummy@vmhost!test-token",
|
||||
Password: "not-used",
|
||||
Token: "ac5293bf-15e2-477f-b04c-a6dfa7a46b80",
|
||||
}
|
||||
|
||||
client, err := newProxmoxClient(config)
|
||||
require.NoError(t, err)
|
||||
|
||||
ref := proxmox.NewVmRef(110)
|
||||
ref.SetNode("node1")
|
||||
ref.SetVmType("qemu")
|
||||
err = client.Sendkey(ref, "ping")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLogin(t *testing.T) {
|
||||
mockAPI := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
// mock ticketing api
|
||||
if req.Method == http.MethodPost && req.URL.Path == "/access/ticket" {
|
||||
body, _ := ioutil.ReadAll(req.Body)
|
||||
values, _ := url.ParseQuery(string(body))
|
||||
user := values.Get("username")
|
||||
pass := values.Get("password")
|
||||
if user != "dummy@vmhost" || pass != "correct-horse-battery-staple" {
|
||||
rw.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(rw).Encode(map[string]interface{}{
|
||||
"data": map[string]string{
|
||||
"username": user,
|
||||
"ticket": "dummy-ticket",
|
||||
"CSRFPreventionToken": "random-token",
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// validate ticket
|
||||
if val, err := req.Cookie("PVEAuthCookie"); err != nil || val.Value != "dummy-ticket" {
|
||||
rw.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}))
|
||||
defer mockAPI.Close()
|
||||
|
||||
pmURL, _ := url.Parse(mockAPI.URL)
|
||||
config := Config{
|
||||
proxmoxURL: pmURL,
|
||||
SkipCertValidation: false,
|
||||
Username: "dummy@vmhost",
|
||||
Password: "correct-horse-battery-staple",
|
||||
Token: "",
|
||||
}
|
||||
|
||||
client, err := newProxmoxClient(config)
|
||||
require.NoError(t, err)
|
||||
|
||||
ref := proxmox.NewVmRef(110)
|
||||
ref.SetNode("node1")
|
||||
ref.SetVmType("qemu")
|
||||
err = client.Sendkey(ref, "ping")
|
||||
require.NoError(t, err)
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func mandatoryConfig(t *testing.T) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"proxmox_url": "https://my-proxmox.my-domain:8006/api2/json",
|
||||
"username": "apiuser@pve",
|
||||
"password": "supersecret",
|
||||
"node": "my-proxmox",
|
||||
"ssh_username": "root",
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequiredParameters(t *testing.T) {
|
||||
var c Config
|
||||
_, _, err := c.Prepare(&c, make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("Expected empty configuration to fail")
|
||||
}
|
||||
errs, ok := err.(*packersdk.MultiError)
|
||||
if !ok {
|
||||
t.Fatal("Expected errors to be packersdk.MultiError")
|
||||
}
|
||||
|
||||
required := []string{"username", "password", "proxmox_url", "node", "ssh_username"}
|
||||
for _, param := range required {
|
||||
found := false
|
||||
for _, err := range errs.Errors {
|
||||
if strings.Contains(err.Error(), param) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("Expected error about missing parameter %q", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentSetToFalse(t *testing.T) {
|
||||
cfg := mandatoryConfig(t)
|
||||
cfg["qemu_agent"] = false
|
||||
|
||||
var c Config
|
||||
_, _, err := c.Prepare(&c, cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if c.Agent != false {
|
||||
t.Errorf("Expected Agent to be false, got %t", c.Agent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPacketQueueSupportForNetworkAdapters(t *testing.T) {
|
||||
drivertests := []struct {
|
||||
expectedToFail bool
|
||||
model string
|
||||
}{
|
||||
{expectedToFail: false, model: "virtio"},
|
||||
{expectedToFail: true, model: "e1000"},
|
||||
{expectedToFail: true, model: "e1000-82540em"},
|
||||
{expectedToFail: true, model: "e1000-82544gc"},
|
||||
{expectedToFail: true, model: "e1000-82545em"},
|
||||
{expectedToFail: true, model: "i82551"},
|
||||
{expectedToFail: true, model: "i82557b"},
|
||||
{expectedToFail: true, model: "i82559er"},
|
||||
{expectedToFail: true, model: "ne2k_isa"},
|
||||
{expectedToFail: true, model: "ne2k_pci"},
|
||||
{expectedToFail: true, model: "pcnet"},
|
||||
{expectedToFail: true, model: "rtl8139"},
|
||||
{expectedToFail: true, model: "vmxnet3"},
|
||||
}
|
||||
|
||||
for _, tt := range drivertests {
|
||||
device := make(map[string]interface{})
|
||||
device["bridge"] = "vmbr0"
|
||||
device["model"] = tt.model
|
||||
device["packet_queues"] = 2
|
||||
|
||||
devices := make([]map[string]interface{}, 0)
|
||||
devices = append(devices, device)
|
||||
|
||||
cfg := mandatoryConfig(t)
|
||||
cfg["network_adapters"] = devices
|
||||
|
||||
var c Config
|
||||
_, _, err := c.Prepare(&c, cfg)
|
||||
|
||||
if tt.expectedToFail == true && err == nil {
|
||||
t.Error("expected config preparation to fail, but no error occured")
|
||||
}
|
||||
|
||||
if tt.expectedToFail == false && err != nil {
|
||||
t.Errorf("expected config preparation to succeed, but %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
type converterMock struct {
|
||||
shutdownVm func(*proxmox.VmRef) (string, error)
|
||||
createTemplate func(*proxmox.VmRef) error
|
||||
}
|
||||
|
||||
func (m converterMock) ShutdownVm(r *proxmox.VmRef) (string, error) {
|
||||
return m.shutdownVm(r)
|
||||
}
|
||||
func (m converterMock) CreateTemplate(r *proxmox.VmRef) error {
|
||||
return m.createTemplate(r)
|
||||
}
|
||||
|
||||
var _ templateConverter = converterMock{}
|
||||
|
||||
func TestConvertToTemplate(t *testing.T) {
|
||||
cs := []struct {
|
||||
name string
|
||||
shutdownErr error
|
||||
expectCallCreateTemplate bool
|
||||
createTemplateErr error
|
||||
expectedAction multistep.StepAction
|
||||
expectTemplateIdSet bool
|
||||
}{
|
||||
{
|
||||
name: "no errors returns continue and sets template id",
|
||||
expectCallCreateTemplate: true,
|
||||
expectedAction: multistep.ActionContinue,
|
||||
expectTemplateIdSet: true,
|
||||
},
|
||||
{
|
||||
name: "when shutdown fails, don't try to create template and halt",
|
||||
shutdownErr: fmt.Errorf("failed to stop vm"),
|
||||
expectCallCreateTemplate: false,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
expectTemplateIdSet: false,
|
||||
},
|
||||
{
|
||||
name: "when create template fails, halt",
|
||||
expectCallCreateTemplate: true,
|
||||
createTemplateErr: fmt.Errorf("failed to stop vm"),
|
||||
expectedAction: multistep.ActionHalt,
|
||||
expectTemplateIdSet: false,
|
||||
},
|
||||
}
|
||||
|
||||
const vmid = 123
|
||||
|
||||
for _, c := range cs {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
converter := converterMock{
|
||||
shutdownVm: func(r *proxmox.VmRef) (string, error) {
|
||||
if r.VmId() != vmid {
|
||||
t.Errorf("ShutdownVm called with unexpected id, expected %d, got %d", vmid, r.VmId())
|
||||
}
|
||||
return "", c.shutdownErr
|
||||
},
|
||||
createTemplate: func(r *proxmox.VmRef) error {
|
||||
if r.VmId() != vmid {
|
||||
t.Errorf("CreateTemplate called with unexpected id, expected %d, got %d", vmid, r.VmId())
|
||||
}
|
||||
if !c.expectCallCreateTemplate {
|
||||
t.Error("Did not expect CreateTemplate to be called")
|
||||
}
|
||||
|
||||
return c.createTemplateErr
|
||||
},
|
||||
}
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packersdk.TestUi(t))
|
||||
state.Put("vmRef", proxmox.NewVmRef(vmid))
|
||||
state.Put("proxmoxClient", converter)
|
||||
|
||||
step := stepConvertToTemplate{}
|
||||
action := step.Run(context.TODO(), state)
|
||||
if action != c.expectedAction {
|
||||
t.Errorf("Expected action to be %v, got %v", c.expectedAction, action)
|
||||
}
|
||||
|
||||
id, wasSet := state.GetOk("template_id")
|
||||
|
||||
if c.expectTemplateIdSet != wasSet {
|
||||
t.Errorf("Expected template_id state present=%v was present=%v", c.expectTemplateIdSet, wasSet)
|
||||
}
|
||||
|
||||
if c.expectTemplateIdSet && id != vmid {
|
||||
t.Errorf("Expected template_id state to be set to %d, got %v", vmid, id)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
type finalizerMock struct {
|
||||
getConfig func() (map[string]interface{}, error)
|
||||
setConfig func(map[string]interface{}) (string, error)
|
||||
}
|
||||
|
||||
func (m finalizerMock) GetVmConfig(*proxmox.VmRef) (map[string]interface{}, error) {
|
||||
return m.getConfig()
|
||||
}
|
||||
func (m finalizerMock) SetVmConfig(vmref *proxmox.VmRef, c map[string]interface{}) (interface{}, error) {
|
||||
return m.setConfig(c)
|
||||
}
|
||||
|
||||
var _ templateFinalizer = finalizerMock{}
|
||||
|
||||
func TestTemplateFinalize(t *testing.T) {
|
||||
cs := []struct {
|
||||
name string
|
||||
builderConfig *Config
|
||||
initialVMConfig map[string]interface{}
|
||||
getConfigErr error
|
||||
expectCallSetConfig bool
|
||||
expectedVMConfig map[string]interface{}
|
||||
setConfigErr error
|
||||
expectedAction multistep.StepAction
|
||||
}{
|
||||
{
|
||||
name: "empty config changes only description",
|
||||
builderConfig: &Config{},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"name": "dummy",
|
||||
"description": "Packer ephemeral build VM",
|
||||
"ide2": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
},
|
||||
expectCallSetConfig: true,
|
||||
expectedVMConfig: map[string]interface{}{
|
||||
"name": nil,
|
||||
"description": "",
|
||||
"ide2": nil,
|
||||
},
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "all options",
|
||||
builderConfig: &Config{
|
||||
TemplateName: "my-template",
|
||||
TemplateDescription: "some-description",
|
||||
},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"name": "dummy",
|
||||
"description": "Packer ephemeral build VM",
|
||||
},
|
||||
expectCallSetConfig: true,
|
||||
expectedVMConfig: map[string]interface{}{
|
||||
"name": "my-template",
|
||||
"description": "some-description",
|
||||
},
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "all options with cloud-init",
|
||||
builderConfig: &Config{
|
||||
TemplateName: "my-template",
|
||||
TemplateDescription: "some-description",
|
||||
CloudInit: true,
|
||||
},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"name": "dummy",
|
||||
"description": "Packer ephemeral build VM",
|
||||
"bootdisk": "virtio0",
|
||||
"virtio0": "ceph01:base-223-disk-0,cache=unsafe,media=disk,size=32G",
|
||||
},
|
||||
expectCallSetConfig: true,
|
||||
expectedVMConfig: map[string]interface{}{
|
||||
"name": "my-template",
|
||||
"description": "some-description",
|
||||
"ide3": "ceph01:cloudinit",
|
||||
},
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "no available controller for cloud-init drive",
|
||||
builderConfig: &Config{
|
||||
TemplateName: "my-template",
|
||||
TemplateDescription: "some-description",
|
||||
CloudInit: true,
|
||||
},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"name": "dummy",
|
||||
"description": "Packer ephemeral build VM",
|
||||
"ide0": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
"ide1": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
"ide2": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
"ide3": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
"bootdisk": "virtio0",
|
||||
"virtio0": "ceph01:base-223-disk-0,cache=unsafe,media=disk,size=32G",
|
||||
},
|
||||
expectCallSetConfig: false,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
{
|
||||
name: "GetVmConfig error should return halt",
|
||||
builderConfig: &Config{
|
||||
TemplateName: "my-template",
|
||||
TemplateDescription: "some-description",
|
||||
CloudInit: true,
|
||||
},
|
||||
getConfigErr: fmt.Errorf("some error"),
|
||||
expectCallSetConfig: false,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
{
|
||||
name: "SetVmConfig error should return halt",
|
||||
builderConfig: &Config{
|
||||
TemplateName: "my-template",
|
||||
TemplateDescription: "some-description",
|
||||
},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"name": "dummy",
|
||||
"description": "Packer ephemeral build VM",
|
||||
},
|
||||
expectCallSetConfig: true,
|
||||
setConfigErr: fmt.Errorf("some error"),
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cs {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
finalizer := finalizerMock{
|
||||
getConfig: func() (map[string]interface{}, error) {
|
||||
return c.initialVMConfig, c.getConfigErr
|
||||
},
|
||||
setConfig: func(cfg map[string]interface{}) (string, error) {
|
||||
if !c.expectCallSetConfig {
|
||||
t.Error("Did not expect SetVmConfig to be called")
|
||||
}
|
||||
for key, val := range c.expectedVMConfig {
|
||||
if cfg[key] != val {
|
||||
t.Errorf("Expected %q to be %q, got %q", key, val, cfg[key])
|
||||
}
|
||||
}
|
||||
|
||||
return "", c.setConfigErr
|
||||
},
|
||||
}
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packersdk.TestUi(t))
|
||||
state.Put("config", c.builderConfig)
|
||||
state.Put("vmRef", proxmox.NewVmRef(1))
|
||||
state.Put("proxmoxClient", finalizer)
|
||||
|
||||
step := stepFinalizeTemplateConfig{}
|
||||
action := step.Run(context.TODO(), state)
|
||||
if action != c.expectedAction {
|
||||
t.Errorf("Expected action to be %v, got %v", c.expectedAction, action)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
type startedVMCleanerMock struct {
|
||||
stopVm func() (string, error)
|
||||
deleteVm func() (string, error)
|
||||
}
|
||||
|
||||
func (m startedVMCleanerMock) StopVm(*proxmox.VmRef) (string, error) {
|
||||
return m.stopVm()
|
||||
}
|
||||
func (m startedVMCleanerMock) DeleteVm(*proxmox.VmRef) (string, error) {
|
||||
return m.deleteVm()
|
||||
}
|
||||
|
||||
var _ startedVMCleaner = &startedVMCleanerMock{}
|
||||
|
||||
func TestCleanupStartVM(t *testing.T) {
|
||||
cs := []struct {
|
||||
name string
|
||||
setVmRef bool
|
||||
setSuccess bool
|
||||
stopVMErr error
|
||||
expectCallStopVM bool
|
||||
deleteVMErr error
|
||||
expectCallDeleteVM bool
|
||||
}{
|
||||
{
|
||||
name: "when vmRef state is not set, nothing should happen",
|
||||
setVmRef: false,
|
||||
expectCallStopVM: false,
|
||||
},
|
||||
{
|
||||
name: "when success state is set, nothing should happen",
|
||||
setVmRef: true,
|
||||
setSuccess: true,
|
||||
expectCallStopVM: false,
|
||||
},
|
||||
{
|
||||
name: "when not successful, vm should be stopped and deleted",
|
||||
setVmRef: true,
|
||||
setSuccess: false,
|
||||
expectCallStopVM: true,
|
||||
expectCallDeleteVM: true,
|
||||
},
|
||||
{
|
||||
name: "if stopping fails, DeleteVm should not be called",
|
||||
setVmRef: true,
|
||||
setSuccess: false,
|
||||
expectCallStopVM: true,
|
||||
stopVMErr: fmt.Errorf("some error"),
|
||||
expectCallDeleteVM: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cs {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
var stopWasCalled, deleteWasCalled bool
|
||||
|
||||
cleaner := startedVMCleanerMock{
|
||||
stopVm: func() (string, error) {
|
||||
if !c.expectCallStopVM {
|
||||
t.Error("Did not expect StopVm to be called")
|
||||
}
|
||||
|
||||
stopWasCalled = true
|
||||
return "", c.stopVMErr
|
||||
},
|
||||
deleteVm: func() (string, error) {
|
||||
if !c.expectCallDeleteVM {
|
||||
t.Error("Did not expect DeleteVm to be called")
|
||||
}
|
||||
|
||||
deleteWasCalled = true
|
||||
return "", c.deleteVMErr
|
||||
},
|
||||
}
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packersdk.TestUi(t))
|
||||
state.Put("proxmoxClient", cleaner)
|
||||
if c.setVmRef {
|
||||
state.Put("vmRef", proxmox.NewVmRef(1))
|
||||
}
|
||||
if c.setSuccess {
|
||||
state.Put("success", "true")
|
||||
}
|
||||
|
||||
step := stepStartVM{}
|
||||
step.Cleanup(state)
|
||||
|
||||
if c.expectCallStopVM && !stopWasCalled {
|
||||
t.Error("Expected StopVm to be called, but it wasn't")
|
||||
}
|
||||
if c.expectCallDeleteVM && !deleteWasCalled {
|
||||
t.Error("Expected DeleteVm to be called, but it wasn't")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type startVMMock struct {
|
||||
create func(*proxmox.VmRef, proxmox.ConfigQemu, multistep.StateBag) error
|
||||
startVm func(*proxmox.VmRef) (string, error)
|
||||
setVmConfig func(*proxmox.VmRef, map[string]interface{}) (interface{}, error)
|
||||
}
|
||||
|
||||
func (m *startVMMock) Create(vmRef *proxmox.VmRef, config proxmox.ConfigQemu, state multistep.StateBag) error {
|
||||
return m.create(vmRef, config, state)
|
||||
}
|
||||
func (m *startVMMock) StartVm(vmRef *proxmox.VmRef) (string, error) {
|
||||
return m.startVm(vmRef)
|
||||
}
|
||||
func (m *startVMMock) SetVmConfig(vmRef *proxmox.VmRef, config map[string]interface{}) (interface{}, error) {
|
||||
return m.setVmConfig(vmRef, config)
|
||||
}
|
||||
func (m *startVMMock) GetNextID(int) (int, error) {
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
func TestStartVM(t *testing.T) {
|
||||
// TODO: proxmox-api-go does a lot of manipulation on the input and does not
|
||||
// give any way to access the actual data it sends to the Proxmox server,
|
||||
// which means writing good tests here is quite hard. This test is mainly a
|
||||
// stub to revisit when we can write better tests.
|
||||
cs := []struct {
|
||||
name string
|
||||
config *Config
|
||||
expectedAction multistep.StepAction
|
||||
}{
|
||||
{
|
||||
name: "Example config from documentation works",
|
||||
config: &Config{
|
||||
Disks: []diskConfig{
|
||||
{
|
||||
Type: "sata",
|
||||
Size: "10G",
|
||||
StoragePool: "local",
|
||||
StoragePoolType: "lvm",
|
||||
},
|
||||
},
|
||||
NICs: []nicConfig{
|
||||
{
|
||||
Bridge: "vmbr0",
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cs {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
mock := &startVMMock{
|
||||
create: func(vmRef *proxmox.VmRef, config proxmox.ConfigQemu, state multistep.StateBag) error {
|
||||
return nil
|
||||
},
|
||||
startVm: func(*proxmox.VmRef) (string, error) {
|
||||
return "", nil
|
||||
},
|
||||
setVmConfig: func(*proxmox.VmRef, map[string]interface{}) (interface{}, error) {
|
||||
return nil, nil
|
||||
},
|
||||
}
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packersdk.TestUi(t))
|
||||
state.Put("config", c.config)
|
||||
state.Put("proxmoxClient", mock)
|
||||
s := stepStartVM{vmCreator: mock}
|
||||
|
||||
action := s.Run(context.TODO(), state)
|
||||
if action != c.expectedAction {
|
||||
t.Errorf("Expected action %s, got %s", c.expectedAction, action)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
package proxmox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/packer-plugin-sdk/bootcommand"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
type commandTyperMock struct {
|
||||
sendkey func(*proxmox.VmRef, string) error
|
||||
}
|
||||
|
||||
func (m commandTyperMock) Sendkey(ref *proxmox.VmRef, cmd string) error {
|
||||
return m.sendkey(ref, cmd)
|
||||
}
|
||||
|
||||
var _ commandTyper = commandTyperMock{}
|
||||
|
||||
func TestTypeBootCommand(t *testing.T) {
|
||||
cs := []struct {
|
||||
name string
|
||||
builderConfig *Config
|
||||
expectCallSendkey bool
|
||||
sendkeyErr error
|
||||
expectedKeysSent string
|
||||
expectedAction multistep.StepAction
|
||||
}{
|
||||
{
|
||||
name: "simple boot command is typed",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"hello"}}},
|
||||
expectCallSendkey: true,
|
||||
expectedKeysSent: "hello",
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "interpolated boot command",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"hello<enter>world"}}},
|
||||
expectCallSendkey: true,
|
||||
expectedKeysSent: "helloretworld",
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "merge multiple interpolated boot command",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"Hello World 2.0", "foo!bar@baz"}}},
|
||||
expectCallSendkey: true,
|
||||
expectedKeysSent: "shift-hellospcshift-worldspc2dot0fooshift-1barshift-2baz",
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "holding and releasing keys",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"<leftShiftOn>hello<rightAltOn>world<leftShiftOff><rightAltOff>"}}},
|
||||
expectCallSendkey: true,
|
||||
expectedKeysSent: "shift-hshift-eshift-lshift-lshift-oshift-alt_r-wshift-alt_r-oshift-alt_r-rshift-alt_r-lshift-alt_r-d",
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "holding multiple alphabetical keys and shift",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"<cOn><leftShiftOn>n<leftShiftOff><cOff>"}}},
|
||||
expectCallSendkey: true,
|
||||
expectedKeysSent: "shift-c-n",
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "noop keystrokes",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"<cOn><leftShiftOn><cOff><leftAltOn><leftShiftOff><leftAltOff>"}}},
|
||||
expectCallSendkey: true,
|
||||
expectedKeysSent: "",
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "noop keystrokes mixed",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"<cOn><leftShiftOn><cOff>h<leftShiftOff>"}}},
|
||||
expectCallSendkey: true,
|
||||
expectedKeysSent: "shift-h",
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "without boot command sendkey should not be called",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{}}},
|
||||
expectCallSendkey: false,
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "invalid boot command template function",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"{{ foo }}"}}},
|
||||
expectCallSendkey: false,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
{
|
||||
// When proxmox (or Qemu, really) doesn't recognize the keycode we send, we get no error back, but
|
||||
// a map {"data": "invalid parameter: X"}, where X is the keycode.
|
||||
name: "invalid keys sent to proxmox",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"x"}}},
|
||||
expectCallSendkey: true,
|
||||
sendkeyErr: fmt.Errorf("invalid parameter: x"),
|
||||
expectedKeysSent: "x",
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
{
|
||||
name: "error in typing should return halt",
|
||||
builderConfig: &Config{BootConfig: bootcommand.BootConfig{BootCommand: []string{"hello"}}},
|
||||
expectCallSendkey: true,
|
||||
sendkeyErr: fmt.Errorf("some error"),
|
||||
expectedKeysSent: "h",
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cs {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
accumulator := strings.Builder{}
|
||||
typer := commandTyperMock{
|
||||
sendkey: func(ref *proxmox.VmRef, cmd string) error {
|
||||
if !c.expectCallSendkey {
|
||||
t.Error("Did not expect sendkey to be called")
|
||||
}
|
||||
|
||||
accumulator.WriteString(cmd)
|
||||
|
||||
return c.sendkeyErr
|
||||
},
|
||||
}
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packersdk.TestUi(t))
|
||||
state.Put("config", c.builderConfig)
|
||||
state.Put("http_port", int(0))
|
||||
state.Put("vmRef", proxmox.NewVmRef(1))
|
||||
state.Put("proxmoxClient", typer)
|
||||
|
||||
step := stepTypeBootCommand{
|
||||
c.builderConfig.BootConfig,
|
||||
c.builderConfig.Ctx,
|
||||
}
|
||||
action := step.Run(context.TODO(), state)
|
||||
step.Cleanup(state)
|
||||
|
||||
if action != c.expectedAction {
|
||||
t.Errorf("Expected action to be %v, got %v", c.expectedAction, action)
|
||||
}
|
||||
if c.expectedKeysSent != accumulator.String() {
|
||||
t.Errorf("Expected keystrokes to be %q, got %q", c.expectedKeysSent, accumulator.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
package proxmoxiso
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer-plugin-sdk/template"
|
||||
)
|
||||
|
||||
func TestBasicExampleFromDocsIsValid(t *testing.T) {
|
||||
const config = `{
|
||||
"builders": [
|
||||
{
|
||||
"type": "proxmox-iso",
|
||||
"proxmox_url": "https://my-proxmox.my-domain:8006/api2/json",
|
||||
"insecure_skip_tls_verify": true,
|
||||
"username": "apiuser@pve",
|
||||
"password": "supersecret",
|
||||
|
||||
"node": "my-proxmox",
|
||||
"network_adapters": [
|
||||
{
|
||||
"bridge": "vmbr0"
|
||||
}
|
||||
],
|
||||
"disks": [
|
||||
{
|
||||
"type": "scsi",
|
||||
"disk_size": "5G",
|
||||
"storage_pool": "local-lvm",
|
||||
"storage_pool_type": "lvm"
|
||||
}
|
||||
],
|
||||
|
||||
"iso_file": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso",
|
||||
"http_directory":"config",
|
||||
"boot_wait": "10s",
|
||||
"boot_command": [
|
||||
"<up><tab> ip=dhcp inst.cmdline inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/ks.cfg<enter>"
|
||||
],
|
||||
|
||||
"ssh_username": "root",
|
||||
"ssh_timeout": "15m",
|
||||
"ssh_password": "packer",
|
||||
|
||||
"unmount_iso": true,
|
||||
"template_name": "fedora-29",
|
||||
"template_description": "Fedora 29-1.2, generated on {{ isotime \"2006-01-02T15:04:05Z\" }}"
|
||||
}
|
||||
]
|
||||
}`
|
||||
tpl, err := template.Parse(strings.NewReader(config))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b := &Builder{}
|
||||
_, _, err = b.Prepare(tpl.Builders["proxmox-iso"].Config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// The example config does not set a number of optional fields. Validate that:
|
||||
// Memory 0 is too small, using default: 512
|
||||
// Number of cores 0 is too small, using default: 1
|
||||
// Number of sockets 0 is too small, using default: 1
|
||||
// CPU type not set, using default 'kvm64'
|
||||
// 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 true
|
||||
// SCSI controller not set, using default 'lsi'
|
||||
// Firewall toggle not set, using default: 0
|
||||
// Disable KVM not set, using default: 0
|
||||
|
||||
if b.config.Memory != 512 {
|
||||
t.Errorf("Expected Memory to be 512, got %d", b.config.Memory)
|
||||
}
|
||||
if b.config.Cores != 1 {
|
||||
t.Errorf("Expected Cores to be 1, got %d", b.config.Cores)
|
||||
}
|
||||
if b.config.Sockets != 1 {
|
||||
t.Errorf("Expected Sockets to be 1, got %d", b.config.Sockets)
|
||||
}
|
||||
if b.config.CPUType != "kvm64" {
|
||||
t.Errorf("Expected CPU type to be 'kvm64', got %s", b.config.CPUType)
|
||||
}
|
||||
if b.config.OS != "other" {
|
||||
t.Errorf("Expected OS to be 'other', got %s", b.config.OS)
|
||||
}
|
||||
if b.config.NICs[0].Model != "e1000" {
|
||||
t.Errorf("Expected NIC model to be 'e1000', got %s", b.config.NICs[0].Model)
|
||||
}
|
||||
if b.config.NICs[0].Firewall != false {
|
||||
t.Errorf("Expected NIC firewall to be false, got %t", b.config.NICs[0].Firewall)
|
||||
}
|
||||
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 != true {
|
||||
t.Errorf("Expected Agent to be true, got %t", b.config.Agent)
|
||||
}
|
||||
if b.config.DisableKVM != false {
|
||||
t.Errorf("Expected Disable KVM toggle to be false, got %t", b.config.DisableKVM)
|
||||
}
|
||||
if b.config.SCSIController != "lsi" {
|
||||
t.Errorf("Expected SCSI controller to be 'lsi', got %s", b.config.SCSIController)
|
||||
}
|
||||
if b.config.CloudInit != false {
|
||||
t.Errorf("Expected CloudInit to be false, got %t", b.config.CloudInit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentSetToFalse(t *testing.T) {
|
||||
cfg := mandatoryConfig(t)
|
||||
cfg["qemu_agent"] = false
|
||||
|
||||
var c Config
|
||||
_, warn, err := c.Prepare(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err, warn)
|
||||
}
|
||||
|
||||
if c.Agent != false {
|
||||
t.Errorf("Expected Agent to be false, got %t", c.Agent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPacketQueueSupportForNetworkAdapters(t *testing.T) {
|
||||
drivertests := []struct {
|
||||
expectedToFail bool
|
||||
model string
|
||||
}{
|
||||
{expectedToFail: false, model: "virtio"},
|
||||
{expectedToFail: true, model: "e1000"},
|
||||
{expectedToFail: true, model: "e1000-82540em"},
|
||||
{expectedToFail: true, model: "e1000-82544gc"},
|
||||
{expectedToFail: true, model: "e1000-82545em"},
|
||||
{expectedToFail: true, model: "i82551"},
|
||||
{expectedToFail: true, model: "i82557b"},
|
||||
{expectedToFail: true, model: "i82559er"},
|
||||
{expectedToFail: true, model: "ne2k_isa"},
|
||||
{expectedToFail: true, model: "ne2k_pci"},
|
||||
{expectedToFail: true, model: "pcnet"},
|
||||
{expectedToFail: true, model: "rtl8139"},
|
||||
{expectedToFail: true, model: "vmxnet3"},
|
||||
}
|
||||
|
||||
for _, tt := range drivertests {
|
||||
device := make(map[string]interface{})
|
||||
device["bridge"] = "vmbr0"
|
||||
device["model"] = tt.model
|
||||
device["packet_queues"] = 2
|
||||
|
||||
devices := make([]map[string]interface{}, 0)
|
||||
devices = append(devices, device)
|
||||
|
||||
cfg := mandatoryConfig(t)
|
||||
cfg["network_adapters"] = devices
|
||||
|
||||
var c Config
|
||||
_, _, err := c.Prepare(cfg)
|
||||
|
||||
if tt.expectedToFail == true && err == nil {
|
||||
t.Error("expected config preparation to fail, but no error occured")
|
||||
}
|
||||
|
||||
if tt.expectedToFail == false && err != nil {
|
||||
t.Errorf("expected config preparation to succeed, but %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHardDiskControllerIOThreadSupport(t *testing.T) {
|
||||
drivertests := []struct {
|
||||
expectedToFail bool
|
||||
controller string
|
||||
disk_type string
|
||||
}{
|
||||
// io thread is only supported by virtio-scsi-single controller
|
||||
// and only for virtio and scsi disks
|
||||
{expectedToFail: false, controller: "virtio-scsi-single", disk_type: "scsi"},
|
||||
{expectedToFail: false, controller: "virtio-scsi-single", disk_type: "virtio"},
|
||||
{expectedToFail: true, controller: "virtio-scsi-single", disk_type: "sata"},
|
||||
{expectedToFail: true, controller: "lsi", disk_type: "scsi"},
|
||||
{expectedToFail: true, controller: "lsi53c810", disk_type: "virtio"},
|
||||
}
|
||||
|
||||
for _, tt := range drivertests {
|
||||
nic := make(map[string]interface{})
|
||||
nic["bridge"] = "vmbr0"
|
||||
|
||||
nics := make([]map[string]interface{}, 0)
|
||||
nics = append(nics, nic)
|
||||
|
||||
disk := make(map[string]interface{})
|
||||
disk["type"] = tt.disk_type
|
||||
disk["io_thread"] = true
|
||||
disk["storage_pool"] = "local-lvm"
|
||||
disk["storage_pool_type"] = "lvm"
|
||||
|
||||
disks := make([]map[string]interface{}, 0)
|
||||
disks = append(disks, disk)
|
||||
|
||||
cfg := mandatoryConfig(t)
|
||||
cfg["network_adapters"] = nics
|
||||
cfg["disks"] = disks
|
||||
cfg["scsi_controller"] = tt.controller
|
||||
|
||||
var c Config
|
||||
_, _, err := c.Prepare(cfg)
|
||||
|
||||
if tt.expectedToFail == true && err == nil {
|
||||
t.Error("expected config preparation to fail, but no error occured")
|
||||
}
|
||||
|
||||
if tt.expectedToFail == false && err != nil {
|
||||
t.Errorf("expected config preparation to succeed, but %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mandatoryConfig(t *testing.T) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"proxmox_url": "https://my-proxmox.my-domain:8006/api2/json",
|
||||
"username": "apiuser@pve",
|
||||
"password": "supersecret",
|
||||
"node": "my-proxmox",
|
||||
"ssh_username": "root",
|
||||
"iso_file": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso",
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
package proxmoxiso
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
type finalizerMock struct {
|
||||
getConfig func() (map[string]interface{}, error)
|
||||
setConfig func(map[string]interface{}) (string, error)
|
||||
}
|
||||
|
||||
func (m finalizerMock) GetVmConfig(*proxmox.VmRef) (map[string]interface{}, error) {
|
||||
return m.getConfig()
|
||||
}
|
||||
func (m finalizerMock) SetVmConfig(vmref *proxmox.VmRef, c map[string]interface{}) (interface{}, error) {
|
||||
return m.setConfig(c)
|
||||
}
|
||||
|
||||
var _ templateFinalizer = finalizerMock{}
|
||||
|
||||
func TestISOTemplateFinalize(t *testing.T) {
|
||||
cs := []struct {
|
||||
name string
|
||||
builderConfig *Config
|
||||
initialVMConfig map[string]interface{}
|
||||
getConfigErr error
|
||||
expectCallSetConfig bool
|
||||
expectedVMConfig map[string]interface{}
|
||||
setConfigErr error
|
||||
expectedAction multistep.StepAction
|
||||
}{
|
||||
{
|
||||
name: "default config does nothing",
|
||||
builderConfig: &Config{},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"ide2": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
},
|
||||
expectCallSetConfig: false,
|
||||
expectedVMConfig: map[string]interface{}{
|
||||
"ide2": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
},
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "should unmount when configured",
|
||||
builderConfig: &Config{
|
||||
UnmountISO: true,
|
||||
},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"ide2": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
},
|
||||
expectCallSetConfig: true,
|
||||
expectedVMConfig: map[string]interface{}{
|
||||
"ide2": "none,media=cdrom",
|
||||
},
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "no cd-drive with unmount=true should returns halt",
|
||||
builderConfig: &Config{
|
||||
UnmountISO: true,
|
||||
},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"ide1": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
},
|
||||
expectCallSetConfig: false,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
{
|
||||
name: "GetVmConfig error should return halt",
|
||||
builderConfig: &Config{
|
||||
UnmountISO: true,
|
||||
},
|
||||
getConfigErr: fmt.Errorf("some error"),
|
||||
expectCallSetConfig: false,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
{
|
||||
name: "SetVmConfig error should return halt",
|
||||
builderConfig: &Config{
|
||||
UnmountISO: true,
|
||||
},
|
||||
initialVMConfig: map[string]interface{}{
|
||||
"ide2": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso,media=cdrom",
|
||||
},
|
||||
expectCallSetConfig: true,
|
||||
setConfigErr: fmt.Errorf("some error"),
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cs {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
finalizer := finalizerMock{
|
||||
getConfig: func() (map[string]interface{}, error) {
|
||||
return c.initialVMConfig, c.getConfigErr
|
||||
},
|
||||
setConfig: func(cfg map[string]interface{}) (string, error) {
|
||||
if !c.expectCallSetConfig {
|
||||
t.Error("Did not expect SetVmConfig to be called")
|
||||
}
|
||||
for key, val := range c.expectedVMConfig {
|
||||
if cfg[key] != val {
|
||||
t.Errorf("Expected %q to be %q, got %q", key, val, cfg[key])
|
||||
}
|
||||
}
|
||||
|
||||
return "", c.setConfigErr
|
||||
},
|
||||
}
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packersdk.TestUi(t))
|
||||
state.Put("iso-config", c.builderConfig)
|
||||
state.Put("vmRef", proxmox.NewVmRef(1))
|
||||
state.Put("proxmoxClient", finalizer)
|
||||
|
||||
step := stepFinalizeISOTemplate{}
|
||||
action := step.Run(context.TODO(), state)
|
||||
if action != c.expectedAction {
|
||||
t.Errorf("Expected action to be %v, got %v", c.expectedAction, action)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
package proxmoxiso
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
type uploaderMock struct {
|
||||
fail bool
|
||||
wasCalled bool
|
||||
}
|
||||
|
||||
func (m *uploaderMock) Upload(node string, storage string, contentType string, filename string, file io.Reader) error {
|
||||
m.wasCalled = true
|
||||
if m.fail {
|
||||
return fmt.Errorf("Testing induced failure")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ uploader = &uploaderMock{}
|
||||
|
||||
func TestUploadISO(t *testing.T) {
|
||||
cs := []struct {
|
||||
name string
|
||||
builderConfig *Config
|
||||
downloadPath string
|
||||
failUpload bool
|
||||
|
||||
expectError bool
|
||||
expectUploadCalled bool
|
||||
expectedISOPath string
|
||||
expectedAction multistep.StepAction
|
||||
}{
|
||||
{
|
||||
name: "should not call upload unless configured to do so",
|
||||
builderConfig: &Config{shouldUploadISO: false, ISOFile: "local:iso/some-file"},
|
||||
|
||||
expectUploadCalled: false,
|
||||
expectedISOPath: "local:iso/some-file",
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "success should continue",
|
||||
builderConfig: &Config{
|
||||
shouldUploadISO: true,
|
||||
ISOStoragePool: "local",
|
||||
ISOConfig: commonsteps.ISOConfig{ISOUrls: []string{"http://server.example/some-file.iso"}},
|
||||
},
|
||||
downloadPath: "testdata/test.iso",
|
||||
|
||||
expectedISOPath: "local:iso/some-file.iso",
|
||||
expectUploadCalled: true,
|
||||
expectedAction: multistep.ActionContinue,
|
||||
},
|
||||
{
|
||||
name: "failing upload should halt",
|
||||
builderConfig: &Config{
|
||||
shouldUploadISO: true,
|
||||
ISOStoragePool: "local",
|
||||
ISOConfig: commonsteps.ISOConfig{ISOUrls: []string{"http://server.example/some-file.iso"}},
|
||||
},
|
||||
downloadPath: "testdata/test.iso",
|
||||
failUpload: true,
|
||||
|
||||
expectError: true,
|
||||
expectUploadCalled: true,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
{
|
||||
name: "downloader: state misconfiguration should halt",
|
||||
builderConfig: &Config{
|
||||
shouldUploadISO: true,
|
||||
ISOStoragePool: "local",
|
||||
ISOConfig: commonsteps.ISOConfig{ISOUrls: []string{"http://server.example/some-file.iso"}},
|
||||
},
|
||||
|
||||
expectError: true,
|
||||
expectUploadCalled: false,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
{
|
||||
name: "downloader: file unreadable should halt",
|
||||
builderConfig: &Config{
|
||||
shouldUploadISO: true,
|
||||
ISOStoragePool: "local",
|
||||
ISOConfig: commonsteps.ISOConfig{ISOUrls: []string{"http://server.example/some-file.iso"}},
|
||||
},
|
||||
downloadPath: "testdata/non-existent.iso",
|
||||
|
||||
expectError: true,
|
||||
expectUploadCalled: false,
|
||||
expectedAction: multistep.ActionHalt,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cs {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
m := &uploaderMock{fail: c.failUpload}
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packersdk.TestUi(t))
|
||||
state.Put("iso-config", c.builderConfig)
|
||||
state.Put(downloadPathKey, c.downloadPath)
|
||||
state.Put("proxmoxClient", m)
|
||||
|
||||
step := stepUploadISO{}
|
||||
action := step.Run(context.TODO(), state)
|
||||
step.Cleanup(state)
|
||||
|
||||
if action != c.expectedAction {
|
||||
t.Errorf("Expected action to be %v, got %v", c.expectedAction, action)
|
||||
}
|
||||
if m.wasCalled != c.expectUploadCalled {
|
||||
t.Errorf("Expected mock to be called: %v, got: %v", c.expectUploadCalled, m.wasCalled)
|
||||
}
|
||||
err, gotError := state.GetOk("error")
|
||||
if gotError != c.expectError {
|
||||
t.Errorf("Expected error state to be: %v, got: %v", c.expectError, gotError)
|
||||
}
|
||||
if err == nil {
|
||||
if isoPath := state.Get("iso_file"); isoPath != c.expectedISOPath {
|
||||
if _, ok := isoPath.(string); !ok {
|
||||
isoPath = ""
|
||||
}
|
||||
t.Errorf("Expected state iso_path to be %q, got %q", c.expectedISOPath, isoPath)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -1,13 +0,0 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/packer-plugin-sdk/version"
|
||||
packerVersion "github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
||||
var ProxmoxPluginVersion *version.PluginVersion
|
||||
|
||||
func init() {
|
||||
ProxmoxPluginVersion = version.InitializePluginVersion(
|
||||
packerVersion.Version, packerVersion.VersionPrerelease)
|
||||
}
|
|
@ -41,9 +41,6 @@ import (
|
|||
parallelsisobuilder "github.com/hashicorp/packer/builder/parallels/iso"
|
||||
parallelspvmbuilder "github.com/hashicorp/packer/builder/parallels/pvm"
|
||||
profitbricksbuilder "github.com/hashicorp/packer/builder/profitbricks"
|
||||
proxmoxbuilder "github.com/hashicorp/packer/builder/proxmox"
|
||||
proxmoxclonebuilder "github.com/hashicorp/packer/builder/proxmox/clone"
|
||||
proxmoxisobuilder "github.com/hashicorp/packer/builder/proxmox/iso"
|
||||
scalewaybuilder "github.com/hashicorp/packer/builder/scaleway"
|
||||
tencentcloudcvmbuilder "github.com/hashicorp/packer/builder/tencentcloud/cvm"
|
||||
tritonbuilder "github.com/hashicorp/packer/builder/triton"
|
||||
|
@ -113,9 +110,6 @@ var Builders = map[string]packersdk.Builder{
|
|||
"parallels-iso": new(parallelsisobuilder.Builder),
|
||||
"parallels-pvm": new(parallelspvmbuilder.Builder),
|
||||
"profitbricks": new(profitbricksbuilder.Builder),
|
||||
"proxmox": new(proxmoxbuilder.Builder),
|
||||
"proxmox-clone": new(proxmoxclonebuilder.Builder),
|
||||
"proxmox-iso": new(proxmoxisobuilder.Builder),
|
||||
"scaleway": new(scalewaybuilder.Builder),
|
||||
"tencentcloud-cvm": new(tencentcloudcvmbuilder.Builder),
|
||||
"triton": new(tritonbuilder.Builder),
|
||||
|
|
|
@ -25,6 +25,8 @@ import (
|
|||
googlecomputebuilder "github.com/hashicorp/packer-plugin-googlecompute/builder/googlecompute"
|
||||
googlecomputeexportpostprocessor "github.com/hashicorp/packer-plugin-googlecompute/post-processor/googlecompute-export"
|
||||
googlecomputeimportpostprocessor "github.com/hashicorp/packer-plugin-googlecompute/post-processor/googlecompute-import"
|
||||
proxmoxclone "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/clone"
|
||||
proxmoxiso "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/iso"
|
||||
qemubuilder "github.com/hashicorp/packer-plugin-qemu/builder/qemu"
|
||||
virtualboxisobuilder "github.com/hashicorp/packer-plugin-virtualbox/builder/virtualbox/iso"
|
||||
virtualboxovfbuilder "github.com/hashicorp/packer-plugin-virtualbox/builder/virtualbox/ovf"
|
||||
|
@ -54,6 +56,9 @@ var VendoredBuilders = map[string]packersdk.Builder{
|
|||
"amazon-instance": new(amazoninstancebuilder.Builder),
|
||||
"docker": new(dockerbuilder.Builder),
|
||||
"googlecompute": new(googlecomputebuilder.Builder),
|
||||
"proxmox": new(proxmoxiso.Builder),
|
||||
"proxmox-iso": new(proxmoxiso.Builder),
|
||||
"proxmox-clone": new(proxmoxclone.Builder),
|
||||
"qemu": new(qemubuilder.Builder),
|
||||
"vsphere-clone": new(vsphereclonebuilder.Builder),
|
||||
"vsphere-iso": new(vsphereisobuilder.Builder),
|
||||
|
|
2
go.mod
2
go.mod
|
@ -11,7 +11,6 @@ require (
|
|||
github.com/Azure/go-autorest/autorest/to v0.3.0
|
||||
github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022
|
||||
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.1.7
|
||||
github.com/Telmate/proxmox-api-go v0.0.0-20210331182840-ff89a0cebcfa
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190418113227-25233c783f4e
|
||||
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20170113022742-e6dbea820a9f
|
||||
github.com/antihax/optional v1.0.0
|
||||
|
@ -49,6 +48,7 @@ require (
|
|||
github.com/hashicorp/packer-plugin-ansible v0.0.2
|
||||
github.com/hashicorp/packer-plugin-docker v0.0.7
|
||||
github.com/hashicorp/packer-plugin-googlecompute v0.0.1
|
||||
github.com/hashicorp/packer-plugin-proxmox v0.0.1
|
||||
github.com/hashicorp/packer-plugin-qemu v0.0.1
|
||||
github.com/hashicorp/packer-plugin-sdk v0.2.0
|
||||
github.com/hashicorp/packer-plugin-virtualbox v0.0.1
|
||||
|
|
7
go.sum
7
go.sum
|
@ -89,8 +89,9 @@ github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUW
|
|||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/Telmate/proxmox-api-go v0.0.0-20200715182505-ec97c70ba887/go.mod h1:OGWyIMJ87/k/GCz8CGiWB2HOXsOVDM6Lpe/nFPkC4IQ=
|
||||
github.com/Telmate/proxmox-api-go v0.0.0-20210320143302-fea68269e6b0/go.mod h1:ayPkdmEKnlssqLQ9K1BE1jlsaYhXVwkoduXI30oQF0I=
|
||||
github.com/Telmate/proxmox-api-go v0.0.0-20210331182840-ff89a0cebcfa h1:n4g0+o4DDX6WGTRfdj1Ux+49vSwtxtqFGB5XtxoDphI=
|
||||
github.com/Telmate/proxmox-api-go v0.0.0-20210331182840-ff89a0cebcfa/go.mod h1:ayPkdmEKnlssqLQ9K1BE1jlsaYhXVwkoduXI30oQF0I=
|
||||
github.com/Telmate/proxmox-api-go v0.0.0-20210402150908-b9cc6607c070 h1:Up56ddjq6/wc46Ng+MDQYuDqVDHQMmbV+q8qSUImask=
|
||||
github.com/Telmate/proxmox-api-go v0.0.0-20210402150908-b9cc6607c070/go.mod h1:ayPkdmEKnlssqLQ9K1BE1jlsaYhXVwkoduXI30oQF0I=
|
||||
github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af h1:DBNMBMuMiWYu0b+8KMJuWmfCkcxl09JwdlqwDZZ6U14=
|
||||
github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw=
|
||||
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
||||
|
@ -462,8 +463,8 @@ github.com/hashicorp/packer-plugin-docker v0.0.7 h1:hMTrH7vrkFIjphtbbtpuzffTzSjM
|
|||
github.com/hashicorp/packer-plugin-docker v0.0.7/go.mod h1:IpeKlwOSy2kdgQcysqd3gCsoqjME9jtmpFoKxn7RRNI=
|
||||
github.com/hashicorp/packer-plugin-googlecompute v0.0.1 h1:Shjio88MraB+ocj0VI5+M65r4UBKbYI4eCqLNyPXKEo=
|
||||
github.com/hashicorp/packer-plugin-googlecompute v0.0.1/go.mod h1:MfV898IrEMpKH6wVnvOI5Tkhxm2snf3QxwVqV4k3bNI=
|
||||
github.com/hashicorp/packer-plugin-qemu v0.0.0-20210419131938-9ec808d0c364 h1:9vTNg4xYdp+PzBFSi+G2Nfc8qw7X1ebrBFKt4wmvARk=
|
||||
github.com/hashicorp/packer-plugin-qemu v0.0.0-20210419131938-9ec808d0c364/go.mod h1:8Q/LCjO7oplLcLe1KLdEt7rq94h42Di6Lab2DTLNwVg=
|
||||
github.com/hashicorp/packer-plugin-proxmox v0.0.1 h1:nwfQtfcfV4Gx4aiX1OQD/FoZvWCt2L4qaRYY7zTJ8L0=
|
||||
github.com/hashicorp/packer-plugin-proxmox v0.0.1/go.mod h1:3URutEWX1yy10qcHNJncS4OMpZknA1FyvlrfL+5usYk=
|
||||
github.com/hashicorp/packer-plugin-qemu v0.0.1 h1:yGnmWf4Z+ZmOJXJF6w23V2KChtTCiPHsFnfg7+LRu74=
|
||||
github.com/hashicorp/packer-plugin-qemu v0.0.1/go.mod h1:8Q/LCjO7oplLcLe1KLdEt7rq94h42Di6Lab2DTLNwVg=
|
||||
github.com/hashicorp/packer-plugin-sdk v0.0.6/go.mod h1:Nvh28f+Jmpp2rcaN79bULTouNkGNDRfHckhHKTAXtyU=
|
||||
|
|
|
@ -731,6 +731,11 @@ func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err e
|
|||
} else if nicConfMap["firewall"] == 0 {
|
||||
nicConfMap["firewall"] = false
|
||||
}
|
||||
if nicConfMap["link_down"] == 1 {
|
||||
nicConfMap["link_down"] = true
|
||||
} else if nicConfMap["link_down"] == 0 {
|
||||
nicConfMap["link_down"] = false
|
||||
}
|
||||
|
||||
// And device config to networks.
|
||||
if len(nicConfMap) > 0 {
|
||||
|
|
|
@ -0,0 +1,373 @@
|
|||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
|
@ -3,9 +3,9 @@ package proxmoxclone
|
|||
import (
|
||||
proxmoxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
proxmox "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
proxmox "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
|
||||
"context"
|
||||
"fmt"
|
|
@ -3,9 +3,9 @@
|
|||
package proxmoxclone
|
||||
|
||||
import (
|
||||
proxmox "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer-plugin-sdk/template/config"
|
||||
proxmox "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
)
|
||||
|
||||
type Config struct {
|
|
@ -4,7 +4,7 @@ package proxmoxclone
|
|||
|
||||
import (
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
proxmox "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
proxmox "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
|
@ -5,11 +5,11 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
common "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
|
||||
"github.com/hashicorp/packer-plugin-sdk/communicator/ssh"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer-plugin-sdk/uuid"
|
||||
common "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
)
|
||||
|
||||
// StepSshKeyPair executes the business logic for setting the SSH key pair in
|
|
@ -1,3 +1,4 @@
|
|||
//go:generate packer-sdc struct-markdown
|
||||
//go:generate packer-sdc mapstructure-to-hcl2 -type Config,nicConfig,diskConfig,vgaConfig,additionalISOsConfig
|
||||
|
||||
package proxmox
|
|
@ -5,10 +5,10 @@ import (
|
|||
|
||||
proxmoxapi "github.com/Telmate/proxmox-api-go/proxmox"
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
proxmox "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
proxmox "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
)
|
||||
|
||||
// The unique id for the builder
|
|
@ -5,9 +5,9 @@ package proxmoxiso
|
|||
import (
|
||||
"errors"
|
||||
|
||||
proxmox "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
|
||||
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
proxmox "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
)
|
||||
|
||||
type Config struct {
|
|
@ -4,7 +4,7 @@ package proxmoxiso
|
|||
|
||||
import (
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
proxmox "github.com/hashicorp/packer/builder/proxmox/common"
|
||||
proxmox "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
|
@ -79,8 +79,7 @@ github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/vpc
|
|||
github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/vserver
|
||||
# github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d
|
||||
github.com/StackExchange/wmi
|
||||
# github.com/Telmate/proxmox-api-go v0.0.0-20210331182840-ff89a0cebcfa
|
||||
## explicit
|
||||
# github.com/Telmate/proxmox-api-go v0.0.0-20210402150908-b9cc6607c070
|
||||
github.com/Telmate/proxmox-api-go/proxmox
|
||||
# github.com/agext/levenshtein v1.2.1
|
||||
github.com/agext/levenshtein
|
||||
|
@ -523,6 +522,11 @@ github.com/hashicorp/packer-plugin-googlecompute/builder/googlecompute
|
|||
github.com/hashicorp/packer-plugin-googlecompute/builder/googlecompute/version
|
||||
github.com/hashicorp/packer-plugin-googlecompute/post-processor/googlecompute-export
|
||||
github.com/hashicorp/packer-plugin-googlecompute/post-processor/googlecompute-import
|
||||
# github.com/hashicorp/packer-plugin-proxmox v0.0.1
|
||||
## explicit
|
||||
github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/clone
|
||||
github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common
|
||||
github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/iso
|
||||
# github.com/hashicorp/packer-plugin-qemu v0.0.1
|
||||
## explicit
|
||||
github.com/hashicorp/packer-plugin-qemu/builder/qemu
|
||||
|
|
|
@ -1,245 +0,0 @@
|
|||
---
|
||||
description: |
|
||||
The proxmox image Packer builder is able to create new images for use with
|
||||
Proxmox VE. The builder takes a cloud-init enabled virtual machine
|
||||
template name, runs any provisioning necessary on the image after
|
||||
launching it, then creates a virtual machine template.
|
||||
page_title: Proxmox Clone - Builders
|
||||
---
|
||||
|
||||
# Proxmox Builder (from an image)
|
||||
|
||||
Type: `proxmox-clone`
|
||||
Artifact BuilderId: `proxmox.clone`
|
||||
|
||||
The `proxmox-clone` Packer builder is able to create new images for use with
|
||||
[Proxmox](https://www.proxmox.com/en/proxmox-ve). The builder takes a virtual
|
||||
machine template, runs any provisioning necessary on the image after launching it,
|
||||
then creates a virtual machine template. This template can then be used as to
|
||||
create new virtual machines within Proxmox.
|
||||
|
||||
The builder does _not_ manage templates. Once it creates a template, it is up
|
||||
to you to use it or delete it.
|
||||
|
||||
## Configuration Reference
|
||||
|
||||
There are many configuration options available for the builder. They are
|
||||
segmented below into two categories: required and optional parameters. Within
|
||||
each category, the available configuration keys are alphabetized.
|
||||
|
||||
In addition to the options listed here, a
|
||||
[communicator](/docs/templates/legacy_json_templates/communicator) can be configured for this
|
||||
builder.
|
||||
|
||||
If no communicator is defined, an SSH key is generated for use, and is used
|
||||
in the image's Cloud-Init settings for provisioning.
|
||||
|
||||
### Required:
|
||||
|
||||
- `proxmox_url` (string) - URL to the Proxmox API, including the full path,
|
||||
so `https://<server>:<port>/api2/json` for example.
|
||||
Can also be set via the `PROXMOX_URL` environment variable.
|
||||
|
||||
- `username` (string) - Username when authenticating to Proxmox, including
|
||||
the realm. For example `user@pve` to use the local Proxmox realm.
|
||||
When used with `token`, it would look like this: `user@pve!token`
|
||||
Can also be set via the `PROXMOX_USERNAME` environment variable.
|
||||
|
||||
- `password` (string) - Password for the user.
|
||||
For API tokens please use `token`.
|
||||
Can also be set via the `PROXMOX_PASSWORD` environment variable.
|
||||
Either `password` or `token` must be specifed. If both are set,
|
||||
`token` takes precedence.
|
||||
|
||||
- `token` (string) - Token for authenticating API calls.
|
||||
This allows the API client to work with API tokens instead of user passwords.
|
||||
Can also be set via the `PROXMOX_TOKEN` environment variable.
|
||||
Either `password` or `token` must be specifed. If both are set,
|
||||
`token` takes precedence.
|
||||
|
||||
- `node` (string) - Which node in the Proxmox cluster to start the virtual
|
||||
machine on during creation.
|
||||
|
||||
- `clone_vm` (string) - The name of the VM Packer should clone and build from.
|
||||
|
||||
### Optional:
|
||||
|
||||
- `insecure_skip_tls_verify` (bool) - Skip validating the certificate.
|
||||
|
||||
- `pool` (string) - Name of resource pool to create virtual machine in.
|
||||
|
||||
- `vm_name` (string) - Name of the virtual machine during creation. If not
|
||||
given, a random uuid will be used.
|
||||
|
||||
- `vm_id` (int) - The ID used to reference the virtual machine. This will
|
||||
also be the ID of the final template. If not given, the next free ID on
|
||||
the node will be used.
|
||||
|
||||
- `memory` (int) - How much memory, in megabytes, to give the virtual
|
||||
machine. Defaults to `512`.
|
||||
|
||||
- `cores` (int) - How many CPU cores to give the virtual machine. Defaults
|
||||
to `1`.
|
||||
|
||||
- `sockets` (int) - How many CPU sockets to give the virtual machine.
|
||||
Defaults to `1`
|
||||
|
||||
- `cpu_type` (string) - The CPU type to emulate. See the Proxmox API
|
||||
documentation for the complete list of accepted values. For best
|
||||
performance, set this to `host`. Defaults to `kvm64`.
|
||||
|
||||
- `os` (string) - The operating system. Can be `wxp`, `w2k`, `w2k3`, `w2k8`,
|
||||
`wvista`, `win7`, `win8`, `win10`, `l24` (Linux 2.4), `l26` (Linux 2.6+),
|
||||
`solaris` or `other`. Defaults to `other`.
|
||||
|
||||
- `vga` (object) - The graphics adapter to use. Example:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "vmware",
|
||||
"memory": 32
|
||||
}
|
||||
```
|
||||
|
||||
- `type` (string) - Can be `cirrus`, `none`, `qxl`,`qxl2`, `qxl3`,
|
||||
`qxl4`, `serial0`, `serial1`, `serial2`, `serial3`, `std`, `virtio`, `vmware`.
|
||||
Defaults to `std`.
|
||||
|
||||
- `memory` (int) - How much memory to assign.
|
||||
|
||||
- `network_adapters` (array of objects) - Network adapters attached to the
|
||||
virtual machine. Example:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"model": "virtio",
|
||||
"bridge": "vmbr0",
|
||||
"vlan_tag": "10",
|
||||
"firewall": true
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- `bridge` (string) - Required. Which Proxmox bridge to attach the
|
||||
adapter to.
|
||||
|
||||
- `model` (string) - Model of the virtual network adapter. Can be
|
||||
`rtl8139`, `ne2k_pci`, `e1000`, `pcnet`, `virtio`, `ne2k_isa`,
|
||||
`i82551`, `i82557b`, `i82559er`, `vmxnet3`, `e1000-82540em`,
|
||||
`e1000-82544gc` or `e1000-82545em`. Defaults to `e1000`.
|
||||
|
||||
- `mac_address` (string) - Give the adapter a specific MAC address. If
|
||||
not set, defaults to a random MAC.
|
||||
|
||||
- `vlan_tag` (string) - If the adapter should tag packets. Defaults to
|
||||
no tagging.
|
||||
|
||||
- `firewall` (bool) - If the interface should be protected by the firewall.
|
||||
Defaults to `false`.
|
||||
|
||||
- `packet_queues` (int) - Number of packet queues to be used on the device.
|
||||
Values greater than 1 indicate that the multiqueue feature is activated.
|
||||
For best performance, set this to the number of cores available to the
|
||||
virtual machine. CPU load on the host and guest systems will increase as
|
||||
the traffic increases, so activate this option only when the VM has to
|
||||
handle a great number of incoming connections, such as when the VM is
|
||||
operating as a router, reverse proxy or a busy HTTP server. Requires
|
||||
`virtio` network adapter. Defaults to `0`.
|
||||
|
||||
- `disks` (array of objects) - Disks attached to the virtual machine.
|
||||
Example:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"type": "scsi",
|
||||
"disk_size": "5G",
|
||||
"storage_pool": "local-lvm",
|
||||
"storage_pool_type": "lvm"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- `storage_pool` (string) - Required. Name of the Proxmox storage pool
|
||||
to store the virtual machine disk on. A `local-lvm` pool is allocated
|
||||
by the installer, for example.
|
||||
|
||||
- `storage_pool_type` (string) - Required. The type of the pool, can
|
||||
be `lvm`, `lvm-thin`, `zfspool`, `cephfs`, `rbd` or `directory`.
|
||||
|
||||
- `type` (string) - The type of disk. Can be `scsi`, `sata`, `virtio` or
|
||||
`ide`. Defaults to `scsi`.
|
||||
|
||||
- `disk_size` (string) - The size of the disk, including a unit suffix, such
|
||||
as `10G` to indicate 10 gigabytes.
|
||||
|
||||
- `cache_mode` (string) - How to cache operations to the disk. Can be
|
||||
`none`, `writethrough`, `writeback`, `unsafe` or `directsync`.
|
||||
Defaults to `none`.
|
||||
|
||||
- `format` (string) - The format of the file backing the disk. Can be
|
||||
`raw`, `cow`, `qcow`, `qed`, `qcow2`, `vmdk` or `cloop`. Defaults to
|
||||
`raw`.
|
||||
|
||||
- `template_name` (string) - Name of the template. Defaults to the generated
|
||||
name used during creation.
|
||||
|
||||
- `template_description` (string) - Description of the template, visible in
|
||||
the Proxmox interface.
|
||||
|
||||
- `onboot` (boolean) - Specifies whether a VM will be started during system
|
||||
bootup. Defaults to `false`.
|
||||
|
||||
- `disable_kvm` (boolean) - Disables KVM hardware virtualization. Defaults to `false`.
|
||||
|
||||
- `scsi_controller` (string) - The SCSI controller model to emulate. Can be `lsi`,
|
||||
`lsi53c810`, `virtio-scsi-pci`, `virtio-scsi-single`, `megasas`, or `pvscsi`.
|
||||
Defaults to `lsi`.
|
||||
|
||||
- `full_clone` (bool) - Whether to run a full or shallow clone from the base clone_vm. Defaults to `true`.
|
||||
|
||||
- `boot` - (string) - Override default boot order. Format example `order=virtio0;ide2;net0`.
|
||||
Prior to Proxmox 6.2-15 the format was `cdn` (c:CDROM -> d:Disk -> n:Network)
|
||||
|
||||
## Example: Cloud-Init enabled Debian
|
||||
|
||||
Here is a basic example creating a Debian 10 server image. This assumes
|
||||
that there exists a Cloud-Init enabled image on the Proxmox server named
|
||||
`debian-10-4`.
|
||||
|
||||
```json
|
||||
{
|
||||
"variables": {
|
||||
"proxmox_url": "{{env `PROXMOX_URL`}}",
|
||||
"proxmox_username": "{{env `PROXMOX_USERNAME`}}",
|
||||
"proxmox_password": "{{env `PROXMOX_PASSWORD`}}"
|
||||
},
|
||||
|
||||
"builders": [
|
||||
{
|
||||
"type": "proxmox-clone",
|
||||
"proxmox_url": "{{user `proxmox_url`}}",
|
||||
"username": "{{user `proxmox_username`}}",
|
||||
"password": "{{user `proxmox_password`}}",
|
||||
"node": "pve",
|
||||
"insecure_skip_tls_verify": true,
|
||||
"clone_vm": "debian-10-4",
|
||||
"template_name": "debian-scaffolding",
|
||||
"template_description": "image made from cloud-init image",
|
||||
|
||||
"pool": "api-users",
|
||||
"os": "l26",
|
||||
"cores": 1,
|
||||
"sockets": 1,
|
||||
"memory": 2048,
|
||||
"network_adapters": [
|
||||
{
|
||||
"bridge": "vmbr0"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A template for building a base"
|
||||
}
|
||||
```
|
|
@ -1,26 +0,0 @@
|
|||
---
|
||||
description: >
|
||||
The Proxmox Packer builder is able to create Cloud-Init virtual machine images
|
||||
on a Proxmox server.
|
||||
page_title: Proxmox - Builders
|
||||
---
|
||||
|
||||
# Proxmox Builder
|
||||
|
||||
The Proxmox Packer builder is able to create
|
||||
[Proxmox](https://www.proxmox.com/en/proxmox-ve) virtual
|
||||
machines and store them as new Proxmox Virtual Machine images.
|
||||
|
||||
Packer is able to target both ISO and existing Cloud-Init images:
|
||||
|
||||
- [proxmox-clone](/docs/builders/proxmox/clone) - The proxmox image
|
||||
Packer builder is able to create new images for use with
|
||||
Proxmox VE. The builder takes a cloud-init enabled virtual machine
|
||||
template name, runs any provisioning necessary on the image after
|
||||
launching it, then creates a virtual machine template.
|
||||
|
||||
- [proxmox-iso](/docs/builders/proxmox/iso) - The proxmox Packer
|
||||
builder is able to create new images for use with
|
||||
Proxmox VE. The builder takes an ISO source, runs any provisioning
|
||||
necessary on the image after launching it, then creates a virtual machine
|
||||
template.
|
|
@ -1,369 +0,0 @@
|
|||
---
|
||||
description: |
|
||||
The proxmox Packer builder is able to create new images for use with
|
||||
Proxmox VE. The builder takes an ISO source, runs any provisioning
|
||||
necessary on the image after launching it, then creates a virtual machine
|
||||
template.
|
||||
page_title: Proxmox ISO - Builders
|
||||
---
|
||||
|
||||
# Proxmox Builder (from an ISO)
|
||||
|
||||
Type: `proxmox-iso`
|
||||
Artifact BuilderId: `proxmox.iso`
|
||||
|
||||
The `proxmox-iso` Packer builder is able to create new images for use with
|
||||
[Proxmox](https://www.proxmox.com/en/proxmox-ve). The builder takes an ISO
|
||||
image, runs any provisioning necessary on the image after launching it, then
|
||||
creates a virtual machine template. This template can then be used as to
|
||||
create new virtual machines within Proxmox.
|
||||
|
||||
The builder does _not_ manage templates. Once it creates a template, it is up
|
||||
to you to use it or delete it.
|
||||
|
||||
## Configuration Reference
|
||||
|
||||
There are many configuration options available for the builder. They are
|
||||
segmented below into two categories: required and optional parameters. Within
|
||||
each category, the available configuration keys are alphabetized.
|
||||
|
||||
In addition to the options listed here, a
|
||||
[communicator](/docs/templates/legacy_json_templates/communicator) can be configured for this
|
||||
builder.
|
||||
|
||||
### Required:
|
||||
|
||||
- `proxmox_url` (string) - URL to the Proxmox API, including the full path,
|
||||
so `https://<server>:<port>/api2/json` for example.
|
||||
Can also be set via the `PROXMOX_URL` environment variable.
|
||||
|
||||
- `username` (string) - Username when authenticating to Proxmox, including
|
||||
the realm. For example `user@pve` to use the local Proxmox realm.
|
||||
When used with `token`, it would look like this: `user@pve!token`
|
||||
Can also be set via the `PROXMOX_USERNAME` environment variable.
|
||||
|
||||
- `password` (string) - Password for the user.
|
||||
For API tokens please use `token`.
|
||||
Can also be set via the `PROXMOX_PASSWORD` environment variable.
|
||||
Either `password` or `token` must be specifed. If both are set,
|
||||
`token` takes precedence.
|
||||
|
||||
- `token` (string) - Token for authenticating API calls.
|
||||
This allows the API client to work with API tokens instead of user passwords.
|
||||
Can also be set via the `PROXMOX_TOKEN` environment variable.
|
||||
Either `password` or `token` must be specifed. If both are set,
|
||||
`token` takes precedence.
|
||||
|
||||
- `node` (string) - Which node in the Proxmox cluster to start the virtual
|
||||
machine on during creation.
|
||||
|
||||
- `iso_file` (string) - Path to the ISO file to boot from, expressed as a
|
||||
proxmox datastore path, for example
|
||||
`local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso`.
|
||||
Either `iso_file` OR `iso_url` must be specifed.
|
||||
|
||||
- `iso_url` (string) - URL to an ISO file to upload to Proxmox, and then
|
||||
boot from. Either `iso_file` OR `iso_url` must be specifed.
|
||||
|
||||
- `iso_storage_pool` (string) - Proxmox storage pool onto which to upload
|
||||
the ISO file.
|
||||
|
||||
- `iso_checksum` (string) - Checksum of the ISO file. Type of the checksum
|
||||
is infered based on string length, or can be explicitly prefixed with
|
||||
md5:, sha1:, sha256:, sha512: or set to none. Corruption of large files,
|
||||
such as ISOs, can occur during transfer from time to time. As such,
|
||||
setting this to none is not recommended.
|
||||
|
||||
### Optional:
|
||||
|
||||
- `insecure_skip_tls_verify` (bool) - Skip validating the certificate.
|
||||
|
||||
- `pool` (string) - Name of resource pool to create virtual machine in.
|
||||
|
||||
- `vm_name` (string) - Name of the virtual machine during creation. If not
|
||||
given, a random uuid will be used.
|
||||
|
||||
- `vm_id` (int) - The ID used to reference the virtual machine. This will
|
||||
also be the ID of the final template. If not given, the next free ID on
|
||||
the node will be used.
|
||||
|
||||
- `memory` (int) - How much memory, in megabytes, to give the virtual
|
||||
machine. Defaults to `512`.
|
||||
|
||||
- `cores` (int) - How many CPU cores to give the virtual machine. Defaults
|
||||
to `1`.
|
||||
|
||||
- `sockets` (int) - How many CPU sockets to give the virtual machine.
|
||||
Defaults to `1`
|
||||
|
||||
- `cpu_type` (string) - The CPU type to emulate. See the Proxmox API
|
||||
documentation for the complete list of accepted values. For best
|
||||
performance, set this to `host`. Defaults to `kvm64`.
|
||||
|
||||
- `os` (string) - The operating system. Can be `wxp`, `w2k`, `w2k3`, `w2k8`,
|
||||
`wvista`, `win7`, `win8`, `win10`, `l24` (Linux 2.4), `l26` (Linux 2.6+),
|
||||
`solaris` or `other`. Defaults to `other`.
|
||||
|
||||
- `vga` (object) - The graphics adapter to use. Example:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "vmware",
|
||||
"memory": 32
|
||||
}
|
||||
```
|
||||
|
||||
- `type` (string) - Can be `cirrus`, `none`, `qxl`,`qxl2`, `qxl3`,
|
||||
`qxl4`, `serial0`, `serial1`, `serial2`, `serial3`, `std`, `virtio`, `vmware`.
|
||||
Defaults to `std`.
|
||||
|
||||
- `memory` (int) - How much memory to assign.
|
||||
|
||||
- `network_adapters` (array of objects) - Network adapters attached to the
|
||||
virtual machine. Example:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"model": "virtio",
|
||||
"bridge": "vmbr0",
|
||||
"vlan_tag": "10",
|
||||
"firewall": true
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- `bridge` (string) - Required. Which Proxmox bridge to attach the
|
||||
adapter to.
|
||||
|
||||
- `model` (string) - Model of the virtual network adapter. Can be
|
||||
`rtl8139`, `ne2k_pci`, `e1000`, `pcnet`, `virtio`, `ne2k_isa`,
|
||||
`i82551`, `i82557b`, `i82559er`, `vmxnet3`, `e1000-82540em`,
|
||||
`e1000-82544gc` or `e1000-82545em`. Defaults to `e1000`.
|
||||
|
||||
- `mac_address` (string) - Give the adapter a specific MAC address. If
|
||||
not set, defaults to a random MAC.
|
||||
|
||||
- `vlan_tag` (string) - If the adapter should tag packets. Defaults to
|
||||
no tagging.
|
||||
|
||||
- `firewall` (bool) - If the interface should be protected by the firewall.
|
||||
Defaults to `false`.
|
||||
|
||||
- `packet_queues` (int) - Number of packet queues to be used on the device.
|
||||
Values greater than 1 indicate that the multiqueue feature is activated.
|
||||
For best performance, set this to the number of cores available to the
|
||||
virtual machine. CPU load on the host and guest systems will increase as
|
||||
the traffic increases, so activate this option only when the VM has to
|
||||
handle a great number of incoming connections, such as when the VM is
|
||||
operating as a router, reverse proxy or a busy HTTP server. Requires
|
||||
`virtio` network adapter. Defaults to `0`.
|
||||
|
||||
- `disks` (array of objects) - Disks attached to the virtual machine.
|
||||
Example:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"type": "scsi",
|
||||
"disk_size": "5G",
|
||||
"storage_pool": "local-lvm",
|
||||
"storage_pool_type": "lvm"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- `storage_pool` (string) - Required. Name of the Proxmox storage pool
|
||||
to store the virtual machine disk on. A `local-lvm` pool is allocated
|
||||
by the installer, for example.
|
||||
|
||||
- `storage_pool_type` (string) - Required. The type of the pool, can
|
||||
be `lvm`, `lvm-thin`, `zfspool`, `cephfs`, `rbd` or `directory`.
|
||||
|
||||
- `type` (string) - The type of disk. Can be `scsi`, `sata`, `virtio` or
|
||||
`ide`. Defaults to `scsi`.
|
||||
|
||||
- `disk_size` (string) - The size of the disk, including a unit suffix, such
|
||||
as `10G` to indicate 10 gigabytes.
|
||||
|
||||
- `cache_mode` (string) - How to cache operations to the disk. Can be
|
||||
`none`, `writethrough`, `writeback`, `unsafe` or `directsync`.
|
||||
Defaults to `none`.
|
||||
|
||||
- `format` (string) - The format of the file backing the disk. Can be
|
||||
`raw`, `cow`, `qcow`, `qed`, `qcow2`, `vmdk` or `cloop`. Defaults to
|
||||
`raw`.
|
||||
|
||||
- `io_thread` (bool) - Create one I/O thread per storage controller, rather
|
||||
than a single thread for all I/O. This can increase performance when
|
||||
multiple disks are used. Requires `virtio-scsi-single` controller and a
|
||||
`scsi` or `virtio` disk. Defaults to `false`.
|
||||
|
||||
- `template_name` (string) - Name of the template. Defaults to the generated
|
||||
name used during creation.
|
||||
|
||||
- `template_description` (string) - Description of the template, visible in
|
||||
the Proxmox interface.
|
||||
|
||||
- `unmount_iso` (bool) - If true, remove the mounted ISO from the template
|
||||
after finishing. Defaults to `false`.
|
||||
|
||||
- `onboot` (boolean) - Specifies whether a VM will be started during system
|
||||
bootup. Defaults to `false`.
|
||||
|
||||
- `qemu_agent` (boolean) - Disables QEMU Agent option for this VM. When enabled,
|
||||
then `qemu-guest-agent` must be installed on the guest. When disabled, then
|
||||
`ssh_host` should be used. Defaults to `true`.
|
||||
|
||||
- `disable_kvm` (boolean) - Disables KVM hardware virtualization. Defaults to `false`.
|
||||
|
||||
- `scsi_controller` (string) - The SCSI controller model to emulate. Can be `lsi`,
|
||||
`lsi53c810`, `virtio-scsi-pci`, `virtio-scsi-single`, `megasas`, or `pvscsi`.
|
||||
Defaults to `lsi`.
|
||||
|
||||
- `cloud_init` (bool) - If true, add a Cloud-Init CDROM drive after the virtual machine has been converted to a template.
|
||||
Defaults to `false`.
|
||||
|
||||
- `cloud_init_storage_pool` - (string) - Name of the Proxmox storage pool
|
||||
to store the Cloud-Init CDROM on. If not given, the storage pool of the boot device will be used.
|
||||
|
||||
- `additional_iso_files` (array of objects) - Additional ISO files attached to the virtual machine.
|
||||
Example:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"device": "scsi5",
|
||||
"iso_file": "local:iso/virtio-win-0.1.185.iso",
|
||||
"unmount": true,
|
||||
"iso_checksum": "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- `device` (string) - Bus type and bus index that the ISO will be mounted on. Can be `ideX`,
|
||||
`sataX` or `scsiX`.
|
||||
For `ide` the bus index ranges from 0 to 3, for `sata` form 0 to 5 and for
|
||||
`scsi` from 0 to 30.
|
||||
Defaults to `ide3` since `ide2` is generelly the boot drive.
|
||||
|
||||
- `iso_file` (string) - Path to the ISO file to boot from, expressed as a
|
||||
proxmox datastore path, for example
|
||||
`local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso`.
|
||||
Either `iso_file` OR `iso_url` must be specifed.
|
||||
|
||||
- `iso_url` (string) - URL to an ISO file to upload to Proxmox, and then
|
||||
boot from. Either `iso_file` OR `iso_url` must be specifed.
|
||||
|
||||
- `iso_storage_pool` (string) - Proxmox storage pool onto which to upload
|
||||
the ISO file.
|
||||
|
||||
- `iso_checksum` (string) - Checksum of the ISO file.
|
||||
- `unmount` (bool) - If true, remove the mounted ISO from the template after finishing. Defaults to `false`.
|
||||
|
||||
- `http_interface` - (string) - Name of the network interface that Packer gets
|
||||
`HTTPIP` from. Defaults to the first non loopback interface.
|
||||
|
||||
- `vm_interface` - (string) - Name of the network interface that Packer gets
|
||||
the VMs IP from. Defaults to the first non loopback interface.
|
||||
|
||||
- `boot` - (string) - Override default boot order. Format example `order=virtio0;ide2;net0`.
|
||||
Prior to Proxmox 6.2-15 the format was `cdn` (c:CDROM -> d:Disk -> n:Network)
|
||||
|
||||
## Boot Command
|
||||
|
||||
The `boot_command` configuration is very important: it specifies the keys to
|
||||
type when the virtual machine is first booted in order to start the OS
|
||||
installer. This command is typed after `boot_wait`, which gives the virtual
|
||||
machine some time to actually load the ISO.
|
||||
|
||||
As documented above, the `boot_command` is an array of strings. The strings
|
||||
are all typed in sequence. It is an array only to improve readability within
|
||||
the template.
|
||||
|
||||
The boot command is "typed" character for character over the virtual keyboard
|
||||
to the machine, simulating a human actually typing the keyboard.
|
||||
|
||||
@include 'builders/boot-command.mdx'
|
||||
|
||||
The example shown below is a working boot command used to start an Ubuntu
|
||||
12.04 installer:
|
||||
|
||||
```json
|
||||
[
|
||||
"<esc><esc><enter><wait>",
|
||||
"/install/vmlinuz noapic ",
|
||||
"preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
|
||||
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
|
||||
"hostname={{ .Name }} ",
|
||||
"fb=false debconf/frontend=noninteractive ",
|
||||
"keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
|
||||
"keyboard-configuration/variant=USA console-setup/ask_detect=false ",
|
||||
"initrd=/install/initrd.gz -- <enter>"
|
||||
]
|
||||
```
|
||||
|
||||
For more examples of various boot commands, see the sample projects from our
|
||||
[community templates page](/community-tools#templates).
|
||||
|
||||
## Http directory configuration
|
||||
|
||||
@include 'packer-plugin-sdk/multistep/commonsteps/HTTPConfig.mdx'
|
||||
|
||||
### Optional:
|
||||
|
||||
@include 'packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx'
|
||||
|
||||
## Example: Fedora with kickstart
|
||||
|
||||
Here is a basic example creating a Fedora 29 server image with a Kickstart
|
||||
file served with Packer's HTTP server. Note that the iso file needs to be
|
||||
manually downloaded.
|
||||
|
||||
```json
|
||||
{
|
||||
"variables": {
|
||||
"username": "apiuser@pve",
|
||||
"password": "supersecret"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "proxmox",
|
||||
"proxmox_url": "https://my-proxmox.my-domain:8006/api2/json",
|
||||
"insecure_skip_tls_verify": true,
|
||||
"username": "{{user `username`}}",
|
||||
"password": "{{user `password`}}",
|
||||
|
||||
"node": "my-proxmox",
|
||||
"network_adapters": [
|
||||
{
|
||||
"bridge": "vmbr0"
|
||||
}
|
||||
],
|
||||
"disks": [
|
||||
{
|
||||
"type": "scsi",
|
||||
"disk_size": "5G",
|
||||
"storage_pool": "local-lvm",
|
||||
"storage_pool_type": "lvm"
|
||||
}
|
||||
],
|
||||
|
||||
"iso_file": "local:iso/Fedora-Server-dvd-x86_64-29-1.2.iso",
|
||||
"http_directory": "config",
|
||||
"boot_wait": "10s",
|
||||
"boot_command": [
|
||||
"<up><tab> ip=dhcp inst.cmdline inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/ks.cfg<enter>"
|
||||
],
|
||||
|
||||
"ssh_username": "root",
|
||||
"ssh_timeout": "15m",
|
||||
"ssh_password": "packer",
|
||||
|
||||
"unmount_iso": true,
|
||||
"template_name": "fedora-29",
|
||||
"template_description": "Fedora 29-1.2, generated on {{ isotime \"2006-01-02T15:04:05Z\" }}"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
|
@ -7,14 +7,20 @@
|
|||
started. The address and port of the HTTP server will be available as
|
||||
variables in `boot_command`. This is covered in more detail below.
|
||||
|
||||
- `http_content` (map[string]string) - Key/Values to serve using an HTTP server. http_content works like and
|
||||
conflicts with http_directory The keys represent the paths and the values
|
||||
contents. This is useful for hosting kickstart files and so on. By
|
||||
- `http_content` (map[string]string) - Key/Values to serve using an HTTP server. `http_content` works like and
|
||||
conflicts with `http_directory`. The keys represent the paths and the
|
||||
values contents, the keys must start with a slash, ex: `/path/to/file`.
|
||||
`http_content` is useful for hosting kickstart files and so on. By
|
||||
default this is empty, which means no HTTP server will be started. The
|
||||
address and port of the HTTP server will be available as variables in
|
||||
`boot_command`. This is covered in more detail below. Example: Setting
|
||||
`"foo/bar"="baz"`, will allow you to http get on
|
||||
`http://{http_ip}:{http_port}/foo/bar`.
|
||||
`boot_command`. This is covered in more detail below.
|
||||
Example:
|
||||
```hcl
|
||||
http_content = {
|
||||
"/a/b" = file("http/b")
|
||||
"/foo/bar" = templatefile("${path.root}/preseed.cfg", { packages = ["nginx"] })
|
||||
}
|
||||
```
|
||||
|
||||
- `http_port_min` (int) - These are the minimum and maximum port to use for the HTTP server
|
||||
started to serve the `http_directory`. Because Packer often runs in
|
||||
|
@ -27,3 +33,5 @@
|
|||
|
||||
- `http_bind_address` (string) - This is the bind address for the HTTP server. Defaults to 0.0.0.0 so that
|
||||
it will work with any network interface.
|
||||
|
||||
<!-- End of code generated from the comments of the HTTPConfig struct in multistep/commonsteps/http_config.go; -->
|
||||
|
|
|
@ -828,23 +828,6 @@
|
|||
"title": "ProfitBricks",
|
||||
"path": "builders/profitbricks"
|
||||
},
|
||||
{
|
||||
"title": "Proxmox",
|
||||
"routes": [
|
||||
{
|
||||
"title": "Overview",
|
||||
"path": "builders/proxmox"
|
||||
},
|
||||
{
|
||||
"title": "ISO",
|
||||
"path": "builders/proxmox/iso"
|
||||
},
|
||||
{
|
||||
"title": "Clone",
|
||||
"path": "builders/proxmox/clone"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Scaleway",
|
||||
"path": "builders/scaleway"
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
"repo": "hashicorp/packer-plugin-googlecompute",
|
||||
"version": "latest"
|
||||
},
|
||||
{
|
||||
"title": "Proxmox",
|
||||
"path": "proxmox",
|
||||
"repo": "hashicorp/packer-plugin-proxmox",
|
||||
"version": "latest"
|
||||
},
|
||||
{
|
||||
"title": "VirtualBox",
|
||||
"path": "virtualbox",
|
||||
|
|
Loading…
Reference in New Issue