ogle 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2-p136@ogle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ogle.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Ogle
2
+
3
+ > Go ahead and ogle, it's so much more than a glance.
4
+
5
+ Lean Ruby bindings to OpenStack's [Glance](http://glance.openstack.org/). Exposes the Glance API endpoints in an easy to access manner.
6
+
7
+ # Why
8
+
9
+ Depending on the call you make, glance will sometimes return JSON and others XML. This will normalize the returned data for easy use. Plus, I was bored.
10
+
11
+ ## Usage
12
+
13
+ ### Bundler
14
+
15
+ gem "ogle"
16
+
17
+ ### Examples
18
+
19
+ require "ogle"
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.resource.all
27
+ puts response
28
+ puts response.body
29
+ puts response.code
30
+
31
+ # This will give a detailed list of all the images
32
+ response = CONNECTION.resource true
33
+ puts response
34
+ puts response.body
35
+ puts response.code
36
+
37
+ # This will return the x-image-meta-* headers for a specific image as a hash
38
+ response = CONNECTION.resource 6
39
+ puts response.inspect
40
+
41
+ ## Compatability
42
+
43
+ ruby 1.9.2
44
+
45
+ ## Testing
46
+
47
+ $ bundle exec rake
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/testtask"
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << "./lib" << "./test"
7
+ test.pattern = "test/**/*_test.rb"
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ %w(hugs ogle/resource).each { |r| require r }
2
+
3
+ module Ogle
4
+ class Client
5
+ ##
6
+ # Required:
7
+ # +host+: A string containing the hostname or IP of your glance server
8
+
9
+ def initialize options
10
+ @connection = Hugs::Client.new(
11
+ :host => options[:host],
12
+ :scheme => options[:scheme] || "http",
13
+ :port => options[:port] || 9292,
14
+ )
15
+ @connection.raise_4xx = true
16
+ @connection.raise_5xx = true
17
+ end
18
+
19
+ def resource
20
+ @resource ||= Resource.new @connection
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,50 @@
1
+ module Ogle
2
+ class Resource
3
+ def initialize connection
4
+ @connection = connection
5
+ end
6
+
7
+ ##
8
+ # Returns information about images.
9
+ #
10
+ # +verbose+: A Boolean toggling the returning of
11
+ # additional image information.
12
+
13
+ def all verbose = false
14
+ path = verbose ? "/images/detail" : "/images"
15
+
16
+ response = @connection.get path
17
+
18
+ response.body['images']
19
+ end
20
+
21
+ ##
22
+ # Returns information about the given 'image_id'.
23
+ #
24
+ # +image_id+: A String representing an image_id.
25
+
26
+ def find image_id
27
+ headers = @connection.head "/images/#{image_id}"
28
+
29
+ meta ={}
30
+
31
+ headers.each_header do |k, v|
32
+ if k.match('x-image-meta-')
33
+ meta["#{k}"] = v
34
+ end
35
+ end
36
+
37
+ meta
38
+ end
39
+
40
+ ##
41
+ # Stores the disk provided disk image in glance
42
+ # Stores provided meta-data about the image in glance
43
+ #
44
+ # +image_location+: A string representing the location of the image to updload
45
+
46
+ def add image_location
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Ogle
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ogle.rb ADDED
@@ -0,0 +1 @@
1
+ require "ogle/client"
data/ogle.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ogle/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ogle"
7
+ s.version = Ogle::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kevin Bringard"]
10
+ s.email = ["kbringard@attinteractive.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Ruby interface for OpenStack Glance}
13
+ s.description = %q{Exposes the API for OpenStack Glance. Go ahead and ogle, it's so much more than a glance.}
14
+
15
+ s.rubyforge_project = "ogle"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "hugs", "~> 2.5.2"
23
+
24
+ s.add_development_dependency "rake"
25
+ s.add_development_dependency "vcr", "1.5.0"
26
+ s.add_development_dependency "webmock"
27
+ s.add_development_dependency "minitest"
28
+ end
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.33:9292/images
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
+ - "1067"
23
+ date:
24
+ - Fri, 08 Apr 2011 17:56:53 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: "{\"images\": [{\"name\": \"ttylinux-uec-amd64-12.1_2.6.35-22_1-initrd\", \"container_format\": \"ari\", \"disk_format\": \"ari\", \"checksum\": \"2d222d406f3ed30e03ed44123c33cba6\", \"id\": 1, \"size\": 5882349}, {\"name\": \"ttylinux-uec-amd64-12.1_2.6.35-22_1-vmlinuz\", \"container_format\": \"aki\", \"disk_format\": \"aki\", \"checksum\": \"3ed2965d3f8d877a3ee3e061fd648e9a\", \"id\": 2, \"size\": 4404752}, {\"name\": \"ttylinux-uec-amd64-12.1_2.6.35-22_1.img\", \"container_format\": \"ami\", \"disk_format\": \"ami\", \"checksum\": \"10047a119149e08fb206eea89832eee0\", \"id\": 3, \"size\": 25165824}, {\"name\": \"CentOS5-5.5-Base_VM-032311-212432\", \"container_format\": \"ami\", \"disk_format\": \"ami\", \"checksum\": \"6277381feb8708c393c64499a0ce7e1e\", \"id\": 4, \"size\": 816906240}, {\"name\": \"maverick-server-uec-amd64-vmlinuz-virtual\", \"container_format\": \"aki\", \"disk_format\": \"aki\", \"checksum\": \"73152adae523a52d481f5150deb30356\", \"id\": 5, \"size\": 4408912}, {\"name\": \"maverick-server-uec-amd64.img\", \"container_format\": \"ami\", \"disk_format\": \"ami\", \"checksum\": \"d511da81009517c53f36ff4e8602ff62\", \"id\": 6, \"size\": 1476395008}]}"
28
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.33:9292/images/detail
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
+ - "3294"
23
+ date:
24
+ - Fri, 08 Apr 2011 17:56:53 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: "{\"images\": [{\"status\": \"active\", \"name\": \"ttylinux-uec-amd64-12.1_2.6.35-22_1-initrd\", \"deleted\": false, \"container_format\": \"ari\", \"created_at\": \"2011-04-06T20:03:11.914270\", \"disk_format\": \"ari\", \"updated_at\": \"2011-04-06T20:03:12.206204\", \"id\": 1, \"location\": \"file:///var/lib/glance/images/1\", \"checksum\": \"2d222d406f3ed30e03ed44123c33cba6\", \"is_public\": true, \"deleted_at\": null, \"properties\": {\"arch\": \"amd64\", \"type\": \"ramdisk\", \"uploader\": \"root@e3ab3\", \"distro\": \"ttylinux\"}, \"size\": 5882349}, {\"status\": \"active\", \"name\": \"ttylinux-uec-amd64-12.1_2.6.35-22_1-vmlinuz\", \"deleted\": false, \"container_format\": \"aki\", \"created_at\": \"2011-04-06T20:03:12.585510\", \"disk_format\": \"aki\", \"updated_at\": \"2011-04-06T20:03:12.846637\", \"id\": 2, \"location\": \"file:///var/lib/glance/images/2\", \"checksum\": \"3ed2965d3f8d877a3ee3e061fd648e9a\", \"is_public\": true, \"deleted_at\": null, \"properties\": {\"arch\": \"amd64\", \"version\": \"2.5.35-22_1\", \"type\": \"kernel\", \"uploader\": \"root@e3ab3\", \"distro\": \"ttylinux\"}, \"size\": 4404752}, {\"status\": \"active\", \"name\": \"ttylinux-uec-amd64-12.1_2.6.35-22_1.img\", \"deleted\": false, \"container_format\": \"ami\", \"created_at\": \"2011-04-06T20:03:13.227286\", \"disk_format\": \"ami\", \"updated_at\": \"2011-04-06T20:03:13.602220\", \"id\": 3, \"location\": \"file:///var/lib/glance/images/3\", \"checksum\": \"10047a119149e08fb206eea89832eee0\", \"is_public\": true, \"deleted_at\": null, \"properties\": {\"kernel_id\": \"2\", \"arch\": \"amd64\", \"ramdisk_id\": \"1\", \"version\": \"1.0\", \"kernel_name\": \"ttylinux-uec-amd64-12.1_2.6.35-22_1-vmlinuz\", \"ramdisk_name\": \"ttylinux-uec-amd64-12.1_2.6.35-22_1-initrd\", \"uploader\": \"root@e3ab3\", \"type\": \"machine\", \"distro\": \"ttylinux\"}, \"size\": 25165824}, {\"status\": \"active\", \"name\": \"CentOS5-5.5-Base_VM-032311-212432\", \"deleted\": false, \"container_format\": \"ami\", \"created_at\": \"2011-04-06T20:03:59.759260\", \"disk_format\": \"ami\", \"updated_at\": \"2011-04-06T20:04:04.498592\", \"id\": 4, \"location\": \"file:///var/lib/glance/images/4\", \"checksum\": \"6277381feb8708c393c64499a0ce7e1e\", \"is_public\": true, \"deleted_at\": null, \"properties\": {\"arch\": \"x86_64\", \"builder\": \"kevin\", \"version\": \"5.5\", \"uploader\": \"root@e3ab3\", \"type\": \"machine\", \"distro\": \"CentOS\"}, \"size\": 816906240}, {\"status\": \"active\", \"name\": \"maverick-server-uec-amd64-vmlinuz-virtual\", \"deleted\": false, \"container_format\": \"aki\", \"created_at\": \"2011-04-06T20:04:47.984648\", \"disk_format\": \"aki\", \"updated_at\": \"2011-04-06T20:04:48.281538\", \"id\": 5, \"location\": \"file:///var/lib/glance/images/5\", \"checksum\": \"73152adae523a52d481f5150deb30356\", \"is_public\": true, \"deleted_at\": null, \"properties\": {\"arch\": \"amd64\", \"version\": \"2.6.32\", \"type\": \"kernel\", \"uploader\": \"root@e3ab3\", \"distro\": \"Ubuntu\"}, \"size\": 4408912}, {\"status\": \"active\", \"name\": \"maverick-server-uec-amd64.img\", \"deleted\": false, \"container_format\": \"ami\", \"created_at\": \"2011-04-06T20:04:48.664176\", \"disk_format\": \"ami\", \"updated_at\": \"2011-04-06T20:04:57.042658\", \"id\": 6, \"location\": \"file:///var/lib/glance/images/6\", \"checksum\": \"d511da81009517c53f36ff4e8602ff62\", \"is_public\": true, \"deleted_at\": null, \"properties\": {\"kernel_id\": \"5\", \"type\": \"machine\", \"version\": \"10.10\", \"kernel_name\": \"maverick-server-uec-amd64-vmlinuz-virtual\", \"uploader\": \"root@e3ab3\", \"arch\": \"amd64\", \"distro\": \"Ubuntu\"}, \"size\": 1476395008}]}"
28
+ http_version: "1.1"
@@ -0,0 +1,72 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :head
5
+ uri: http://10.1.170.33: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
+ - Ubuntu
25
+ x-image-meta-id:
26
+ - "6"
27
+ x-image-meta-property-arch:
28
+ - amd64
29
+ x-image-meta-deleted:
30
+ - "False"
31
+ x-image-meta-container-format:
32
+ - ami
33
+ x-image-meta-property-uploader:
34
+ - root@e3ab3
35
+ x-image-meta-location:
36
+ - file:///var/lib/glance/images/6
37
+ x-image-meta-deleted-at:
38
+ - ""
39
+ x-image-meta-created-at:
40
+ - 2011-04-06T20:04:48.664176
41
+ x-image-meta-size:
42
+ - "1476395008"
43
+ x-image-meta-status:
44
+ - active
45
+ x-image-meta-property-type:
46
+ - machine
47
+ x-image-meta-property-kernel-name:
48
+ - maverick-server-uec-amd64-vmlinuz-virtual
49
+ x-image-meta-is-public:
50
+ - "True"
51
+ x-image-meta-property-kernel-id:
52
+ - "5"
53
+ x-image-meta-updated-at:
54
+ - 2011-04-06T20:04:57.042658
55
+ x-image-meta-checksum:
56
+ - d511da81009517c53f36ff4e8602ff62
57
+ x-image-meta-property-version:
58
+ - "10.10"
59
+ x-image-meta-disk-format:
60
+ - ami
61
+ x-image-meta-name:
62
+ - maverick-server-uec-amd64.img
63
+ location:
64
+ - http://10.1.170.33:9292/images/6
65
+ etag:
66
+ - d511da81009517c53f36ff4e8602ff62
67
+ date:
68
+ - Fri, 08 Apr 2011 17:56:53 GMT
69
+ connection:
70
+ - keep-alive
71
+ body:
72
+ http_version: "1.1"
@@ -0,0 +1,37 @@
1
+ require "test_helper"
2
+
3
+ CONNECTION = Ogle::Client.new(
4
+ :host => "10.1.170.33"
5
+ )
6
+
7
+ describe Ogle::Resource do
8
+ describe "#all" do
9
+ it "returns a hash of images" do
10
+ VCR.use_cassette "resource_all" do
11
+ response = CONNECTION.resource.all
12
+
13
+ response.size.must_equal 6
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "#all true" do
19
+ it "returns a detailed hash of images (verbose = true)" do
20
+ VCR.use_cassette "resource_all_verbose" do
21
+ response = CONNECTION.resource.all true
22
+
23
+ response.size.must_equal 6
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "#find" do
29
+ it "returns X-Image-Meta-* headers as a hash" do
30
+ VCR.use_cassette "resource_find" do
31
+ response = CONNECTION.resource.find 6
32
+
33
+ response.size.must_equal 20
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ %w(bundler minitest/spec ogle vcr webmock).each { |r| require r }
2
+
3
+ Bundler.setup :default, :test
4
+
5
+ class MiniTest::Unit::TestCase
6
+ def cassette_for cassette
7
+ c = VCR::Cassette.new(cassette).send :recorded_interactions
8
+ end
9
+ end
10
+
11
+ VCR.config do |c|
12
+ c.stub_with :webmock
13
+ c.cassette_library_dir = "test/cassettes"
14
+ c.default_cassette_options = { :record => :none }
15
+ end
16
+
17
+
18
+ MiniTest::Unit.autorun
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ogle
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Kevin Bringard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-08 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: hugs
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 2.5.2
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: vcr
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - "="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.5.0
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: webmock
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: minitest
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ type: :development
70
+ version_requirements: *id005
71
+ description: Exposes the API for OpenStack Glance. Go ahead and ogle, it's so much more than a glance.
72
+ email:
73
+ - kbringard@attinteractive.com
74
+ executables: []
75
+
76
+ extensions: []
77
+
78
+ extra_rdoc_files: []
79
+
80
+ files:
81
+ - .gitignore
82
+ - .rvmrc
83
+ - Gemfile
84
+ - README.md
85
+ - Rakefile
86
+ - lib/ogle.rb
87
+ - lib/ogle/client.rb
88
+ - lib/ogle/resource.rb
89
+ - lib/ogle/version.rb
90
+ - ogle.gemspec
91
+ - test/cassettes/resource_all.yml
92
+ - test/cassettes/resource_all_verbose.yml
93
+ - test/cassettes/resource_find.yml
94
+ - test/lib/ogle/resource_test.rb
95
+ - test/test_helper.rb
96
+ has_rdoc: true
97
+ homepage: ""
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project: ogle
120
+ rubygems_version: 1.6.2
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Ruby interface for OpenStack Glance
124
+ test_files:
125
+ - test/cassettes/resource_all.yml
126
+ - test/cassettes/resource_all_verbose.yml
127
+ - test/cassettes/resource_find.yml
128
+ - test/lib/ogle/resource_test.rb
129
+ - test/test_helper.rb