docker-api 1.7.4 → 1.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -250,6 +250,10 @@ container.run('pwd', 10)
250
250
  container.delete
251
251
  # => nil
252
252
 
253
+ # Request a Container by ID or name.
254
+ Docker::Container.get('500f53b25e6e')
255
+ # => Docker::Container { :id => , :connection => Docker::Connection { :url => http://localhost, :options => {:port=>4243} } }
256
+
253
257
  # Request all of the Containers. By default, will only return the running Containers.
254
258
  Docker::Container.all(:all => true)
255
259
  # => [Docker::Container { :id => , :connection => Docker::Connection { :url => http://localhost, :options => {:port=>4243} } }]
data/lib/docker.rb CHANGED
@@ -5,6 +5,7 @@ require 'tempfile'
5
5
  require 'base64'
6
6
  require 'rubygems/package'
7
7
  require 'archive/tar/minitar'
8
+ require 'uri'
8
9
 
9
10
  # The top-level module for this gem. It's purpose is to hold global
10
11
  # configuration variables that are used as defaults in other classes.
@@ -38,6 +38,8 @@ class Docker::Connection
38
38
  raise ClientError, ex.message
39
39
  rescue Excon::Errors::Unauthorized => ex
40
40
  raise UnauthorizedError, ex.message
41
+ rescue Excon::Errors::NotFound => ex
42
+ raise NotFoundError, ex.message
41
43
  rescue Excon::Errors::InternalServerError => ex
42
44
  raise ServerError, ex.message
43
45
  rescue Excon::Errors::Timeout => ex
@@ -133,6 +133,13 @@ class Docker::Container
133
133
  end
134
134
  end
135
135
 
136
+ # Return the container with specified ID
137
+ def self.get(id, opts = {}, conn = Docker.connection)
138
+ container_json = conn.get("/containers/#{URI.encode(id)}/json", opts)
139
+ hash = Docker::Util.parse_json(container_json) || {}
140
+ new(conn, hash['ID'])
141
+ end
142
+
136
143
  # Return all of the Containers.
137
144
  def self.all(opts = {}, conn = Docker.connection)
138
145
  hashes = Docker::Util.parse_json(conn.get('/containers/json', opts)) || []
data/lib/docker/error.rb CHANGED
@@ -14,6 +14,9 @@ module Docker::Error
14
14
  # Raised when a request returns a 401.
15
15
  class UnauthorizedError < DockerError; end
16
16
 
17
+ # Raised when a request returns a 404.
18
+ class NotFoundError < DockerError; end
19
+
17
20
  # Raised when a request returns a 500.
18
21
  class ServerError < DockerError; end
19
22
 
data/lib/docker/image.rb CHANGED
@@ -122,6 +122,13 @@ class Docker::Image
122
122
  end
123
123
  end
124
124
 
125
+ # Return a specific image.
126
+ def get(id, opts = {}, conn = Docker.connection)
127
+ image_json = conn.get("/images/#{URI.encode(id)}/json", opts)
128
+ hash = Docker::Util.parse_json(image_json) || {}
129
+ new(conn, hash['id'])
130
+ end
131
+
125
132
  # Return every Image.
126
133
  def all(opts = {}, conn = Docker.connection)
127
134
  hashes = Docker::Util.parse_json(conn.get('/images/json', opts)) || []
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  # The version of the docker-api gem.
3
- VERSION = '1.7.4'
3
+ VERSION = '1.7.5'
4
4
 
5
5
  # The version of the compatible Docker remote API.
6
6
  API_VERSION = '1.6'
@@ -371,6 +371,35 @@ describe Docker::Container do
371
371
  end
372
372
  end
373
373
 
374
+ describe '.get' do
375
+ subject { described_class }
376
+
377
+ context 'when the HTTP response is not a 200' do
378
+ before do
379
+ Docker.options = { :mock => true }
380
+ Excon.stub({ :method => :get }, { :status => 500 })
381
+ end
382
+ after do
383
+ Excon.stubs.shift
384
+ Docker.options = {}
385
+ end
386
+
387
+ it 'raises an error' do
388
+ expect { subject.get('randomID') }
389
+ .to raise_error(Docker::Error::ServerError)
390
+ end
391
+ end
392
+
393
+ context 'when the HTTP response is a 200' do
394
+ let(:container) { subject.create('Cmd' => ['ls'], 'Image' => 'base') }
395
+
396
+ it 'materializes the Container into a Docker::Container', :vcr do
397
+ subject.get(container.id).should be_a(Docker::Container)
398
+ end
399
+ end
400
+
401
+ end
402
+
374
403
  describe '.all' do
