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: disk id enumeration overwrite #254

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 13 additions & 6 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ func NewConfigQemuFromJson(input []byte) (config *ConfigQemu, err error) {
var (
rxIso = regexp.MustCompile(`(.*?),media`)
rxDeviceID = regexp.MustCompile(`\d+`)
rxDiskName = regexp.MustCompile(`(virtio|scsi|ide|sata)\d+`)
rxDiskType = regexp.MustCompile(`\D+`)
rxUnusedDiskName = regexp.MustCompile(`^(unused)\d+`)
rxNicName = regexp.MustCompile(`net\d+`)
Expand Down Expand Up @@ -723,13 +722,20 @@ func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err e

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

for k := range vmConfig {
if diskName := rxDiskName.FindStringSubmatch(k); len(diskName) > 0 {
diskNames = append(diskNames, diskName[0])
diskTypes := []string{"scsi", "virtio", "sata", "ide"}

// Search for disks in a predictable order
for _, t := range diskTypes {
// 30 is the max number for scsi disks
for i := 0; i <= 30; i++ {
n := fmt.Sprintf("%s%d", t, i)
if _, ok := vmConfig[n]; ok {
diskNames = append(diskNames, n)
}
}
}

var diskIndex int = 0
for _, diskName := range diskNames {
var isDiskByID bool = false
diskConfStr := vmConfig[diskName].(string)
Expand Down Expand Up @@ -800,7 +806,8 @@ func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err e

// And device config to disks map.
if len(diskConfMap) > 0 {
config.QemuDisks[diskID] = diskConfMap
config.QemuDisks[diskIndex] = diskConfMap
diskIndex += 1
}
}

Expand Down