From c8099570c098bd35acf254c19d3aee037a704f08 Mon Sep 17 00:00:00 2001 From: Yuriy Kohut Date: Tue, 3 Mar 2020 15:52:41 +0200 Subject: [PATCH] Ensure VmRestorePoints are an Array. (#3) * Ensure VmRestorePoints are an Array. --- recovery_points_for_virtual_server.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/recovery_points_for_virtual_server.rb b/recovery_points_for_virtual_server.rb index 4de3f64..25a0242 100644 --- a/recovery_points_for_virtual_server.rb +++ b/recovery_points_for_virtual_server.rb @@ -2,10 +2,7 @@ def call(virtual_server) # Get VmRestorePoint for Virtual Server - vm_recovery_points = - api_get( - build_query(:vmrestorepoint, HierarchyObjRef: "\"#{virtual_server.metadata[:veeam_uid]}\"") - ).dig(:QueryResult, :Entities, :VmRestorePoints, :VmRestorePoint) + vm_recovery_points = get_vm_recovery_points(virtual_server.metadata[:veeam_uid]) # Iterate over Jobs => Backup => restorePoints => vmRestorePoints virtual_server.metadata[:veeam_related_job_ids].flat_map do |job_id| @@ -72,4 +69,12 @@ def get_recovery_points(resource_type, resource_id, points_type) points.is_a?(Hash) ? [points] : points end + + def get_vm_recovery_points(resource_id) + vm_points = api_get(build_query(:vmrestorepoint, HierarchyObjRef: "\"#{resource_id}\"")) + .dig(:QueryResult, :Entities, :VmRestorePoints, :VmRestorePoint) || [] + + vm_points.is_a?(Hash) ? [vm_points] : vm_points + end + end