From b6e592caf3b085681fce0376c73f5f49b7178b55 Mon Sep 17 00:00:00 2001 From: Spencer McElmurry Date: Thu, 5 Jul 2018 15:46:55 -0700 Subject: [PATCH] (POOLER-81) Add time_remaining information Before, the only time calculation displayed for a given VM was the lifetime parameter. Added the time_remaining parameter which will display time until the VM is destroyed in hours, minutes, seconds. Additionally, updated the running parameter to display in a similar fashion as time_remaining. --- lib/vmpooler/api/v1.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index 29d52a6..f57d49e 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -644,7 +644,10 @@ module Vmpooler result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2) result[params[:hostname]]['state'] = 'destroyed' elsif rdata['checkout'] - result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2) + running = Time.now - Time.parse(rdata['checkout']) + result[params[:hostname]]['running'] = format("%02dh %02dm %02ds", running / (60 * 60), (running / 60) % 60, running % 60) + remaining = Time.parse(rdata['checkout']) + rdata['lifetime'].to_i*60*60 - Time.now + result[params[:hostname]]['time_remaining'] = format("%02dh %02dm %02ds", remaining / (60 * 60), (remaining / 60) % 60, remaining % 60) result[params[:hostname]]['state'] = 'running' elsif rdata['check'] result[params[:hostname]]['state'] = 'ready'