375
404
  subject { described_class }
376
405
 
@@ -213,6 +213,37 @@ describe Docker::Image do
213
213
  end
214
214
  end
215
215
 
216
+ describe '.get' do
217
+ subject { described_class }
218
+ let(:image) { subject.get(image_name) }
219
+
220
+ context 'when the image does exist' do
221
+ let(:image_name) { 'base' }
222
+
223
+ it 'returns the new image', :vcr do
224
+ expect(image).to be_a Docker::Image
225
+ end
226
+ end
227
+
228
+ context 'when the image does not exist' do
229
+ let(:image_name) { 'abcdefghijkl' }
230
+
231
+ before do
232
+ Docker.options = { :mock => true }
233
+ Excon.stub({ :method => :get }, { :status => 404 })
234
+ end
235
+
236
+ after do
237
+ Docker.options = {}
238
+ Excon.stubs.shift
239
+ end
240
+
241
+ it 'raises a not found error', :vcr do
242
+ expect { image }.to raise_error(Docker::Error::NotFoundError)
243
+ end
244
+ end
245
+ end
246
+
216
247
  describe '.import' do
217
248
  subject { described_class }
218
249
 
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: unix:///var/run/docker.sock/v1.6/containers/create
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"Cmd":["ls"],"Image":"base"}'
9
+ headers:
10
+ User-Agent:
11
+ - Swipely/Docker-API 1.6.0
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 201
17
+ message:
18
+ headers:
19
+ !binary "Q29udGVudC1UeXBl":
20
+ - !binary |-
21
+ YXBwbGljYXRpb24vanNvbg==
22
+ !binary "Q29udGVudC1MZW5ndGg=":
23
+ - !binary |-
24
+ MjE=
25
+ !binary "RGF0ZQ==":
26
+ - !binary |-
27
+ TW9uLCAyOCBPY3QgMjAxMyAxNDozNTozNiBHTVQ=
28
+ body:
29
+ encoding: US-ASCII
30
+ string: ! '{"Id":"86e7cfd11b94"}'
31
+ http_version:
32
+ recorded_at: Mon, 28 Oct 2013 14:35:36 GMT
33
+ - request:
34
+ method: get
35
+ uri: unix:///var/run/docker.sock/v1.6/containers/86e7cfd11b94/json
36
+ body:
37
+ encoding: US-ASCII
38
+ string: ''
39
+ headers:
40
+ User-Agent:
41
+ - Swipely/Docker-API 1.6.0
42
+ Content-Type:
43
+ - text/plain
44
+ response:
45
+ status:
46
+ code: 200
47
+ message:
48
+ headers:
49
+ !binary "Q29udGVudC1UeXBl":
50
+ - !binary |-
51
+ YXBwbGljYXRpb24vanNvbg==
52
+ !binary "Q29udGVudC1MZW5ndGg=":
53
+ - !binary |-
54
+ MTkx
55
+ !binary "RGF0ZQ==":
56
+ - !binary |-
57
+ TW9uLCAyOCBPY3QgMjAxMyAxNDozNTozNiBHTVQ=
58
+ body:
59
+ encoding: US-ASCII
60
+ string: ! '{"Id":"86e7cfd11b94c982d011dc6b9f5414dae7f92065f8ad444ec5254fc92ed6ffd3","Image":"base:latest","Command":"ls
61
+ ","Created":1382970936,"Status":"Exit 0","Ports":null,"SizeRw":0,"SizeRootFs":0}'
62
+ http_version:
63
+ recorded_at: Mon, 28 Oct 2013 14:35:36 GMT
@@ -0,0 +1,33 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: unix:///var/run/docker.sock/v1.6/images/base/json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Swipely/Docker-API 1.7.4
12
+ Content-Type:
13
+ - text/plain
14
+ response:
15
+ status:
16
+ code: 200
17
+ message:
18
+ headers:
19
+ !binary "Q29udGVudC1UeXBl":
20
+ - !binary |-
21
+ YXBwbGljYXRpb24vanNvbg==
22
+ !binary "RGF0ZQ==":
23
+ - !binary |-
24
+ VGh1LCAxMiBEZWMgMjAxMyAxNjo0NDowMiBHTVQ=
25
+ !binary "Q29udGVudC1MZW5ndGg=":
26
+ - !binary |-
27
+ NjMx
28
+ body:
29
+ encoding: US-ASCII
30
+ string: ! '{"id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc","parent":"27cf784147099545","created":"2013-03-23T22:24:18.818426-07:00","container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0","container_config":{"Hostname":"","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":null,"Tty":true,"OpenStdin":true,"StdinOnce":false,"Env":null,"Cmd":["/bin/bash"],"Dns":null,"Image":"base","Volumes":null,"VolumesFrom":"","WorkingDir":"","Entrypoint":null,"NetworkDisabled":false},"Size":24653}'
31
+ http_version:
32
+ recorded_at: Thu, 12 Dec 2013 16:44:02 GMT
33
+ recorded_with: VCR 2.7.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.7.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-07 00:00:00.000000000 Z
12
+ date: 2013-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
@@ -209,6 +209,7 @@ files:
209
209
  - spec/vcr/Docker_Container/_create/when_the_Container_does_not_yet_exist/when_the_HTTP_request_returns_a_200/sets_the_id.yml
