From 858d4c7541249200feb528067600daf23bd45b7b Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Wed, 25 Mar 2015 13:07:46 -0700 Subject: [PATCH] Use 'checkout' time to calculate 'running' time --- lib/vmpooler/api/v1.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index 1989dae..1e3f9e9 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -453,7 +453,12 @@ module Vmpooler result[params[:hostname]]['template'] = rdata['template'] result[params[:hostname]]['lifetime'] = rdata['lifetime'] || $config[:config]['vm_lifetime'] - result[params[:hostname]]['running'] = ((Time.now - Time.parse($redis.hget('vmpooler__active__' + result[params[:hostname]]['template'], params[:hostname]))) / 60 / 60).round(2) + + if rdata['destroy'] + result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2) + else + result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2) + end rdata.keys.each do |key| if key.match('^tag\:(.+?)$')