Status local/remote

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

View File

@ -1,9 +1,9 @@
# This configuration file was generated by `ameba --gen-config` # This configuration file was generated by `ameba --gen-config`
# on 2024-07-03 14:31:04 UTC using Ameba version 1.6.1. # on 2024-07-03 18:18:32 UTC using Ameba version 1.6.1.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the reported problems are removed from the code base. # one by one as the reported problems are removed from the code base.
# Problems found: 5 # Problems found: 6
# Run `ameba --only Documentation/DocumentationAdmonition` for details # Run `ameba --only Documentation/DocumentationAdmonition` for details
Documentation/DocumentationAdmonition: Documentation/DocumentationAdmonition:
Description: Reports documentation admonitions Description: Reports documentation admonitions
@ -12,6 +12,8 @@ Documentation/DocumentationAdmonition:
- src/secrets.cr - src/secrets.cr
- src/daemon/main.cr - src/daemon/main.cr
- src/daemon/secrets.cr - src/daemon/secrets.cr
- src/daemon/funko.cr
- src/funko.cr
- spec/faaso_spec.cr - spec/faaso_spec.cr
Admonitions: Admonitions:
- TODO - TODO

View File

@ -5,21 +5,31 @@ module Faaso
funko = Funko::Funko.from_names([name])[0] funko = Funko::Funko.from_names([name])[0]
status = funko.docker_status status = funko.docker_status
Log.info { "Name: #{status["name"]}" } Log.info { "Name: #{status.@name}" }
Log.info { "Scale: #{status["scale"]}" } Log.info { "Scale: #{status.scale}" }
Log.info { "Containers: #{status["containers"].size}" } Log.info { "Containers: #{status.containers.size}" }
status["containers"].each do |container| status.containers.each do |container|
Log.info { " #{container.@names[0]} #{container.status}" } Log.info { " #{container.@names[0]} #{container.status}" }
end end
Log.info { "Images: #{status["images"].size}" } Log.info { "Images: #{status.images.size}" }
status["images"].each do |image| status.images.each do |image|
Log.info { " #{image.repo_tags} #{image.created}" } Log.info { " #{image.repo_tags} #{Time.unix(image.created)}" }
end end
end end
def remote(options, name) 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 end
def run(options, name) def run(options, name)

View File

@ -5,6 +5,18 @@ require "../funko.cr"
module Funko module Funko
extend self 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 the funko's scale
get "/funkos/:name/scale/" do |env| get "/funkos/:name/scale/" do |env|
name = env.params.url["name"] name = env.params.url["name"]

View File

@ -6,6 +6,20 @@ require "yaml"
module Funko module Funko
extend self 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 class Funko
include YAML::Serializable include YAML::Serializable
@ -168,12 +182,12 @@ module Funko
# A comprehensive status for the funko: # A comprehensive status for the funko:
def docker_status def docker_status
{ Status.new(
"name" => name, name: name,
"containers" => containers, containers: containers,
"images" => images, images: images,
"scale" => scale, scale: scale,
} )
end end
# Descriptive status for the funko # Descriptive status for the funko

View File

@ -23,6 +23,7 @@ ReversePath "/faaso/hello-7273704811390/" "http://hello-7273704811390:3000/"
ReversePath "/faaso/hello-761221081008155/" "http://hello-761221081008155:3000/" ReversePath "/faaso/hello-761221081008155/" "http://hello-761221081008155:3000/"
ReversePath "/faaso/hello-9798100678476/" "http://hello-9798100678476:3000/" ReversePath "/faaso/hello-9798100678476/" "http://hello-9798100678476:3000/"
ReversePath "/faaso/hello-98103104100103100/" "http://hello-98103104100103100:3000/" ReversePath "/faaso/hello-98103104100103100/" "http://hello-98103104100103100:3000/"
ReversePath "/faaso/hello-e24ojr/" "http://hello-e24ojr:3000/"
ReversePath "/faaso/hello-foo/" "http://hello-foo:3000/" ReversePath "/faaso/hello-foo/" "http://hello-foo:3000/"
ReversePath "/faaso/hello-gfvij3/" "http://hello-gfvij3:3000/" ReversePath "/faaso/hello-gfvij3/" "http://hello-gfvij3:3000/"
ReversePath "/faaso/hello-ngisvh/" "http://hello-ngisvh:3000/" ReversePath "/faaso/hello-ngisvh/" "http://hello-ngisvh:3000/"