aeolus-image 0.0.1 → 0.4.0

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.
Files changed (63) hide show
  1. data/COPYING +161 -0
  2. data/Rakefile +32 -19
  3. data/lib/aeolus_image.rb +35 -0
  4. data/lib/aeolus_image/active_resource_oauth_client.rb +62 -0
  5. data/lib/aeolus_image/import.rb +44 -0
  6. data/lib/aeolus_image/model/factory/base.rb +93 -0
  7. data/lib/aeolus_image/model/factory/build.rb +23 -0
  8. data/lib/aeolus_image/model/factory/builder.rb +46 -0
  9. data/lib/aeolus_image/model/factory/image.rb +23 -0
  10. data/lib/aeolus_image/model/factory/provider_image.rb +35 -0
  11. data/lib/aeolus_image/model/factory/target_image.rb +45 -0
  12. data/lib/aeolus_image/model/warehouse/icicle.rb +60 -0
  13. data/lib/aeolus_image/model/warehouse/image.rb +135 -0
  14. data/lib/aeolus_image/model/warehouse/image_build.rb +60 -0
  15. data/lib/aeolus_image/model/warehouse/provider_image.rb +36 -0
  16. data/lib/aeolus_image/model/warehouse/target_image.rb +53 -0
  17. data/lib/aeolus_image/model/warehouse/template.rb +35 -0
  18. data/lib/aeolus_image/model/warehouse/warehouse_client.rb +201 -0
  19. data/lib/aeolus_image/model/warehouse/warehouse_model.rb +236 -0
  20. data/spec/aeolus_image/model/factory/provider_image_spec.rb +12 -0
  21. data/spec/models/factory/base_spec.rb +94 -0
  22. data/spec/models/factory/builder_spec.rb +31 -0
  23. data/spec/models/factory/provider_image_spec.rb +21 -0
  24. data/spec/models/factory/target_image_spec.rb +21 -0
  25. data/spec/models/warehouse/image_build_spec.rb +189 -0
  26. data/spec/models/warehouse/image_spec.rb +241 -0
  27. data/spec/models/warehouse/provider_image_spec.rb +115 -0
  28. data/spec/models/warehouse/target_image_spec.rb +180 -0
  29. data/spec/models/warehouse/template_spec.rb +76 -0
  30. data/spec/models/warehouse/warehouse_client_spec.rb +445 -0
  31. data/spec/models/warehouse/warehouse_model_spec.rb +94 -0
  32. data/spec/spec_helper.rb +34 -47
  33. data/spec/vcr/cassettes/builder.yml +24 -0
  34. data/spec/vcr/cassettes/oauth.yml +80 -0
  35. data/spec/vcr/cassettes/oauth_fail_invalid.yml +30 -0
  36. data/spec/vcr/cassettes/oauth_fail_no.yml +22 -0
  37. data/spec/vcr/cassettes/oauth_success_valid.yml +30 -0
  38. data/spec/vcr_setup.rb +26 -0
  39. metadata +70 -46
  40. data/bin/aeolus-image +0 -6
  41. data/examples/aeolus-cli +0 -9
  42. data/examples/custom_repo.tdl +0 -18
  43. data/examples/image_description.xml +0 -3
  44. data/examples/tdl.rng +0 -207
  45. data/lib/base_command.rb +0 -134
  46. data/lib/build_command.rb +0 -68
  47. data/lib/config_parser.rb +0 -212
  48. data/lib/delete_command.rb +0 -9
  49. data/lib/import_command.rb +0 -44
  50. data/lib/list_command.rb +0 -141
  51. data/lib/push_command.rb +0 -72
  52. data/man/aeolus-image-build.1 +0 -36
  53. data/man/aeolus-image-import.1 +0 -57
  54. data/man/aeolus-image-list.1 +0 -80
  55. data/man/aeolus-image-push.1 +0 -40
  56. data/man/aeolus-image.1 +0 -16
  57. data/spec/base_command_spec.rb +0 -76
  58. data/spec/build_command_spec.rb +0 -63
  59. data/spec/config_parser_spec.rb +0 -82
  60. data/spec/import_command_spec.rb +0 -43
  61. data/spec/list_command_spec.rb +0 -21
  62. data/spec/push_command_spec.rb +0 -56
  63. data/spec/spec.opts +0 -3
