Status local/remote

This commit is contained in:
2024-07-03 15:18:45 -03:00
parent e17f421b5e
commit 126cae6c18
5 changed files with 54 additions and 15 deletions

View File

@ -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)

View File

@ -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"]

View File

@ -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