From 64778bba193789da025e59f1e0722c3e92681af6 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 3 Jul 2024 15:33:53 -0300 Subject: [PATCH] Remove old API --- src/daemon/funko.cr | 40 ++-------------------------------- src/funko.cr | 53 --------------------------------------------- 2 files changed, 2 insertions(+), 91 deletions(-) diff --git a/src/daemon/funko.cr b/src/daemon/funko.cr index 515ac38..8192e8a 100644 --- a/src/daemon/funko.cr +++ b/src/daemon/funko.cr @@ -43,34 +43,6 @@ module Funko end end - get "/funkos/:name/pause/" do |env| - funko = Funko.from_names([env.params.url["name"]])[0] - funko.pause - funko.wait_for("paused", 5) - end - - get "/funkos/:name/unpause/" do |env| - funko = Funko.from_names([env.params.url["name"]])[0] - funko.unpause - funko.wait_for("running", 5) - end - - get "/funkos/:name/start/" do |env| - funko = Funko.from_names([env.params.url["name"]])[0] - funko.start - funko.wait_for("running", 5) - end - - get "/funkos/:name/stop/" do |env| - funko = Funko.from_names([env.params.url["name"]])[0] - begin - funko.stop - funko.wait_for("exited", 5) - rescue ex : Docr::Errors::DockerAPIError - halt env, status_code: 500, response: "Failed to stop container" - end - end - # Build image for funko received as "funko.tgz" # TODO: This may take a while, consider using something like # mosquito-cr/mosquito to make it a job queue @@ -107,20 +79,12 @@ module Funko result = [] of Hash(String, String) funkos.each do |funko| - state = "" - case funko - when .running? - state = "running" - when .paused? - state = "paused" - else - state = "stopped" - end + state = "FIXME" result << { "name" => funko.name, "state" => state, - "status" => funko.status, + "status" => "FIXME", } end diff --git a/src/funko.cr b/src/funko.cr index e5e8ee1..16a7bbe 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -195,59 +195,6 @@ module Funko ) end - # Descriptive status for the funko - def status - status = self.containers.map { |container| - container.@status - }.join(", ") - status.empty? ? "Stopped" : status - end - - # Is any instance of this funko running? - def running? - self.containers.any? { |container| - container.@state == "running" - } - end - - # Is any instance of this funko paused? - def paused? - self.containers.any? { |container| - container.@state == "paused" - } - end - - # Pause running container - def pause - docker_api = Docr::API.new(Docr::Client.new) - images = self.image_history - running = self.containers.select { |container| - container.@state == "running" - }.sort! { |i, j| - (images.index(j.@image_id) || 9999) <=> (images.index(i.@image_id) || 9999) - } - docker_api.containers.pause(running[0].@id) unless running.empty? - end - - # Unpause paused container with the newer image - def unpause - docker_api = Docr::API.new(Docr::Client.new) - images = self.image_history - paused = self.containers.select { |container| - container.@state == "paused" - }.sort! { |i, j| - (images.index(j.@image_id) || 9999) <=> (images.index(i.@image_id) || 9999) - } - docker_api.containers.unpause(paused[0].@id) unless paused.empty? - end - - # Is any instance of this funko exited? - def exited? - self.containers.any? { |container| - container.@state == "exited" - } - end - # Start container with given id def start(id : String) docker_api = Docr::API.new(Docr::Client.new)