Remove old API

This commit is contained in:
Roberto Alsina 2024-07-03 15:33:53 -03:00
parent e618f7c9e6
commit 64778bba19
2 changed files with 2 additions and 91 deletions

View File

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

View File

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