Skip to content

Commit

Permalink
bump api version to fix tags with hyphens
Browse files Browse the repository at this point in the history
  • Loading branch information
mpywell authored and lbajolet-hashicorp committed Oct 28, 2024
1 parent 07788d3 commit ebbd33b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
79 changes: 72 additions & 7 deletions builder/proxmox/clone/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
package proxmoxclone

import (
"crypto"
"net/netip"
"strings"

proxmoxapi "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/hcl/v2/hcldec"
proxmox "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common"
Expand Down Expand Up @@ -61,17 +65,78 @@ func (*cloneVMCreator) Create(vmRef *proxmoxapi.VmRef, config proxmoxapi.ConfigQ
config.FullClone = &fullClone

// cloud-init options
config.CIuser = comm.SSHUsername
config.Sshkeys = string(comm.SSHPublicKey)
config.Nameserver = c.Nameserver
config.Searchdomain = c.Searchdomain
IpconfigMap := make(map[int]interface{})

var nameServers []netip.Addr
if c.Nameserver != "" {
for _, nameserver := range strings.Split(c.Nameserver, " ") {
ip, _ := netip.ParseAddr(nameserver)
nameServers = append(nameServers, ip)
}
}

IpconfigMap := proxmoxapi.CloudInitNetworkInterfaces{}
for idx := range c.Ipconfigs {
if c.Ipconfigs[idx] != (cloudInitIpconfig{}) {
IpconfigMap[idx] = c.Ipconfigs[idx].String()

// backwards compatibility conversions

var ipv4cfg proxmoxapi.CloudInitIPv4Config
var ipv6cfg proxmoxapi.CloudInitIPv6Config

// cloudInitIpconfig.Ip accepts a CIDR address or 'dhcp' string
switch c.Ipconfigs[idx].Ip {
case "dhcp":
ipv4cfg.DHCP = true
default:
if c.Ipconfigs[idx].Ip != "" {
addr := proxmoxapi.IPv4CIDR(c.Ipconfigs[idx].Ip)
ipv4cfg.Address = &addr
}
}
if c.Ipconfigs[idx].Gateway != "" {
gw := proxmoxapi.IPv4Address(c.Ipconfigs[idx].Gateway)
ipv4cfg.Gateway = &gw
}

// cloudInitIpconfig.Ip6 accepts a CIDR address, 'auto' or 'dhcp' string
switch c.Ipconfigs[idx].Ip6 {
case "dhcp":
ipv6cfg.DHCP = true
case "auto":
ipv6cfg.SLAAC = true
default:
if c.Ipconfigs[idx].Ip6 != "" {
addr := proxmoxapi.IPv6CIDR(c.Ipconfigs[idx].Ip6)
ipv6cfg.Address = &addr
}
}
if c.Ipconfigs[idx].Gateway6 != "" {
addr := proxmoxapi.IPv6Address(c.Ipconfigs[idx].Gateway6)
ipv6cfg.Gateway = &addr
}

IpconfigMap[proxmoxapi.QemuNetworkInterfaceID(idx)] = proxmoxapi.CloudInitNetworkConfig{
IPv4: &ipv4cfg,
IPv6: &ipv6cfg,
}
}
}
config.Ipconfig = IpconfigMap

var publicKey []crypto.PublicKey

if comm.SSHPublicKey != nil {
publicKey = append(publicKey, crypto.PublicKey(string(comm.SSHPublicKey)))
}

config.CloudInit = &proxmoxapi.CloudInit{
Username: &comm.SSHUsername,
PublicSSHkeys: &publicKey,
DNS: &proxmoxapi.GuestDNS{
NameServers: &nameServers,
SearchDomain: &c.Searchdomain,
},
NetworkInterfaces: IpconfigMap,
}

var sourceVmr *proxmoxapi.VmRef
if c.CloneVM != "" {
Expand Down
4 changes: 3 additions & 1 deletion builder/proxmox/common/step_start_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
}
}

var description = "Packer ephemeral build VM"

config := proxmox.ConfigQemu{
Name: c.VMName,
Agent: generateAgentConfig(c.Agent),
QemuKVM: &kvm,
Tags: generateTags(c.Tags),
Boot: c.Boot, // Boot priority, example: "order=virtio0;ide2;net0", virtio0:Disk0 -> ide0:CDROM -> net0:Network
QemuCpu: c.CPUType,
Description: "Packer ephemeral build VM",
Description: &description,
Memory: c.Memory,
QemuCores: c.Cores,
QemuSockets: c.Sockets,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/hashicorp/packer-plugin-proxmox
go 1.21.0

require (
github.com/Telmate/proxmox-api-go v0.0.0-20240525163725-6676d8933df0
github.com/Telmate/proxmox-api-go v0.0.0-20240726134822-4c4580d03d9e
github.com/hashicorp/go-getter/v2 v2.2.2
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/packer-plugin-sdk v0.5.4
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ github.com/Telmate/proxmox-api-go v0.0.0-20240409105641-32c480fe008e h1:NdpVflh7
github.com/Telmate/proxmox-api-go v0.0.0-20240409105641-32c480fe008e/go.mod h1:bscBzOUx0tJAdVGmQvcnoWPg5eI2eJ6anJKV1ueZ1oU=
github.com/Telmate/proxmox-api-go v0.0.0-20240525163725-6676d8933df0 h1:VK35Q0s1IayA2Nwm0uREu+LVs0WWPq9Zsn3Oic1q5eg=
github.com/Telmate/proxmox-api-go v0.0.0-20240525163725-6676d8933df0/go.mod h1:bscBzOUx0tJAdVGmQvcnoWPg5eI2eJ6anJKV1ueZ1oU=
github.com/Telmate/proxmox-api-go v0.0.0-20240615154505-578dffaf4d38 h1:ViSuq1kQmOHycY8pvwDo319UwuuEnqhRXp4b0EiMJW4=
github.com/Telmate/proxmox-api-go v0.0.0-20240615154505-578dffaf4d38/go.mod h1:bscBzOUx0tJAdVGmQvcnoWPg5eI2eJ6anJKV1ueZ1oU=
github.com/Telmate/proxmox-api-go v0.0.0-20240726134822-4c4580d03d9e h1:e2StaFGv+J2yhCP29DBQmchLQHNqbCnLomZGx66p6/Q=
github.com/Telmate/proxmox-api-go v0.0.0-20240726134822-4c4580d03d9e/go.mod h1:O6yNUi0hG9GQLMBgpikSvbnuek1OMweFtbac1sfGuUs=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down

0 comments on commit ebbd33b

Please sign in to comment.