-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(POOLER-81) Add time_remaining information #276
Conversation
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.
@@ -644,7 +644,10 @@ def invalid_template_or_path(payload) | |||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -644,7 +644,10 @@ def invalid_template_or_path(payload) | |||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only question would be if something is using this existing API, like kermi or bitbar/vmfloaty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this with vmfloaty and it just returns the json:
➜ vmpooler git:(pooler-81) # floaty get debian-7-i386
{"debian-7-i386":"poolvm-me51df2cadymlq0.company.com"}
➜ vmpooler git:(pooler-81) # floaty query poolvm-me51df2cadymlq0
{
"ok"=>true,
"poolvm-me51df2cadymlq0"=>
{"template"=>"debian-7-i386",
"lifetime"=>24,
"running"=>"00h 00m 08s",
"time_remaining"=>"23h 59m 51s",
"state"=>"running",
"ip"=>"",
"domain"=>"company.com"}
}
➜ vmpooler git:(pooler-81) #
Not sure about bitbar or kerminator. Is there a plugin for kermi? I wasn't aware of that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like bitbar expects this to be a float64 value. So, we may consider pushing an update there before rolling out this change. Either way I think it's reasonable to merge and we can discuss whether to update bitbar before pushing this change out to instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd personally prefer if the running/time_remaining returned from the API didn't come formatted, would be preferable to leave this up to the client.
Or even better a start_time field, with TZ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a public API, this would be considered a breaking change (going from a Float to Formatted String). I know my PowerShell Pooler code will blow up because of this.
+1 to @johnmccabe . If the data is coming back formatted, the API should expose the raw data somehow and/or the explicitly say this is the "friendly" text version e.g.
{
"ok"=>true,
"poolvm-me51df2cadymlq0"=>
{"template"=>"debian-7-i386",
"lifetime"=>24,
"running"=>"0.01",
"start_time" => "2018-01-01 01:02:03Z"
"time_remaining"=>"23.99",
"end_time" => "2018-01-02 01:02:03Z"
"state"=>"running",
"ip"=>"",
"domain"=>"company.com"}
}
This looks reasonable to me. I wonder if we can add a block to the vm_spec tests |
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.