ogler 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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ogler.gemspec
4
+ gemspec
data/README ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,242 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ##
4
+ # Copyright (c) 2011 Kevin Bringard
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ ###
25
+
26
+ # gem install ogle
27
+ require 'ogle'
28
+
29
+ require 'optparse'
30
+
31
+ # Define our options
32
+ options = {}
33
+
34
+ optparse = OptionParser.new do |opts|
35
+ opts.banner = "Usage: #{$0} -i|--image file -v|--version version -d|--distro distribution -a|--arch architecture [-u|--user user] [ -P|--pass password] [-H|--host host] [-p|--port port] [-n|--name name] [-r|-ramdisk ramdisk] [-k|--kernel kernel] [-e|--kernel_version kernel_version] [-s|--storage ENGINE] [-c|--custom_fields field1=1,field2=2]"
36
+
37
+ options[:host] = "localhost"
38
+ opts.on( '-H', '--host HOST', 'Glance host to connect to (defaults to localhost)') do |host|
39
+ options[:host] = host
40
+ end
41
+
42
+ options[:port] = "9292"
43
+ opts.on( '-p', '--port PORT', 'Glance port to connect to (defaults to 9292)') do |port|
44
+ options[:port] = port
45
+ end
46
+
47
+ options[:user] = nil
48
+ opts.on( '-u', '--user USER', 'Username to authenticate with') do |user|
49
+ options[:user] = user
50
+ end
51
+
52
+ options[:pass] = nil
53
+ opts.on( '-P', '--pass PASSWORD', 'Password to authenticate with') do |pass|
54
+ options[:pass] = pass
55
+ end
56
+
57
+ options[:image] = nil
58
+ opts.on( '-i', '--image FILE', 'Machine image to upload (required)') do |image|
59
+ options[:image] = image
60
+ end
61
+
62
+ options[:name] = nil
63
+ opts.on( '-n', '--name NAME', 'Name to give the image when it has been uploaded (defaults to distro_version-arch)') do |name|
64
+ options[:name] = name
65
+ end
66
+
67
+ options[:ramdisk] = nil
68
+ opts.on( '-r', '--ramdisk [FILE|ID]', 'Ramdisk image to upload, or existing ID to link to') do |ramdisk|
69
+ options[:ramdisk] = ramdisk
70
+ end
71
+
72
+ options[:kernel] = nil
73
+ opts.on( '-k', '--kernel [FILE|ID]', 'Kernel image to upload, or existing ID to link to') do |kernel|
74
+ options[:kernel] = kernel
75
+ end
76
+
77
+ options[:version] = nil
78
+ opts.on( '-v', '--version VERSION', 'The version of the OS you are uploading (required)') do |version|
79
+ options[:version] = version
80
+ end
81
+
82
+ options[:distro] = nil
83
+ opts.on( '-d', '--distro DISTRO', 'The distribution you are uploading (Ubuntu, CentOS, Debian, etc) (required)') do |distro|
84
+ options[:distro] = distro
85
+ end
86
+
87
+ options[:storage] = nil
88
+ opts.on( '-s', '--storage ENGINE', [:file, :s3, :swift ], 'The storage engine to use, valid options are file, s3, or swift. If you don\'t specify one it uses the glance default (currently file)') do |storage|
89
+ options[:storage] = storage
90
+ end
91
+
92
+ options[:kernel_version] = nil
93
+ opts.on( '-e', '--kernel_version VERSION', 'The kernel version (2.6.28, 2.6.32-el6, etc). Required if you are uploading a kernel') do |kernel_version|
94
+ options[:kernel_version] = kernel_version
95
+ end
96
+
97
+ options[:arch] = nil
98
+ opts.on( '-a', '--arch ARCH', 'The architecture of the image (x86_64, amd64, i386, etc) (required)') do |arch|
99
+ options[:arch] = arch
100
+ end
101
+
102
+ options[:custom] = []
103
+ opts.on( '-c', '--custom_fields a=1,b=2,c=3', Array, 'Custom fields you wish to define') do |custom|
104
+ options[:custom] = custom
105
+ end
106
+
107
+ opts.on( '-h', '--help', 'Display the help screen' ) do
108
+ puts opts
109
+ exit
110
+ end
111
+
112
+ if ARGV.empty?
113
+ puts opts
114
+ exit
115
+ end
116
+
117
+ end
118
+
119
+ optparse.parse!
120
+
121
+ # These options are required
122
+ unless options[:distro] && options[:version] && options[:arch]
123
+ puts "You seem to be missing a required option"
124
+ puts optparse
125
+ exit
126
+ end
127
+
128
+ # Set the name to be "#{options[:distro]}_#{options[:version]}-#{options[:arch]}" if a name wasn't specified
129
+ unless options[:name]
130
+ options[:name] = "#{options[:distro]}_#{options[:version]}-#{options[:arch]}"
131
+ end
132
+
133
+ def build_headers options, ramdisk_id, kernel_id, type
134
+
135
+ # These headers are required
136
+ required_headers = {
137
+ "x-image-meta-is-public" => "true",
138
+ }
139
+
140
+ if options[:storage] != nil
141
+ required_headers = {"x-image-meta-store" => "#{options[:storage]}" }.merge required_headers
142
+ end
143
+
144
+ if type == "ramdisk"
145
+ required_headers = { "x-image-meta-disk-format" => "ari", "x-image-meta-container-format" => "ari", "x-image-meta-name" => "#{options[:name]}-ramdisk" }.merge required_headers
146
+ elsif type == "kernel"
147
+ required_headers = { "x-image-meta-disk-format" => "aki", "x-image-meta-container-format" => "aki", "x-image-meta-name" => "#{options[:name]}-kernel" }.merge required_headers
148
+ elsif type == "machine"
149
+ required_headers = { "x-image-meta-disk-format" => "ami", "x-image-meta-container-format" => "ami" }.merge required_headers
150
+ else
151
+ puts "Something seems to be wrong... valid types are ramdisk, kernel or machine"
152
+ exit 1
153
+ end
154
+
155
+ # If a ramdisk was included, we need to link the image to the ramdisk_id
156
+ if ramdisk_id && type == "machine"
157
+ required_headers = { "x-image-meta-property-ramdisk_id" => "#{ramdisk_id}" }.merge required_headers
158
+ end
159
+
160
+ # Same as above, except for the kernel
161
+ if kernel_id && type == "machine"
162
+ required_headers = { "x-image-meta-property-kernel_id" => "#{kernel_id}" }.merge required_headers
163
+ end
164
+
165
+ # These are the required options specific to ATT
166
+ options_headers = {
167
+ "x-image-meta-property-distro" => "#{options[:distro]}",
168
+ "x-image-meta-property-version" => "#{options[:version]}",
169
+ "x-image-meta-property-arch" => "#{options[:arch]}"
170
+ }
171
+
172
+ # These are custom property headers. They're not required but if the user wants to add them, they can
173
+ custom_headers = {}
174
+ options[:custom].each do |custom|
175
+ k,v = custom.split("=")
176
+ custom_headers = { "x-image-meta-property-#{k}" => v }.merge custom_headers
177
+ end
178
+
179
+ # Finally we merge them all into one big hash and return it
180
+ headers = {}
181
+ headers.merge!(required_headers) if required_headers
182
+ headers.merge!(options_headers) if options_headers
183
+ headers.merge!(custom_headers) if custom_headers
184
+
185
+ end
186
+
187
+ def create options, ramdisk_id, kernel_id
188
+
189
+ if options[:ramdisk] && ramdisk_id == ""
190
+ # Upload the ramdisk and parse it's ID from the response
191
+ @headers = build_headers options, ramdisk_id, kernel_id, "ramdisk"
192
+ response = CONNECTION.image.create "#{options[:ramdisk]}", "#{options[:ramdisk]}", @headers
193
+ ramdisk_id = response.id
194
+ end
195
+
196
+ if options[:kernel] && kernel_id == ""
197
+ # Upload the kernel and parse it's ID from the response
198
+ @headers = build_headers options, ramdisk_id, kernel_id, "kernel"
199
+ response = CONNECTION.image.create "#{options[:kernel]}", "#{options[:kernel]}", @headers
200
+ kernel_id = response.id
201
+ end
202
+
203
+ @headers = build_headers options, ramdisk_id, kernel_id, "machine"
204
+ response = CONNECTION.image.create "#{options[:name]}", "#{options[:image]}", @headers
205
+ return response
206
+ end
207
+
208
+ CONNECTION = Ogle::Client.new(
209
+ :user => "#{options[:user]}",
210
+ :pass => "#{options[:pass]}",
211
+ :host => "#{options[:host]}",
212
+ :port => "#{options[:port]}"
213
+ )
214
+
215
+ # If the argument specified in kernel and ramdisk are files that exist, upload them
216
+ if File.exist?("#{options[:kernel]}") && File.exist?("#{options[:ramdisk]}")
217
+ response = create options, "", ""
218
+
219
+ # If the argument that was specified for ramdisk doesn't exist, and is an integer, then we assume it's a ramdisk_id and pass it along to create
220
+ elsif File.exist?("#{options[:kernel]}") && options[:ramdisk].to_i != 0
221
+ response = create options, "#{options[:ramdisk]}", ""
222
+
223
+ # If the argument that was specified for kernel doesn't exist, and is an integer, then we assume it's a kernel_id and pass it alone to create
224
+ elsif File.exist?("#{options[:ramdisk]}") && options[:kernel].to_i != 0
225
+ response = create options, "", "#{options[:kernel]}"
226
+
227
+ # If neither ramdisk nor kernel are on disk and they're both integers, then we pass them along to create to link up
228
+ elsif options[:ramdisk].to_i != 0 && options[:kernel].to_i != 0
229
+ response = create options, "#{options[:ramdisk]}", "#{options[:kernel]}"
230
+ else
231
+ if options[:kernel] == nil || options[:ramdisk] == nil
232
+ response = create options, "", ""
233
+ else
234
+ puts "Something seems to have gone wrong, I'm out of here"
235
+ exit 1
236
+ end
237
+ end
238
+
239
+ if defined? response != "nil"
240
+ puts "Image(s) uploaded!"
241
+ puts response.inspect
242
+ end
@@ -0,0 +1,3 @@
1
+ module Ogler
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,3 @@
1
+ module Ogler
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ogler/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ogler"
7
+ s.version = Ogler::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kevin Bringard"]
10
+ s.email = ["kevinbringard@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Uploader for glance using ogle}
13
+ s.description = %q{Uploader for glance which uses the ogle library to be completely standalone}
14
+
15
+ s.rubyforge_project = "ogler"
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 "ogle"
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ogler
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-08-12 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ogle
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Uploader for glance which uses the ogle library to be completely standalone
28
+ email:
29
+ - kevinbringard@gmail.com
30
+ executables:
31
+ - ogler
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - README
40
+ - Rakefile
41
+ - bin/ogler
42
+ - lib/ogler.rb
43
+ - lib/ogler/version.rb
44
+ - ogler.gemspec
45
+ has_rdoc: true
46
+ homepage: ""
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: ogler
69
+ rubygems_version: 1.6.2
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Uploader for glance using ogle
73
+ test_files: []
74
+