210
210
  - spec/vcr/Docker_Container/_delete/deletes_the_container.yml
211
211
  - spec/vcr/Docker_Container/_export/yields_each_chunk.yml
212
+ - spec/vcr/Docker_Container/_get/when_the_HTTP_response_is_a_200/materializes_the_Container_into_a_Docker_Container.yml
212
213
  - spec/vcr/Docker_Container/_json/returns_the_description_as_a_Hash.yml
213
214
  - spec/vcr/Docker_Container/_kill/kills_the_container.yml
214
215
  - spec/vcr/Docker_Container/_restart/restarts_the_container.yml
@@ -227,6 +228,7 @@ files:
227
228
  - spec/vcr/Docker_Image/_build_from_dir/with_a_valid_Dockerfile/with_no_query_parameters/builds_the_image.yml
228
229
  - spec/vcr/Docker_Image/_build_from_dir/with_a_valid_Dockerfile/with_specifying_a_repo_in_the_query_parameters/builds_the_image_and_tags_it.yml
229
230
  - spec/vcr/Docker_Image/_create/when_the_Image_does_not_yet_exist_and_the_body_is_a_Hash/sets_the_id.yml
231
+ - spec/vcr/Docker_Image/_get/when_the_image_does_exist/returns_the_new_image.yml
230
232
  - spec/vcr/Docker_Image/_history/returns_the_history_of_the_Image.yml
231
233
  - spec/vcr/Docker_Image/_insert/inserts_the_url_s_file_into_a_new_Image.yml
232
234
  - spec/vcr/Docker_Image/_insert_local/when_removing_intermediate_containers/creates_a_new_image.yml
@@ -297,6 +299,7 @@ test_files:
297
299
  - spec/vcr/Docker_Container/_create/when_the_Container_does_not_yet_exist/when_the_HTTP_request_returns_a_200/sets_the_id.yml
298
300
  - spec/vcr/Docker_Container/_delete/deletes_the_container.yml
299
301
  - spec/vcr/Docker_Container/_export/yields_each_chunk.yml
302
+ - spec/vcr/Docker_Container/_get/when_the_HTTP_response_is_a_200/materializes_the_Container_into_a_Docker_Container.yml
300
303
  - spec/vcr/Docker_Container/_json/returns_the_description_as_a_Hash.yml
301
304
  - spec/vcr/Docker_Container/_kill/kills_the_container.yml
302
305
  - spec/vcr/Docker_Container/_restart/restarts_the_container.yml
@@ -315,6 +318,7 @@ test_files:
315
318
  - spec/vcr/Docker_Image/_build_from_dir/with_a_valid_Dockerfile/with_no_query_parameters/builds_the_image.yml
316
319
  - spec/vcr/Docker_Image/_build_from_dir/with_a_valid_Dockerfile/with_specifying_a_repo_in_the_query_parameters/builds_the_image_and_tags_it.yml
317
320
  - spec/vcr/Docker_Image/_create/when_the_Image_does_not_yet_exist_and_the_body_is_a_Hash/sets_the_id.yml
321
+ - spec/vcr/Docker_Image/_get/when_the_image_does_exist/returns_the_new_image.yml
318
322
  - spec/vcr/Docker_Image/_history/returns_the_history_of_the_Image.yml
319
323
  - spec/vcr/Docker_Image/_insert/inserts_the_url_s_file_into_a_new_Image.yml
320
324
  - spec/vcr/Docker_Image/_insert_local/when_removing_intermediate_containers/creates_a_new_image.yml
@@ -331,3 +335,4 @@ test_files:
331
335
  - spec/vcr/Docker_Image/_run/when_the_argument_is_nil/no_command_configured_in_image/should_raise_an_error_if_no_command_is_specified.yml
332
336
  - spec/vcr/Docker_Image/_search/materializes_each_Image_into_a_Docker_Image.yml
333
337
  - spec/vcr/Docker_Image/_tag/tags_the_image_with_the_repo_name.yml
338
+ has_rdoc: