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:
parent
6c8f3d4f0c
commit
613be842be
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user