Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Proxmox v8.0.4 panic interface {} is string, not float64 #280

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 212 additions & 0 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,218 @@
if vmConfig["lock"] != nil {
return nil, fmt.Errorf("vm locked, could not obtain config")
}

// vmConfig Sample: map[ cpu:host
// net0:virtio=62:DF:XX:XX:XX:XX,bridge=vmbr0
// ide2:local:iso/xxx-xx.iso,media=cdrom memory:2048
// smbios1:uuid=8b3bf833-aad8-4545-xxx-xxxxxxx digest:aa6ce5xxxxx1b9ce33e4aaeff564d4 sockets:1
// name:terraform-ubuntu1404-template bootdisk:virtio0
// virtio0:ProxmoxxxxISCSI:vm-1014-disk-2,size=4G
// description:Base image
// cores:2 ostype:l26

name := ""
if _, isSet := vmConfig["name"]; isSet {
name = vmConfig["name"].(string)
}
description := ""
if _, isSet := vmConfig["description"]; isSet {
description = vmConfig["description"].(string)
}
tags := ""
if _, isSet := vmConfig["tags"]; isSet {
tags = vmConfig["tags"].(string)
}
args := ""
if _, isSet := vmConfig["args"]; isSet {
args = vmConfig["args"].(string)
}

bios := "seabios"
if _, isSet := vmConfig["bios"]; isSet {
bios = vmConfig["bios"].(string)
}
onboot := true
if _, isSet := vmConfig["onboot"]; isSet {
onboot = Itob(int(vmConfig["onboot"].(float64)))
}
startup := ""
if _, isSet := vmConfig["startup"]; isSet {
startup = vmConfig["startup"].(string)
}
tablet := true
if _, isSet := vmConfig["tablet"]; isSet {
tablet = Itob(int(vmConfig["tablet"].(float64)))
}

agent := 0
if _, isSet := vmConfig["agent"]; isSet {
switch vmConfig["agent"].(type) {
case float64:
agent = int(vmConfig["agent"].(float64))
case string:
AgentConfList := strings.Split(vmConfig["agent"].(string), ",")
agent, _ = strconv.Atoi(AgentConfList[0])
}

}
ostype := "other"
if _, isSet := vmConfig["ostype"]; isSet {
ostype = vmConfig["ostype"].(string)
}
memory := 0.0
if _, isSet := vmConfig["memory"]; isSet {
switch vmConfig["memory"].(type) {
case float64:
memory = vmConfig["memory"].(float64)
case string:
memory2, err := strconv.ParseFloat(vmConfig["memory"].(string), 64)
if err != nil {
log.Fatal(err)
return nil, err
} else {
memory = memory2
}
}
}
balloon := 0.0
if _, isSet := vmConfig["balloon"]; isSet {
balloon = vmConfig["balloon"].(float64)
}
cores := 1.0
if _, isSet := vmConfig["cores"]; isSet {
cores = vmConfig["cores"].(float64)
}
vcpus := 0.0
if _, isSet := vmConfig["vcpus"]; isSet {
vcpus = vmConfig["vcpus"].(float64)
}
sockets := 1.0
if _, isSet := vmConfig["sockets"]; isSet {
sockets = vmConfig["sockets"].(float64)
}
cpu := "host"
if _, isSet := vmConfig["cpu"]; isSet {
cpu = vmConfig["cpu"].(string)
}
numa := false
if _, isSet := vmConfig["numa"]; isSet {
numa = Itob(int(vmConfig["numa"].(float64)))
}
//Can be network,disk,cpu,memory,usb
hotplug := "network,disk,usb"
if _, isSet := vmConfig["hotplug"]; isSet {
hotplug = vmConfig["hotplug"].(string)
}
//boot by default from hard disk (c), CD-ROM (d), network (n).
boot := "cdn"
if _, isSet := vmConfig["boot"]; isSet {
boot = vmConfig["boot"].(string)
}
bootdisk := ""
if _, isSet := vmConfig["bootdisk"]; isSet {
bootdisk = vmConfig["bootdisk"].(string)
}
kvm := true
if _, isSet := vmConfig["kvm"]; isSet {
kvm = Itob(int(vmConfig["kvm"].(float64)))
}
scsihw := "lsi"
if _, isSet := vmConfig["scsihw"]; isSet {
scsihw = vmConfig["scsihw"].(string)
}
hookscript := ""
if _, isSet := vmConfig["hookscript"]; isSet {
hookscript = vmConfig["hookscript"].(string)
}

config = &ConfigQemu{
Name: name,
Description: strings.TrimSpace(description),
Tags: strings.TrimSpace(tags),
Args: strings.TrimSpace(args),
Bios: bios,
EFIDisk: QemuDevice{},
Onboot: &onboot,
Startup: startup,
Tablet: &tablet,
Agent: agent,
QemuOs: ostype,
Memory: int(memory),
QemuCores: int(cores),
QemuSockets: int(sockets),
QemuCpu: cpu,
QemuNuma: &numa,
QemuKVM: &kvm,
Hotplug: hotplug,
Boot: boot,
BootDisk: bootdisk,
Scsihw: scsihw,
Hookscript: hookscript,
QemuDisks: QemuDevices{},
QemuUnusedDisks: QemuDevices{},
QemuVga: QemuDevice{},
QemuNetworks: QemuDevices{},
QemuSerials: QemuDevices{},
QemuPCIDevices: QemuDevices{},
QemuUsbs: QemuDevices{},
Ipconfig: IpconfigMap{},
}

if balloon >= 1 {
config.Balloon = int(balloon)
}
if vcpus >= 1 {
config.QemuVcpus = int(vcpus)
}

