From 13401465c9b4136b75d3814f470f0e7f46e05fe6 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Fri, 11 Apr 2025 09:02:15 -0400 Subject: [PATCH] fix(vm,lxc): error parsing disk ID when datastore name contains `.` (#1894) Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmox/nodes/vms/custom_storage_device.go | 15 +++++++++++---- proxmox/nodes/vms/custom_storage_device_test.go | 12 ++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/proxmox/nodes/vms/custom_storage_device.go b/proxmox/nodes/vms/custom_storage_device.go index 7df5b01e..0aab1f9a 100644 --- a/proxmox/nodes/vms/custom_storage_device.go +++ b/proxmox/nodes/vms/custom_storage_device.go @@ -243,10 +243,17 @@ func (d *CustomStorageDevice) UnmarshalJSON(b []byte) error { if len(v) == 1 { d.FileVolume = v[0] - ext := filepath.Ext(v[0]) - if ext != "" { - format := string([]byte(ext)[1:]) - d.Format = &format + // split file volume into datastore ID and path + _, pathInDatastore, hasDatastoreID := strings.Cut(v[0], ":") + if hasDatastoreID { + // we don't set them here,... but probably should + // d.DatastoreID = &probablyDatastoreID + // d.FileID = &pathInDatastore + ext := filepath.Ext(pathInDatastore) + if ext != "" { + format := string([]byte(ext)[1:]) + d.Format = &format + } } } else if len(v) == 2 { switch v[0] { diff --git a/proxmox/nodes/vms/custom_storage_device_test.go b/proxmox/nodes/vms/custom_storage_device_test.go index 7a55f5a0..8c16709f 100644 --- a/proxmox/nodes/vms/custom_storage_device_test.go +++ b/proxmox/nodes/vms/custom_storage_device_test.go @@ -38,6 +38,18 @@ func TestCustomStorageDevice_UnmarshalJSON(t *testing.T) { SSD: types.CustomBool(true).Pointer(), }, }, + { + name: "volume with dot", + line: `"volumes.hdd:base-269-disk-0,cache=writeback,discard=on,iothread=1,size=8G,ssd=1"`, + want: &CustomStorageDevice{ + Cache: ptr.Ptr("writeback"), + Discard: ptr.Ptr("on"), + FileVolume: "volumes.hdd:base-269-disk-0", + IOThread: types.CustomBool(true).Pointer(), + Size: ds8gig, + SSD: types.CustomBool(true).Pointer(), + }, + }, { name: "raw volume type", line: `"nfs:2041/vm-2041-disk-0.raw,discard=ignore,ssd=1,iothread=1,size=8G"`,