ogle 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -25
- data/lib/ogle/image.rb +48 -17
- data/lib/ogle/version.rb +1 -1
- data/test/cassettes/image_find.yml +139 -0
- data/test/lib/ogle/{resource_test.rb → image_test.rb} +40 -16
- data/test/test_helper.rb +1 -2
- metadata +6 -4
data/README.md
CHANGED
@@ -16,31 +16,7 @@ Depending on the call you make, glance will sometimes return JSON and others XML
|
|
16
16
|
|
17
17
|
### Examples
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
CONNECTION = Ogle::Client.new(
|
22
|
-
:host => "example.com"
|
23
|
-
)
|
24
|
-
|
25
|
-
# This will give a list of all the images
|
26
|
-
response = CONNECTION.image.all
|
27
|
-
puts response
|
28
|
-
|
29
|
-
# This will give a detailed list of all the images
|
30
|
-
response = CONNECTION.image true
|
31
|
-
puts response
|
32
|
-
|
33
|
-
# This will return a list of only images that are runable (are not aki or ari)
|
34
|
-
response = CONNECTION.image.runable
|
35
|
-
puts response
|
36
|
-
|
37
|
-
# This will return headers for a specific image as a hash
|
38
|
-
response = CONNECTION.image.find 6
|
39
|
-
puts response
|
40
|
-
|
41
|
-
# This will delete a given image
|
42
|
-
response = CONNECTION.image.delete 6
|
43
|
-
puts response.code
|
19
|
+
Please see the examples wiki here: https://github.com/kevinbringard/ogle/wiki/Examples
|
44
20
|
|
45
21
|
## Compatability
|
46
22
|
|
data/lib/ogle/image.rb
CHANGED
@@ -1,4 +1,33 @@
|
|
1
1
|
module Ogle
|
2
|
+
class ImageData
|
3
|
+
##
|
4
|
+
# Return a valid ami id from the given 'glance id'.
|
5
|
+
#
|
6
|
+
# +glance_id+: A String representing an image id in glance.
|
7
|
+
#
|
8
|
+
# Note:
|
9
|
+
# Glance image ids differ from those used by the EC2 API.
|
10
|
+
# Currently there is no way to query EC2 for a glance_id
|
11
|
+
# or vice versa.
|
12
|
+
|
13
|
+
def to_ami_id
|
14
|
+
hex = self.id.to_i.to_s 16
|
15
|
+
padded = hex.to_s.rjust 8,"0"
|
16
|
+
|
17
|
+
"ami-#{padded}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize hash
|
21
|
+
class << self; self end.instance_eval do
|
22
|
+
hash.each_pair.each do |k, v|
|
23
|
+
define_method k do
|
24
|
+
v
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
2
31
|
class Image
|
3
32
|
def initialize connection
|
4
33
|
@connection = connection
|
@@ -15,7 +44,9 @@ module Ogle
|
|
15
44
|
|
16
45
|
response = @connection.get path
|
17
46
|
|
18
|
-
response.body['images']
|
47
|
+
response.body['images'].collect do |r|
|
48
|
+
ImageData.new r
|
49
|
+
end
|
19
50
|
end
|
20
51
|
|
21
52
|
##
|
@@ -26,17 +57,19 @@ module Ogle
|
|
26
57
|
def find image_id
|
27
58
|
response = @connection.head "/images/#{image_id}"
|
28
59
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
60
|
+
ImageData.new(
|
61
|
+
Hash.new.tap do |h|
|
62
|
+
properties = h['properties'] = Hash.new
|
63
|
+
response.each_header do |k, v|
|
64
|
+
case k.downcase.tr '-', '_'
|
65
|
+
when %r{^x_image_meta_property_([a-z_]+)$}
|
66
|
+
properties[$1] = v
|
67
|
+
when %r{^x_image_meta_([a-z_]+)$}
|
68
|
+
h[$1] = v
|
69
|
+
end
|
37
70
|
end
|
38
71
|
end
|
39
|
-
|
72
|
+
)
|
40
73
|
end
|
41
74
|
|
42
75
|
##
|
@@ -51,13 +84,11 @@ module Ogle
|
|
51
84
|
end
|
52
85
|
end
|
53
86
|
|
54
|
-
def create file
|
55
|
-
end
|
56
|
-
|
57
87
|
##
|
58
|
-
# Delete an image
|
88
|
+
# Delete an image.
|
89
|
+
#
|
59
90
|
# +image_id+: A String representing an image_id.
|
60
|
-
|
91
|
+
|
61
92
|
def delete image_id
|
62
93
|
response = @connection.delete "/images/#{image_id}"
|
63
94
|
end
|
@@ -67,8 +98,8 @@ module Ogle
|
|
67
98
|
# Kernels and Ramdisks are not runable, so we want to ignore them.
|
68
99
|
|
69
100
|
def runable? image
|
70
|
-
image
|
71
|
-
image
|
101
|
+
image.container_format == "ami" &&
|
102
|
+
image.disk_format == "ami"
|
72
103
|
end
|
73
104
|
end
|
74
105
|
end
|
data/lib/ogle/version.rb
CHANGED
@@ -0,0 +1,139 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :head
|
5
|
+
uri: http://10.3.170.32:9292/images/6
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
accept:
|
9
|
+
- application/json
|
10
|
+
connection:
|
11
|
+
- keep-alive
|
12
|
+
keep-alive:
|
13
|
+
- 30
|
14
|
+
response: !ruby/struct:VCR::Response
|
15
|
+
status: !ruby/struct:VCR::ResponseStatus
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
content-type:
|
20
|
+
- text/html; charset=UTF-8
|
21
|
+
content-length:
|
22
|
+
- "0"
|
23
|
+
x-image-meta-property-distro:
|
24
|
+
- CentOS
|
25
|
+
x-image-meta-id:
|
26
|
+
- "6"
|
27
|
+
x-image-meta-property-arch:
|
28
|
+
- x86_64
|
29
|
+
x-image-meta-deleted:
|
30
|
+
- "False"
|
31
|
+
x-image-meta-container-format:
|
32
|
+
- ami
|
33
|
+
x-image-meta-location:
|
34
|
+
- file:///var/lib/glance/images/6
|
35
|
+
x-image-meta-deleted-at:
|
36
|
+
- ""
|
37
|
+
x-image-meta-created-at:
|
38
|
+
- 2011-04-11T21:04:51
|
39
|
+
x-image-meta-size:
|
40
|
+
- "816906240"
|
41
|
+
x-image-meta-status:
|
42
|
+
- active
|
43
|
+
x-image-meta-property-type:
|
44
|
+
- machine
|
45
|
+
x-image-meta-property-uploader:
|
46
|
+
- root@cc-01
|
47
|
+
x-image-meta-is-public:
|
48
|
+
- "True"
|
49
|
+
x-image-meta-updated-at:
|
50
|
+
- 2011-04-11T21:04:56
|
51
|
+
x-image-meta-checksum:
|
52
|
+
- 6277381feb8708c393c64499a0ce7e1e
|
53
|
+
x-image-meta-property-version:
|
54
|
+
- "5.5"
|
55
|
+
x-image-meta-disk-format:
|
56
|
+
- ami
|
57
|
+
x-image-meta-name:
|
58
|
+
- CentOS5-5.5-Base_VM-032311-212432
|
59
|
+
location:
|
60
|
+
- http://10.3.170.32:9292/images/6
|
61
|
+
etag:
|
62
|
+
- 6277381feb8708c393c64499a0ce7e1e
|
63
|
+
date:
|
64
|
+
- Thu, 21 Apr 2011 00:17:37 GMT
|
65
|
+
connection:
|
66
|
+
- keep-alive
|
67
|
+
body:
|
68
|
+
http_version: "1.1"
|
69
|
+
- !ruby/struct:VCR::HTTPInteraction
|
70
|
+
request: !ruby/struct:VCR::Request
|
71
|
+
method: :head
|
72
|
+
uri: http://10.3.170.32:9292/images/17
|
73
|
+
body:
|
74
|
+
headers:
|
75
|
+
accept:
|
76
|
+
- application/json
|
77
|
+
connection:
|
78
|
+
- keep-alive
|
79
|
+
keep-alive:
|
80
|
+
- 30
|
81
|
+
response: !ruby/struct:VCR::Response
|
82
|
+
status: !ruby/struct:VCR::ResponseStatus
|
83
|
+
code: 200
|
84
|
+
message: OK
|
85
|
+
headers:
|
86
|
+
content-type:
|
87
|
+
- text/html; charset=UTF-8
|
88
|
+
content-length:
|
89
|
+
- "0"
|
90
|
+
x-image-meta-property-distro:
|
91
|
+
- Ubuntu
|
92
|
+
x-image-meta-id:
|
93
|
+
- "17"
|
94
|
+
x-image-meta-property-arch:
|
95
|
+
- amd64
|
96
|
+
x-image-meta-deleted:
|
97
|
+
- "False"
|
98
|
+
x-image-meta-container-format:
|
99
|
+
- ami
|
100
|
+
x-image-meta-property-uploader:
|
101
|
+
- root@e21ab3
|
102
|
+
x-image-meta-location:
|
103
|
+
- file:///var/lib/glance/images/17
|
104
|
+
x-image-meta-deleted-at:
|
105
|
+
- ""
|
106
|
+
x-image-meta-created-at:
|
107
|
+
- 2011-04-18T17:08:02
|
108
|
+
x-image-meta-size:
|
109
|
+
- "2610561024"
|
110
|
+
x-image-meta-status:
|
111
|
+
- active
|
112
|
+
x-image-meta-property-type:
|
113
|
+
- machine
|
114
|
+
x-image-meta-property-kernel-name:
|
115
|
+
- maverick-server-uec-amd64-vmlinuz-virtual
|
116
|
+
x-image-meta-is-public:
|
117
|
+
- "True"
|
118
|
+
x-image-meta-property-kernel-id:
|
119
|
+
- "1"
|
120
|
+
x-image-meta-updated-at:
|
121
|
+
- 2011-04-18T17:08:32
|
122
|
+
x-image-meta-checksum:
|
123
|
+
- c283810a95e1c8028cb22ca39f0fc40d
|
124
|
+
x-image-meta-property-version:
|
125
|
+
- "10.10"
|
126
|
+
x-image-meta-disk-format:
|
127
|
+
- ami
|
128
|
+
x-image-meta-name:
|
129
|
+
- maverick-server-uec-amd64-CloudFoundry
|
130
|
+
location:
|
131
|
+
- http://10.3.170.32:9292/images/17
|
132
|
+
etag:
|
133
|
+
- c283810a95e1c8028cb22ca39f0fc40d
|
134
|
+
date:
|
135
|
+
- Thu, 21 Apr 2011 00:17:37 GMT
|
136
|
+
connection:
|
137
|
+
- keep-alive
|
138
|
+
body:
|
139
|
+
http_version: "1.1"
|
@@ -4,11 +4,6 @@ CONNECTION = Ogle::Client.new(
|
|
4
4
|
:host => "10.3.170.32"
|
5
5
|
)
|
6
6
|
|
7
|
-
def must_have_valid_keys response, keys
|
8
|
-
raise "The response passed in is empty." if response.keys.empty?
|
9
|
-
response.keys.delete_if { |k| keys.include? k }.must_be_empty
|
10
|
-
end
|
11
|
-
|
12
7
|
describe Ogle::Image do
|
13
8
|
describe "#all" do
|
14
9
|
before do
|
@@ -17,12 +12,12 @@ describe Ogle::Image do
|
|
17
12
|
end
|
18
13
|
end
|
19
14
|
|
20
|
-
it "returns
|
15
|
+
it "returns all images" do
|
21
16
|
@response.size.must_be :>=, 1
|
22
17
|
end
|
23
18
|
|
24
19
|
it "returns metadata" do
|
25
|
-
|
20
|
+
must_have_valid_methods @response.first, METADATA_KEYS
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
@@ -33,12 +28,12 @@ describe Ogle::Image do
|
|
33
28
|
end
|
34
29
|
end
|
35
30
|
|
36
|
-
it "returns
|
31
|
+
it "returns detailed images" do
|
37
32
|
@response.size.must_be :>=, 1
|
38
33
|
end
|
39
34
|
|
40
35
|
it "returns metadata" do
|
41
|
-
|
36
|
+
must_have_valid_methods @response.first, DETAILED_METADATA_KEYS
|
42
37
|
end
|
43
38
|
end
|
44
39
|
|
@@ -49,12 +44,12 @@ describe Ogle::Image do
|
|
49
44
|
end
|
50
45
|
end
|
51
46
|
|
52
|
-
it "returns
|
53
|
-
@response.any? { |i| i
|
47
|
+
it "returns all images which are runable" do
|
48
|
+
@response.any? { |i| i.id != 1}.must_equal true
|
54
49
|
end
|
55
50
|
|
56
51
|
it "returns metadata" do
|
57
|
-
|
52
|
+
must_have_valid_methods @response.first, METADATA_KEYS
|
58
53
|
end
|
59
54
|
end
|
60
55
|
|
@@ -63,7 +58,7 @@ describe Ogle::Image do
|
|
63
58
|
response = CONNECTION.image.runable(true)
|
64
59
|
|
65
60
|
it "returns metadata" do
|
66
|
-
|
61
|
+
must_have_valid_methods response.first, DETAILED_METADATA_KEYS
|
67
62
|
end
|
68
63
|
end
|
69
64
|
end
|
@@ -76,11 +71,11 @@ describe Ogle::Image do
|
|
76
71
|
end
|
77
72
|
|
78
73
|
it "returns X-Image-Meta-* headers as a hash" do
|
79
|
-
|
74
|
+
must_have_valid_methods @response, DETAILED_METADATA_KEYS
|
80
75
|
end
|
81
76
|
|
82
77
|
it "returns a nested properties hash" do
|
83
|
-
must_have_valid_keys @response
|
78
|
+
must_have_valid_keys @response.properties, %w(
|
84
79
|
distro
|
85
80
|
arch
|
86
81
|
uploader
|
@@ -95,10 +90,39 @@ describe Ogle::Image do
|
|
95
90
|
describe "#delete" do
|
96
91
|
VCR.use_cassette "image_delete" do
|
97
92
|
response = CONNECTION.image.delete 15
|
98
|
-
|
93
|
+
|
99
94
|
it "returns an HTTP/1.1 200 OK" do
|
100
95
|
response.code.must_equal "200"
|
101
96
|
end
|
102
97
|
end
|
103
98
|
end
|
99
|
+
|
100
|
+
def must_have_valid_keys response, keys
|
101
|
+
raise "The response passed in is empty." if response.keys.empty?
|
102
|
+
response.keys.delete_if { |k| keys.include? k }.must_be_empty
|
103
|
+
end
|
104
|
+
|
105
|
+
def must_have_valid_methods response, keys
|
106
|
+
keys.each { |k| response.respond_to? k }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe Ogle::ImageData do
|
111
|
+
describe "#to_ami_id" do
|
112
|
+
it "return a valid ami id" do
|
113
|
+
VCR.use_cassette "image_find" do
|
114
|
+
@response = CONNECTION.image.find 6
|
115
|
+
|
116
|
+
@response.to_ami_id.must_equal "ami-00000006"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "return a valid hex ami id" do
|
121
|
+
VCR.use_cassette "image_find" do
|
122
|
+
@response = CONNECTION.image.find 17
|
123
|
+
|
124
|
+
@response.to_ami_id.must_equal "ami-00000011"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
104
128
|
end
|
data/test/test_helper.rb
CHANGED
@@ -28,13 +28,12 @@ class MiniTest::Unit::TestCase
|
|
28
28
|
properties
|
29
29
|
size
|
30
30
|
)
|
31
|
-
|
32
31
|
end
|
33
32
|
|
34
33
|
VCR.config do |c|
|
35
34
|
c.stub_with :webmock
|
36
35
|
c.cassette_library_dir = "test/cassettes"
|
37
|
-
c.default_cassette_options = { :record => :
|
36
|
+
c.default_cassette_options = { :record => :none }
|
38
37
|
end
|
39
38
|
|
40
39
|
MiniTest::Unit.autorun
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ogle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kevin Bringard
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-21 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -89,12 +89,13 @@ files:
|
|
89
89
|
- lib/ogle/version.rb
|
90
90
|
- ogle.gemspec
|
91
91
|
- test/cassettes/image_delete.yml
|
92
|
+
- test/cassettes/image_find.yml
|
92
93
|
- test/cassettes/images_all.yml
|
93
94
|
- test/cassettes/images_all_with_details.yml
|
94
95
|
- test/cassettes/images_find.yml
|
95
96
|
- test/cassettes/images_runable.yml
|
96
97
|
- test/cassettes/images_runable_with_details.yml
|
97
|
-
- test/lib/ogle/
|
98
|
+
- test/lib/ogle/image_test.rb
|
98
99
|
- test/test_helper.rb
|
99
100
|
has_rdoc: true
|
100
101
|
homepage: ""
|
@@ -126,10 +127,11 @@ specification_version: 3
|
|
126
127
|
summary: Ruby interface for OpenStack Glance
|
127
128
|
test_files:
|
128
129
|
- test/cassettes/image_delete.yml
|
130
|
+
- test/cassettes/image_find.yml
|
129
131
|
- test/cassettes/images_all.yml
|
130
132
|
- test/cassettes/images_all_with_details.yml
|
131
133
|
- test/cassettes/images_find.yml
|
132
134
|
- test/cassettes/images_runable.yml
|
133
135
|
- test/cassettes/images_runable_with_details.yml
|
134
|
-
- test/lib/ogle/
|
136
|
+
- test/lib/ogle/image_test.rb
|
135
137
|
- test/test_helper.rb
|