0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-01 11:02:59 +00:00

fix(vm): optimize retrieval of VM volume attributes from a datastore (#862)

* Use GetDatastoreFile instead of ListDatastoreFiles

Signed-off-by: CppBunny <noah@vantiggel.be>

* make linter happy

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>

---------

Signed-off-by: CppBunny <noah@vantiggel.be>
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
CppBunny 2024-01-07 14:31:30 +01:00 committed by GitHub
parent 6c8f3d4f0c
commit 613be842be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 21 deletions

View File

@ -72,12 +72,7 @@ func (c *Client) ListDatastoreFiles(
func (c *Client) GetDatastoreFile(
ctx context.Context,
volumeID string,
nodeName string,
) (*DatastoreFileGetResponseData, error) {
reqBody := &DatastoreFileGetRequestData{
Node: nodeName,
VolumeID: volumeID,
}
resBody := &DatastoreFileGetResponseBody{}
err := c.DoRequest(
@ -89,7 +84,7 @@ func (c *Client) GetDatastoreFile(
url.PathEscape(volumeID),
),
),
reqBody,
nil,
resBody,
)
if err != nil {

View File

@ -4187,18 +4187,13 @@ func vmReadCustom(
if datastoreID != "" {
// disk format may not be returned by config API if it is default for the storage, and that may be different
// from the default qcow2, so we need to read it from the storage API to make sure we have the correct value
files, err := api.Node(nodeName).Storage(datastoreID).ListDatastoreFiles(ctx)
volume, err := api.Node(nodeName).Storage(datastoreID).GetDatastoreFile(ctx, dd.FileVolume)
if err != nil {
diags = append(diags, diag.FromErr(err)...)
continue
}
for _, v := range files {
if v.VolumeID == dd.FileVolume {
disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = v.FileFormat
break
}
}
disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = volume.FileFormat
}
} else {
disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = dd.Format
@ -4292,17 +4287,11 @@ func vmReadCustom(
} else {
// disk format may not be returned by config API if it is default for the storage, and that may be different
// from the default qcow2, so we need to read it from the storage API to make sure we have the correct value
files, err := api.Node(nodeName).Storage(fileIDParts[0]).ListDatastoreFiles(ctx)
volume, err := api.Node(nodeName).Storage(fileIDParts[0]).GetDatastoreFile(ctx, vmConfig.EFIDisk.FileVolume)
if err != nil {
diags = append(diags, diag.FromErr(err)...)
} else {
efiDisk[mkResourceVirtualEnvironmentVMEFIDiskFileFormat] = ""
for _, v := range files {
if v.VolumeID == vmConfig.EFIDisk.FileVolume {
efiDisk[mkResourceVirtualEnvironmentVMEFIDiskFileFormat] = v.FileFormat
break
}
}
efiDisk[mkResourceVirtualEnvironmentVMEFIDiskFileFormat] = volume.FileFormat
}
}