Skip to content

Commit

Permalink
Ensure VmRestorePoints are an Array. (#3)
Browse files Browse the repository at this point in the history
* Ensure VmRestorePoints are an Array.
  • Loading branch information
ykohut authored Mar 3, 2020
1 parent 21e9786 commit c809957
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions recovery_points_for_virtual_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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

0 comments on commit c809957

Please sign in to comment.