Status local/remote
This commit is contained in:
@ -5,21 +5,31 @@ module Faaso
|
||||
funko = Funko::Funko.from_names([name])[0]
|
||||
status = funko.docker_status
|
||||
|
||||
Log.info { "Name: #{status["name"]}" }
|
||||
Log.info { "Scale: #{status["scale"]}" }
|
||||
Log.info { "Name: #{status.@name}" }
|
||||
Log.info { "Scale: #{status.scale}" }
|
||||
|
||||
Log.info { "Containers: #{status["containers"].size}" }
|
||||
status["containers"].each do |container|
|
||||
Log.info { "Containers: #{status.containers.size}" }
|
||||
status.containers.each do |container|
|
||||
Log.info { " #{container.@names[0]} #{container.status}" }
|
||||
end
|
||||
|
||||
Log.info { "Images: #{status["images"].size}" }
|
||||
status["images"].each do |image|
|
||||
Log.info { " #{image.repo_tags} #{image.created}" }
|
||||
Log.info { "Images: #{status.images.size}" }
|
||||
status.images.each do |image|
|
||||
Log.info { " #{image.repo_tags} #{Time.unix(image.created)}" }
|
||||
end
|
||||
end
|
||||
|
||||
def remote(options, name)
|
||||
response = Crest.get(
|
||||
"#{FAASO_SERVER}funkos/#{name}/status/", \
|
||||
user: "admin", password: "admin")
|
||||
body = JSON.parse(response.body)
|
||||
Log.info { body["output"] }
|
||||
rescue ex : Crest::InternalServerError
|
||||
Log.error { "Error scaling funko #{name}" }
|
||||
body = JSON.parse(ex.response.body)
|
||||
Log.info { body["output"] }
|
||||
exit 1
|
||||
end
|
||||
|
||||
def run(options, name)
|
||||
|
@ -5,6 +5,18 @@ require "../funko.cr"
|
||||
module Funko
|
||||
extend self
|
||||
|
||||
# Get the funko's status
|
||||
get "/funkos/:name/status/" do |env|
|
||||
name = env.params.url["name"]
|
||||
response = run_faaso(["status", name])
|
||||
|
||||
if response["exit_code"] != 0
|
||||
halt env, status_code: 500, response: response.to_json
|
||||
else
|
||||
response.to_json
|
||||
end
|
||||
end
|
||||
|
||||
# Get the funko's scale
|
||||
get "/funkos/:name/scale/" do |env|
|
||||
name = env.params.url["name"]
|
||||
|
26
src/funko.cr
26
src/funko.cr
@ -6,6 +6,20 @@ require "yaml"
|
||||
module Funko
|
||||
extend self
|
||||
|
||||
struct Status
|
||||
property name : String = ""
|
||||
property scale : Int32 = 0
|
||||
property containers : Array(Docr::Types::ContainerSummary) = [] of Docr::Types::ContainerSummary
|
||||
property images : Array(Docr::Types::ImageSummary) = [] of Docr::Types::ImageSummary
|
||||
|
||||
def initialize(name, scale, containers, images)
|
||||
@name = name
|
||||
@scale = scale
|
||||
@containers = containers
|
||||
@images = images
|
||||
end
|
||||
end
|
||||
|
||||
class Funko
|
||||
include YAML::Serializable
|
||||
|
||||
@ -168,12 +182,12 @@ module Funko
|
||||
|
||||
# A comprehensive status for the funko:
|
||||
def docker_status
|
||||
{
|
||||
"name" => name,
|
||||
"containers" => containers,
|
||||
"images" => images,
|
||||
"scale" => scale,
|
||||
}
|
||||
Status.new(
|
||||
name: name,
|
||||
containers: containers,
|
||||
images: images,
|
||||
scale: scale,
|
||||
)
|
||||
end
|
||||
|
||||
# Descriptive status for the funko
|
||||
|
Reference in New Issue
Block a user