0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-08-23 03:48:35 +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( func (c *Client) GetDatastoreFile(
ctx context.Context, ctx context.Context,
volumeID string, volumeID string,
nodeName string,
) (*DatastoreFileGetResponseData, error) { ) (*DatastoreFileGetResponseData, error) {
reqBody := &DatastoreFileGetRequestData{
Node: nodeName,
VolumeID: volumeID,
}
resBody := &DatastoreFileGetResponseBody{} resBody := &DatastoreFileGetResponseBody{}
err := c.DoRequest( err := c.DoRequest(
@ -89,7 +84,7 @@ func (c *Client) GetDatastoreFile(
url.PathEscape(volumeID), url.PathEscape(volumeID),
), ),
), ),
reqBody, nil,
resBody, resBody,
) )
if err != nil { if err != nil {

View File

@ -4187,18 +4187,13 @@ func vmReadCustom(
if datastoreID != "" { if datastoreID != "" {
// disk format may not be returned by config API if it is default for the storage, and that may be different // 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 // 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 { if err != nil {
diags = append(diags, diag.FromErr(err)...) diags = append(diags, diag.FromErr(err)...)
continue continue
} }
for _, v := range files { disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = volume.FileFormat
if v.VolumeID == dd.FileVolume {
disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = v.FileFormat
break
}
}
} }
} else { } else {
disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = dd.Format disk[mkResourceVirtualEnvironmentVMDiskFileFormat] = dd.Format
@ -4292,17 +4287,11 @@ func vmReadCustom(
} else { } else {
// disk format may not be returned by config API if it is default for the storage, and that may be different // 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 // 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 { if err != nil {
diags = append(diags, diag.FromErr(err)...) diags = append(diags, diag.FromErr(err)...)
} else { } else {
efiDisk[mkResourceVirtualEnvironmentVMEFIDiskFileFormat] = "" efiDisk[mkResourceVirtualEnvironmentVMEFIDiskFileFormat] = volume.FileFormat
for _, v := range files {
if v.VolumeID == vmConfig.EFIDisk.FileVolume {
efiDisk[mkResourceVirtualEnvironmentVMEFIDiskFileFormat] = v.FileFormat
break
}
}
} }
} }