Skip to content

Commit

Permalink
Merge pull request #7 from ArtemHushcha/feature/VMWARE-818-add-abbili…
Browse files Browse the repository at this point in the history
…ty-to-get-backup-size

[VMWARE-818] Add ability to get backup size directly for vm_restore_point
  • Loading branch information
ArtemHushcha authored Apr 8, 2022
2 parents ea6c9c8 + 0bb0658 commit e6470ff
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions recovery_points_for_virtual_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def call(virtual_server)
next
end

# Get BackupSize for restorePoints
backup_size = get_backup_size(backup_id)

# Get vmRestorePoints for restorePoints
get_recovery_points("restorePoints", rp_id, "vmRestorePoints")
.flatten
Expand All @@ -43,6 +40,9 @@ def call(virtual_server)
# Restore point date is right after '@' rightmost occurrence
vm_restore_point_date = vm_restore_point_hash[:Name].rpartition('@')[2]

# Get BackupSize for restorePoints
backup_size = get_backup_size(vm_restore_point_hash)

build_recovery_point(size: backup_size,
created_at: vm_restore_point_date,
updated_at: vm_restore_point_date,
Expand Down Expand Up @@ -80,14 +80,14 @@ def get_vm_recovery_points(resource_id)
vm_points.is_a?(Hash) ? [vm_points] : vm_points
end

def get_backup_size(backup_id)
api_get(
build_query(:BackupFile, BackupUid: identifier_to_uid(:Backup, backup_id))
)
.dig(:QueryResult, :Entities, :BackupFiles, :BackupFile)
.map { |hash| hash.transform_keys(&:downcase) }
.max_by { |hash| Time.parse(hash[:creationtimeutc]) if hash[:creationtimeutc] }
&.fetch(:backupsize, 0)
def get_backup_size(vm_restore_point_hash)
refs = vm_restore_point_hash.dig(:Links, :Link)

backup_file_id = refs.detect { |hash| hash[:Type] == 'BackupFileReference' }&.fetch(:Href, '')&.rpartition('/')&.last

return 0 unless backup_file_id

api_get("backupFiles/#{backup_file_id}?format=Entity").dig(:BackupFile, :BackupSize)
rescue RestClient::BadRequest
0
end
Expand Down

0 comments on commit e6470ff

Please sign in to comment.