Skip to content

Commit

Permalink
made docker via api class more dynamic, by allowing api version to be…
Browse files Browse the repository at this point in the history
… past to it
  • Loading branch information
laferrieren committed Nov 1, 2015
1 parent 09751f3 commit b013b61
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Your name could be here!
* [Suren Karapetyan][skarap]
* [Jon Wood][jellybob]
* [Mark Borcherding][markborcherding]
* [Nick Laferriere][laferrieren]

Pre-release
-----------
Expand Down
2 changes: 1 addition & 1 deletion lib/centurion/docker_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def old_containers_for_name(wanted_name)

def docker_via_api
@docker_via_api ||= Centurion::DockerViaApi.new(@hostname, @port,
@tls_params)
@tls_params, nil)
end

def docker_via_cli
Expand Down
21 changes: 11 additions & 10 deletions lib/centurion/docker_via_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
module Centurion; end

class Centurion::DockerViaApi
def initialize(hostname, port, tls_args = {})
def initialize(hostname, port, tls_args = {}, api_version = nil)
@tls_args = default_tls_args(tls_args[:tls]).merge(tls_args.reject { |k, v| v.nil? }) # Required by tls_enable?
@base_uri = "http#{'s' if tls_enable?}://#{hostname}:#{port}"

api_version ||= "/v1.12"
@docker_api_version = api_version
configure_excon_globally
end

def ps(options={})
path = "/v1.12" + "/containers/json"
path = @docker_api_version + "/containers/json"
path += "?all=1" if options[:all]
response = Excon.get(@base_uri + path, tls_excon_arguments)

Expand All @@ -24,7 +25,7 @@ def ps(options={})

def inspect_image(image, tag = "latest")
repository = "#{image}:#{tag}"
path = "/v1.12" + "/images/#{repository}/json"
path = @docker_api_version + "/images/#{repository}/json"

response = Excon.get(
@base_uri + path,
Expand All @@ -35,7 +36,7 @@ def inspect_image(image, tag = "latest")
end

def remove_container(container_id)
path = "/v1.12" + "/containers/#{container_id}"
path = @docker_api_version + "/containers/#{container_id}"
response = Excon.delete(
@base_uri + path,
tls_excon_arguments
Expand All @@ -45,7 +46,7 @@ def remove_container(container_id)
end

def stop_container(container_id, timeout = 30)
path = "/v1.12" + "/containers/#{container_id}/stop?t=#{timeout}"
path = @docker_api_version + "/containers/#{container_id}/stop?t=#{timeout}"
response = Excon.post(
@base_uri + path,
tls_excon_arguments
Expand All @@ -55,7 +56,7 @@ def stop_container(container_id, timeout = 30)
end

def create_container(configuration, name = nil)
path = "/v1.12" + "/containers/create"
path = @docker_api_version + "/containers/create"
response = Excon.post(
@base_uri + path,
tls_excon_arguments.merge(
Expand All @@ -69,7 +70,7 @@ def create_container(configuration, name = nil)
end

def start_container(container_id, configuration)
path = "/v1.12" + "/containers/#{container_id}/start"
path = @docker_api_version + "/containers/#{container_id}/start"
response = Excon.post(
@base_uri + path,
tls_excon_arguments.merge(
Expand All @@ -88,7 +89,7 @@ def start_container(container_id, configuration)
end

def restart_container(container_id, timeout = 30)
path = "/v1.12" + "/containers/#{container_id}/restart?t=#{timeout}"
path = @docker_api_version + "/containers/#{container_id}/restart?t=#{timeout}"
response = Excon.post(
@base_uri + path,
tls_excon_arguments
Expand All @@ -106,7 +107,7 @@ def restart_container(container_id, timeout = 30)
end

def inspect_container(container_id)
path = "/v1.12" + "/containers/#{container_id}/json"
path = @docker_api_version + "/containers/#{container_id}/json"
response = Excon.get(
@base_uri + path,
tls_excon_arguments
Expand Down
2 changes: 1 addition & 1 deletion lib/centurion/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Centurion
VERSION = '1.8.2'
VERSION = '1.8.3'
end
1 change: 1 addition & 0 deletions spec/docker_via_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
describe Centurion::DockerViaApi do
let(:hostname) { 'example.com' }
let(:port) { '2375' }
let(:api_version) { '1.12' }
let(:json_string) { '[{ "Hello": "World" }]' }
let(:json_value) { JSON.load(json_string) }

Expand Down

0 comments on commit b013b61

Please sign in to comment.