Module: DataValidators::DataCompute
- Included in:
- ApelDataValidator, LogstashDataValidator, PbsDataValidator
- Defined in:
- lib/data_validators/data_compute.rb
Instance Method Summary collapse
-
#sum_disk_size(disks, vm_id) ⇒ Integer
Sums disk size of all disks within the virtual machine.
-
#sum_rstime(history_records, completed, vm_id) ⇒ Integer
Sums RSTIME (time when virtual machine was actually running).
Instance Method Details
#sum_disk_size(disks, vm_id) ⇒ Integer
Sums disk size of all disks within the virtual machine
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/data_validators/data_compute.rb', line 39 def sum_disk_size(disks, vm_id) return nil unless disks disk_size = 0 disks.each do |disk| size = default(disk['size'], :number, nil) unless size log.warn("Disk size invalid for vm with id #{vm_id}") return nil end disk_size += size.to_i end disk_size end |
#sum_rstime(history_records, completed, vm_id) ⇒ Integer
Sums RSTIME (time when virtual machine was actually running)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/data_validators/data_compute.rb', line 11 def sum_rstime(history_records, completed, vm_id) return nil unless history_records rstime = 0 history_records.each do |record| next unless default(record['rstart_time'], :nzn, nil) && default(record['rend_time'], :number, nil) rstart_time = record['rstart_time'].to_i rend_time = record['rend_time'].to_i if (rend_time > 0 && rstart_time > rend_time) || (rend_time == 0 && completed) fail Errors::ValidationError, 'Skipping a malformed record. '\ "History records' times are invalid for vm with id #{vm_id}." end rend_time = rend_time == 0 ? Time.now.to_i : rend_time rstime += rend_time - rstart_time end rstime end |