Skip to content

Commit

Permalink
Handle [total|used]_space columns being nil
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jan 7, 2021
1 parent 14f0689 commit fb2489d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/models/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,17 +576,17 @@ def self.get_common_refresh_targets(storages)
end

def used_space
total_space.to_i == 0 ? 0 : total_space.to_i - free_space.to_i
total_space.to_i.zero? ? 0 : total_space.to_i - free_space.to_i
end
alias_method :v_used_space, :used_space

def used_space_percent_of_total
total_space.zero? ? 0.0 : (used_space.to_f / total_space * 1000.0).round / 10.0
total_space.to_i.zero? ? 0.0 : (used_space.to_f / total_space * 1000.0).round / 10.0
end
alias_method :v_used_space_percent_of_total, :used_space_percent_of_total

def free_space_percent_of_total
total_space.zero? ? 0.0 : (free_space.to_f / total_space * 1000.0).round / 10.0
total_space.to_i.zero? ? 0.0 : (free_space.to_f / total_space * 1000.0).round / 10.0
end
alias_method :v_free_space_percent_of_total, :free_space_percent_of_total

Expand Down Expand Up @@ -618,31 +618,31 @@ def v_total_vms
alias_method :v_total_disk_size, :disk_size

def v_debris_percent_of_used
used_space.zero? ? 0.0 : (debris_size.to_f / used_space * 1000.0).round / 10.0
used_space.to_i.zero? ? 0.0 : (debris_size.to_f / used_space * 1000.0).round / 10.0
end

def v_snapshot_percent_of_used
used_space.zero? ? 0.0 : (snapshot_size.to_f / used_space * 1000.0).round / 10.0
used_space.to_i.zero? ? 0.0 : (snapshot_size.to_f / used_space * 1000.0).round / 10.0
end

def v_memory_percent_of_used
used_space.zero? ? 0.0 : (vm_ram_size.to_f / used_space * 1000.0).round / 10.0
used_space.to_i.zero? ? 0.0 : (vm_ram_size.to_f / used_space * 1000.0).round / 10.0
end

def v_vm_misc_percent_of_used
used_space.zero? ? 0.0 : (vm_misc_size.to_f / used_space * 1000.0).round / 10.0
used_space.to_i.zero? ? 0.0 : (vm_misc_size.to_f / used_space * 1000.0).round / 10.0
end

def v_disk_percent_of_used
used_space.zero? ? 0.0 : (disk_size.to_f / used_space * 1000.0).round / 10.0
used_space.to_i.zero? ? 0.0 : (disk_size.to_f / used_space * 1000.0).round / 10.0
end

def v_total_provisioned
used_space + uncommitted.to_i
end

def v_provisioned_percent_of_total
total_space.zero? ? 0.0 : (v_total_provisioned.to_f / total_space * 1000.0).round / 10.0
total_space.to_i.zero? ? 0.0 : (v_total_provisioned.to_f / total_space * 1000.0).round / 10.0
end

#
Expand Down

0 comments on commit fb2489d

Please sign in to comment.