data/COPYING ADDED
@@ -0,0 +1,161 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and
12
+ distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
15
+ owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all other entities
18
+ that control, are controlled by, or are under common control with that entity.
19
+ For the purposes of this definition, "control" means (i) the power, direct or
20
+ indirect, to cause the direction or management of such entity, whether by
21
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
25
+ permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications, including
28
+ but not limited to software source code, documentation source, and
29
+ configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical transformation or
32
+ translation of a Source form, including but not limited to compiled object
33
+ code, generated documentation, and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object form,
36
+ made available under the License, as indicated by a copyright notice that is
37
+ included in or attached to the work (an example is provided in the Appendix
38
+ below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
41
+ is based on (or derived from) the Work and for which the editorial revisions,
42
+ annotations, elaborations, or other modifications represent, as a whole, an
43
+ original work of authorship. For the purposes of this License, Derivative Works
44
+ shall not include works that remain separable from, or merely link (or bind by
45
+ name) to the interfaces of, the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
52
+ of this definition, "submitted" means any form of electronic, verbal, or
53
+ written communication sent to the Licensor or its representatives, including
54
+ but not limited to communication on electronic mailing lists, source code
55
+ control systems, and issue tracking systems that are managed by, or on behalf
56
+ of, the Licensor for the purpose of discussing and improving the Work, but
57
+ excluding communication that is conspicuously marked or otherwise designated in
58
+ writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
61
+ of whom a Contribution has been received by Licensor and subsequently
62
+ incorporated within the Work.
63
+
64
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
65
+ License, each Contributor hereby grants to You a perpetual, worldwide,
66
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
67
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
68
+ sublicense, and distribute the Work and such Derivative Works in Source or
69
+ Object form.
70
+
71
+ 3. Grant of Patent License. Subject to the terms and conditions of this
72
+ License, each Contributor hereby grants to You a perpetual, worldwide,
73
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
74
+ section) patent license to make, have made, use, offer to sell, sell, import,
75
+ and otherwise transfer the Work, where such license applies only to those
76
+ patent claims licensable by such Contributor that are necessarily infringed by
77
+ their Contribution(s) alone or by combination of their Contribution(s) with the
78
+ Work to which such Contribution(s) was submitted. If You institute patent
79
+ litigation against any entity (including a cross-claim or counterclaim in a
80
+ lawsuit) alleging that the Work or a Contribution incorporated within the Work
81
+ constitutes direct or contributory patent infringement, then any patent
82
+ licenses granted to You under this License for that Work shall terminate as of
83
+ the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
86
+ Derivative Works thereof in any medium, with or without modifications, and in
87
+ Source or Object form, provided that You meet the following conditions:
88
+
89
+ You must give any other recipients of the Work or Derivative Works a copy of
90
+ this License; and
91
+
92
+ You must cause any modified files to carry prominent notices stating that You
93
+ changed the files; and
94
+
95
+ You must retain, in the Source form of any Derivative Works that You
96
+ distribute, all copyright, patent, trademark, and attribution notices from the
97
+ Source form of the Work, excluding those notices that do not pertain to any
98
+ part of the Derivative Works; and
99
+
100
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
101
+ Derivative Works that You distribute must include a readable copy of the
102
+ attribution notices contained within such NOTICE file, excluding those notices
103
+ that do not pertain to any part of the Derivative Works, in at least one of the
104
+ following places: within a NOTICE text file distributed as part of the
105
+ Derivative Works; within the Source form or documentation, if provided along
106
+ with the Derivative Works; or, within a display generated by the Derivative
107
+ Works, if and wherever such third-party notices normally appear. The contents
108
+ of the NOTICE file are for informational purposes only and do not modify the
109
+ License. You may add Your own attribution notices within Derivative Works that
110
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
111
+ provided that such additional attribution notices cannot be construed as
112
+ modifying the License. You may add Your own copyright statement to Your
113
+ modifications and may provide additional or different license terms and
114
+ conditions for use, reproduction, or distribution of Your modifications, or for
115
+ any such Derivative Works as a whole, provided Your use, reproduction, and
116
+ distribution of the Work otherwise complies with the conditions stated in this
117
+ License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
120
+ Contribution intentionally submitted for inclusion in the Work by You to the
121
+ Licensor shall be under the terms and conditions of this License, without any
122
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
123
+ supersede or modify the terms of any separate license agreement you may have
124
+ executed with Licensor regarding such Contributions.
125
+
126
+ 6. Trademarks. This License does not grant permission to use the trade names,
127
+ trademarks, service marks, or product names of the Licensor, except as required
128
+ for reasonable and customary use in describing the origin of the Work and
129
+ reproducing the content of the NOTICE file.
130
+
131
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
132
+ writing, Licensor provides the Work (and each Contributor provides its
133
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
134
+ KIND, either express or implied, including, without limitation, any warranties
135
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
136
+ PARTICULAR PURPOSE. You are solely responsible for determining the
137
+ appropriateness of using or redistributing the Work and assume any risks
138
+ associated with Your exercise of permissions under this License.
139
+
140
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
141
+ tort (including negligence), contract, or otherwise, unless required by
142
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
143
+ writing, shall any Contributor be liable to You for damages, including any
144
+ direct, indirect, special, incidental, or consequential damages of any
145
+ character arising as a result of this License or out of the use or inability to
146
+ use the Work (including but not limited to damages for loss of goodwill, work
147
+ stoppage, computer failure or malfunction, or any and all other commercial
148
+ damages or losses), even if such Contributor has been advised of the
149
+ possibility of such damages.
150
+
151
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
152
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
153
+ acceptance of support, warranty, indemnity, or other liability obligations
154
+ and/or rights consistent with this License. However, in accepting such
155
+ obligations, You may act only on Your own behalf and on Your sole
156
+ responsibility, not on behalf of any other Contributor, and only if You agree
157
+ to indemnify, defend, and hold each Contributor harmless for any liability
158
+ incurred by, or claims asserted against, such Contributor by reason of your
159
+ accepting any such warranty or additional liability.
160
+
161
+ END OF TERMS AND CONDITIONS
data/Rakefile CHANGED
@@ -1,44 +1,58 @@
1
+ # Copyright 2011 Red Hat, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'rubygems'
2
16
  require 'rake'
3
17
  require 'rake/clean'
4
- require 'rake/gempackagetask'
5
- require 'rake/rdoctask'
18
+ require 'rubygems/package_task'
19
+ require 'rdoc/task'
6
20
  require 'rake/testtask'
7
- require 'spec/rake/spectask'
8
- require 'rake/rpmtask'
21
+ require 'rspec/core/rake_task'
22
+ require './rake/rpmtask'
9
23
 
10
24
  RPMBUILD_DIR = "#{File.expand_path('~')}/rpmbuild"
11
25
  RPM_SPEC = "rubygem-aeolus-image.spec"
26
+ RPM_SPEC_IN = "rubygem-aeolus-image.spec.in"
27
+ PKG_VERSION = "0.4.0"
12
28
 
13
29
  spec = Gem::Specification.new do |s|
14
30
  s.name = 'aeolus-image'
15
- s.version = '0.0.1'
16
- s.has_rdoc = true
17
- s.summary= 'cli for aeolus cloud suite'
18
- s.description = 'Commandline interface for working with the aeolus cloud management suite'
31
+ s.version = PKG_VERSION
32
+ s.summary= 'Ruby Client for Image Warehouse and Image Factory for the Aeolus cloud suite'
33
+ s.description = 'Library for managing image via the Factory and Warehouse projects for the aeolus cloud management suite'
19
34
  s.author = 'Jason Guiditta, Martyn Taylor'
20
35
  s.email = 'jguiditt@redhat.com, mtaylor@redhat.com'
21
- s.license = 'GPL-2'
36
+ s.license = 'ASL 2.0'
22
37
  s.homepage = 'http://aeolusproject.org'
23
- s.executables << 'aeolus-image'
24
- s.files = %w(Rakefile) + Dir.glob("{bin,lib,spec,examples,man}/**/*")
38
+ s.files = %w(Rakefile) + Dir.glob("{lib,spec}/**/*") + %w(COPYING)
25
39
  s.require_path = "lib"
26
- s.bindir = "bin"
27
40
  s.add_dependency('nokogiri', '>=0.4.0')
28
41
  s.add_dependency('rest-client')
29
- s.add_dependency('imagefactory-console', '>=0.4.0')
42
+ s.add_dependency('activeresource', '~>3.0.10')
43
+ s.add_dependency('oauth')
30
44
 
31
45
  s.add_development_dependency('rspec', '~>1.3.0')
32
46
  end
33
47
 
34
- Rake::GemPackageTask.new(spec) do |p|
48
+ Gem::PackageTask.new(spec) do |p|
35
49
  p.gem_spec = spec
36
50
  p.need_tar = true
37
51
  p.need_zip = true
38
52
  end
39
53
 
40
54
  Rake::RDocTask.new do |rdoc|
41
- files =['README', 'LICENSE', 'lib/**/*.rb']
55
+ files =['README', 'COPYING', 'lib/**/*.rb']
42
56
  rdoc.rdoc_files.add(files)
43
57
  rdoc.main = "README" # page to start on
44
58
  rdoc.title = "aeolus-image Docs"
@@ -50,12 +64,11 @@ Rake::TestTask.new do |t|
50
64
  t.test_files = FileList['test/**/*.rb']
51
65
  end
52
66
 
53
- Spec::Rake::SpecTask.new do |t|
54
- t.spec_files = FileList['spec/**/*.rb']
55
- t.libs << Dir["lib"]
67
+ RSpec::Core::RakeTask.new do |t|
68
+ t.pattern = FileList['spec/**/*.rb']
56
69
  end
57
70
 
58
- Rake::RpmTask.new(RPM_SPEC) do |rpm|
71
+ Rake::RpmTask.new(RPM_SPEC, {:suffix => '.in', :pkg_version => PKG_VERSION}) do |rpm|
59
72
  rpm.need_tar = true
60
73
  rpm.package_files.include("lib/*")
61
74
  rpm.topdir = "#{RPMBUILD_DIR}"
@@ -0,0 +1,35 @@
1
+ # Copyright 2011 Red Hat, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'optparse'
16
+ require 'logger'
17
+ require 'active_resource'
18
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'warehouse_client') # Not sure we need this
19
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'warehouse_model') # We may be able to factor this out?
20
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'icicle')
21
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'image')
22
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'image_build')
23
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'provider_image')
24
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'target_image')
25
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/warehouse', 'template')
26
+
27
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'base')
28
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'image')
29
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'build')
30
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'provider_image')
31
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'target_image')
32
+ require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory', 'builder')
33
+ require File.join(File.dirname(__FILE__), 'aeolus_image', 'active_resource_oauth_client')
34
+
35
+ require File.join(File.dirname(__FILE__), 'aeolus_image', 'import')
@@ -0,0 +1,62 @@
1
+ # Copyright (c) 2011 Red Hat, Inc.
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
4
+ # associated documentation files (the "Software"), to deal in the Software without restriction,
5
+ # including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6
+ # and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
7
+ # so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial
10
+ # portions of the Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
13
+ # LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
14
+ # NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+
18
+
19
+ require 'oauth'
20
+
21
+ # Monkey-patch ActiveResource to allow us to merge our OAuth headers in.
22
+ # Portions of the below are taken from Active Resource which is MIT licensed;
23
+ # hence this whole file is being licensed under the MIT License to err on the side of safety.
24
+ module ActiveResourceOAuthClient
25
+ ActiveResource::Connection.class_eval do
26
+ def request_with_oauth(method, path, *arguments)
27
+ @oauth_config = Aeolus::Image::Factory::Base.config || {}
28
+ # Take care to fall back to the standard request method if we don't have full OAuth credentials
29
+ unless Aeolus::Image::Factory::Base.use_oauth?
30
+ return request_without_oauth(method, path, *arguments)
31
+ end
32
+ result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
33
+ payload[:method] = method
34
+ payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
35
+ oauth_consumer = OAuth::Consumer.new(
36
+ @oauth_config[:consumer_key],
37
+ @oauth_config[:consumer_secret],
38
+ :site => @oauth_config[:site] )
39
+ token = OAuth::AccessToken.new(oauth_consumer)
40
+ base_request = oauth_consumer.create_signed_request(method, path, token, {}, *arguments)
41
+ payload[:result] = http.request(base_request)
42
+ end
43
+ # Error-handling code from OAuth
44
+ # http://wiki.oauth.net/w/page/12238543/ProblemReporting
45
+ auth_header = result.to_hash['www-authenticate']
46
+ problem_header = auth_header ? auth_header.select{|h| h =~ /^OAuth /}.select{|h| h =~ /oauth_problem/}.first : nil
47
+ if auth_header && problem_header
48
+ params = OAuth::Helper.parse_header(problem_header)
49
+ raise OAuth::Problem.new(params.delete("oauth_problem"), result, params)
50
+ end
51
+ # Error-handling code from ActiveResource
52
+ handle_response(result)
53
+ rescue Timeout::Error => e
54
+ raise TimeoutError.new(e.message)
55
+ rescue OpenSSL::SSL::SSLError => e
56
+ raise SSLError.new(e.message)
57
+ end
58
+
59
+ alias_method_chain :request, :oauth
60
+
61
+ end
62
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright 2011 Red Hat, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Aeolus
16
+ module Image
17
+ def self.import(provider_name, deltacloud_driver, image_id, account_id, environment, xml=nil, arch=nil)
18
+ xml ||= "<image><name>#{image_id}</name></image>"
19
+ image = Factory::Image.new(
20
+ :target_name => deltacloud_driver,
21
+ :provider_name => provider_name,
22
+ :target_identifier => image_id,
23
+ :image_descriptor => xml
24
+ )
25
+ image.save!
26
+ # Set the provider_account_id on the image
27
+ iwhd_image = Warehouse::Image.find(image.id)
28
+ iwhd_image.set_attr("environment", environment)
29
+ # For imported images, stash an :architecture flag on the image itself since we have no template
30
+ iwhd_image.set_attr(:architecture, arch) if arch
31
+ # Set the account on the provider image
32
+ # This assumes (as is currently correct) that there will only be one provider image for imported images
33
+ pimg = iwhd_image.provider_images.first
34
+ # Check that we have provider images! If not, the import has failed.
35
+ if pimg
36
+ pimg.set_attr('provider_account_identifier', account_id)
37
+ return image
38
+ else
39
+ iwhd_image.delete!
40
+ raise "Image import failed to import provider image! Aborting."
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,93 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Aeolus
17
+ module Image
18
+ module Factory
19
+ class Base < ActiveResource::Base
20
+ self.format = :json
21
+ self.ssl_options = {:verify_mode => OpenSSL::SSL::VERIFY_NONE}
22
+
23
+ class << self
24
+ ## Remove format from the url for resources
25
+ def element_path(id, prefix_options = {}, query_options = nil)
26
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
27
+ "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
28
+ end
29
+
30
+ ## Remove format from the url for collections
31
+ def collection_path(prefix_options = {}, query_options = nil)
32
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
33
+ "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
34
+ end
35
+
36
+ ## For a collection call, ActiveResource formatting is not
37
+ ## compliant with Factory's output.
38
+ def instantiate_collection(collection, prefix_options = {})
39
+ unless collection.kind_of? Array
40
+ [instantiate_record(collection, prefix_options)]
41
+ else
42
+ collection.collect! { |record| instantiate_record(record, prefix_options) }
43
+ end
44
+ end
45
+
46
+ ## The objects returned from this method are not automatically converted into ActiveResource instances - they are ordinary Hashes.
47
+ ## Modifications below ensures that you get ActiveResource instances.
48
+ def get(method_name, options = {})
49
+ object_array = connection.get(custom_method_collection_url(method_name, options), headers)
50
+ if object_array.class.to_s=="Array"
51
+ object_array.collect! {|record| self.class.new.load(record)}
52
+ else
53
+ self.class.new.load(object_array)
54
+ end
55
+ end
56
+
57
+ # This approach does mean you're limited to one server at a time
58
+ def config
59
+ defined?(@@config) ? @@config : {}
60
+ end
61
+ def config=(conf={})
62
+ @@config = conf
63
+ self.site = @@config[:site]
64
+ end
65
+
66
+ # Should we use OAuth?
67
+ def use_oauth?
68
+ config[:consumer_key] && config[:consumer_secret] && config[:site]
69
+ end
70
+ end
71
+
72
+ ## Instance Methods: (modifying the ActiveRecord::CustomMethods).
73
+ ## This modification is same as defined in above method
74
+ def get(method_name, options = {})
75
+ self.class.new.load(connection.get(custom_method_element_url(method_name, options), self.class.headers))
76
+ end
77
+
78
+ # Modifying the url formations to make them Factory compliant
79
+ def custom_method_element_url(method_name, options = {})
80
+ "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/" +
81
+ "#{method_name}#{self.class.send!(:query_string, options)}"
82
+ end
83
+
84
+ # Modifying the url formations to make them Factory compliant
85
+ def self.custom_method_collection_url(method_name, options = {})
86
+ prefix_options, query_options = split_options(options)
87
+ url = "#{prefix(prefix_options)}#{collection_name}/#{method_name}#{query_string(query_options)}"
88
+ url
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end