if vmConfig["ide2"] != nil {
isoMatch := rxIso.FindStringSubmatch(vmConfig["ide2"].(string))
config.QemuIso = isoMatch[1]
}

// Add Cloud-Init options
if _, isSet := vmConfig["ciuser"]; isSet {
config.CIuser = vmConfig["ciuser"].(string)
}
if _, isSet := vmConfig["cipassword"]; isSet {
config.CIpassword = vmConfig["cipassword"].(string)
}
if _, isSet := vmConfig["cicustom"]; isSet {
config.CIcustom = vmConfig["cicustom"].(string)
}
if _, isSet := vmConfig["searchdomain"]; isSet {
config.Searchdomain = vmConfig["searchdomain"].(string)
}
if _, isSet := vmConfig["nameserver"]; isSet {
config.Nameserver = vmConfig["nameserver"].(string)
}
if _, isSet := vmConfig["sshkeys"]; isSet {
config.Sshkeys, _ = url.PathUnescape(vmConfig["sshkeys"].(string))
}

ipconfigNames := []string{}

for k := range vmConfig {
if ipconfigName := rxIpconfigName.FindStringSubmatch(k); len(ipconfigName) > 0 {
ipconfigNames = append(ipconfigNames, ipconfigName[0])
}
}

for _, ipconfigName := range ipconfigNames {
ipConfStr := vmConfig[ipconfigName]
id := rxDeviceID.FindStringSubmatch(ipconfigName)
ipconfigID, _ := strconv.Atoi(id[0])
config.Ipconfig[ipconfigID] = ipConfStr
}

// Add disks.
diskNames := []string{}

for k := range vmConfig {
if diskName := rxDiskName.FindStringSubmatch(k); len(diskName) > 0 {
diskNames = append(diskNames, diskName[0])
}
config, err = ConfigQemu{}.mapToStruct(vmConfig)
if err != nil {
return
Expand Down Expand Up @@ -1259,7 +1471,7 @@
}

// Useful waiting for ISO install to complete
func WaitForShutdown(vmr *VmRef, client *Client) (err error) {

Check failure on line 1474 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected WaitForShutdown, expecting (
for ii := 0; ii < 100; ii++ {
vmState, err := client.GetVmState(vmr)
if err != nil {
Expand All @@ -1274,7 +1486,7 @@
}

// This is because proxmox create/config API won't let us make usernet devices
func SshForwardUsernet(vmr *VmRef, client *Client) (sshPort string, err error) {

Check failure on line 1489 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected SshForwardUsernet, expecting (
vmState, err := client.GetVmState(vmr)
if err != nil {
return "", err
Expand All @@ -1295,7 +1507,7 @@
}

// URL encodes the ssh keys
func sshKeyUrlEncode(keys string) (encodedKeys string) {

Check failure on line 1510 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected sshKeyUrlEncode, expecting (
encodedKeys = url.PathEscape(keys + "\n")
encodedKeys = strings.Replace(encodedKeys, "+", "%2B", -1)
encodedKeys = strings.Replace(encodedKeys, "@", "%40", -1)
Expand All @@ -1306,7 +1518,7 @@

// device_del net1
// netdev_del net1
func RemoveSshForwardUsernet(vmr *VmRef, client *Client) (err error) {

Check failure on line 1521 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected RemoveSshForwardUsernet, expecting (
vmState, err := client.GetVmState(vmr)
if err != nil {
return err
Expand All @@ -1325,7 +1537,7 @@
return nil
}

func MaxVmId(client *Client) (max int, err error) {

Check failure on line 1540 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected MaxVmId, expecting (
vms, err := client.GetResourceList(resourceListGuest)
max = 100
for vmii := range vms {
Expand All @@ -1338,7 +1550,7 @@
return
}

func SendKeysString(vmr *VmRef, client *Client, keys string) (err error) {

Check failure on line 1553 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected SendKeysString, expecting (
vmState, err := client.GetVmState(vmr)
if err != nil {
return err
Expand Down Expand Up @@ -1405,14 +1617,14 @@
}

// Given a QemuDevice, return a param string to give to ProxMox
func formatDeviceParam(device QemuDevice) string {

Check failure on line 1620 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected formatDeviceParam, expecting (
deviceConfParams := QemuDeviceParam{}
deviceConfParams = deviceConfParams.createDeviceParam(device, nil)
return strings.Join(deviceConfParams, ",")
}

// Given a QemuDevice (representing a disk), return a param string to give to ProxMox
func FormatDiskParam(disk QemuDevice) string {

Check failure on line 1627 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected FormatDiskParam, expecting (
diskConfParam := QemuDeviceParam{}

if volume, ok := disk["volume"]; ok && volume != "" {
Expand Down Expand Up @@ -1463,7 +1675,7 @@
}

// Given a QemuDevice (representing a usb), return a param string to give to ProxMox
func FormatUsbParam(usb QemuDevice) string {

Check failure on line 1678 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected FormatUsbParam, expecting (
usbConfParam := QemuDeviceParam{}

usbConfParam = usbConfParam.createDeviceParam(usb, []string{})
Expand All @@ -1472,7 +1684,7 @@
}

// Create parameters for each Nic device.
func (c ConfigQemu) CreateQemuNetworksParams(params map[string]interface{}) {

Check failure on line 1687 in proxmox/config_qemu.go

View workflow job for this annotation

GitHub Actions / audit

syntax error: unexpected map in argument list; possibly missing comma or )
// For new style with multi net device.
for nicID, nicConfMap := range c.QemuNetworks {

Expand Down
Loading