(POOLER-81) Add time_remaining information

Before, the only time calculation displayed for a given VM was the
lifetime parameter. Added the remaining parameter which will
display time until the VM is destroyed as a float.

Additionally, start_time and end_time were added to api to return
as UTC based times (e.g. 2018-07-10 11:01:03 -0700).
This commit is contained in:
Spencer McElmurry 2018-07-05 15:46:55 -07:00
parent 84065dd059
commit f95b878c8a
2 changed files with 25 additions and 0 deletions

View file

@ -645,6 +645,9 @@ module Vmpooler
result[params[:hostname]]['state'] = 'destroyed'
elsif rdata['checkout']
result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
result[params[:hostname]]['remaining'] = ((Time.parse(rdata['checkout']) + rdata['lifetime'].to_i*60*60 - Time.now) / 60 / 60).round(2).abs
result[params[:hostname]]['start_time'] = Time.parse(rdata['checkout'])
result[params[:hostname]]['end_time'] = Time.parse(rdata['checkout']) + rdata['lifetime'].to_i*60*60
result[params[:hostname]]['state'] = 'running'
elsif rdata['check']
result[params[:hostname]]['state'] = 'ready'