steamcannon-deltacloud-core 0.0.7.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/COPYING +176 -0
  2. data/Rakefile +106 -0
  3. data/bin/deltacloudd +120 -0
  4. data/config.ru +5 -0
  5. data/deltacloud.rb +20 -0
  6. data/lib/deltacloud/base_driver/base_driver.rb +259 -0
  7. data/lib/deltacloud/base_driver/features.rb +173 -0
  8. data/lib/deltacloud/base_driver/mock_driver.rb +58 -0
  9. data/lib/deltacloud/base_driver.rb +20 -0
  10. data/lib/deltacloud/drivers/azure/azure_driver.rb +127 -0
  11. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +580 -0
  12. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
  13. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +50 -0
  14. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +343 -0
  15. data/lib/deltacloud/drivers/gogrid/test.rb +13 -0
  16. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml +5 -0
  17. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml +5 -0
  18. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml +5 -0
  19. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml +5 -0
  20. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml +5 -0
  21. data/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml +2 -0
  22. data/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml +2 -0
  23. data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
  24. data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
  25. data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
  26. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
  27. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
  28. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
  29. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
  30. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
  31. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
  32. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
  33. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
  34. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
  35. data/lib/deltacloud/drivers/mock/mock_driver.rb +356 -0
  36. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
  37. data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
  38. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
  39. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +130 -0
  40. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +290 -0
  41. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +258 -0
  42. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +85 -0
  43. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +166 -0
  44. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +295 -0
  45. data/lib/deltacloud/hardware_profile.rb +153 -0
  46. data/lib/deltacloud/helpers/application_helper.rb +122 -0
  47. data/lib/deltacloud/helpers/blob_stream.rb +51 -0
  48. data/lib/deltacloud/helpers/conversion_helper.rb +39 -0
  49. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
  50. data/lib/deltacloud/helpers.rb +5 -0
  51. data/lib/deltacloud/method_serializer.rb +85 -0
  52. data/lib/deltacloud/models/base_model.rb +59 -0
  53. data/lib/deltacloud/models/blob.rb +26 -0
  54. data/lib/deltacloud/models/bucket.rb +24 -0
  55. data/lib/deltacloud/models/image.rb +27 -0
  56. data/lib/deltacloud/models/instance.rb +38 -0
  57. data/lib/deltacloud/models/instance_profile.rb +48 -0
  58. data/lib/deltacloud/models/key.rb +35 -0
  59. data/lib/deltacloud/models/realm.rb +26 -0
  60. data/lib/deltacloud/models/storage_snapshot.rb +27 -0
  61. data/lib/deltacloud/models/storage_volume.rb +28 -0
  62. data/lib/deltacloud/state_machine.rb +84 -0
  63. data/lib/deltacloud/validation.rb +70 -0
  64. data/lib/drivers.rb +51 -0
  65. data/lib/sinatra/accept_media_types.rb +128 -0
  66. data/lib/sinatra/lazy_auth.rb +56 -0
  67. data/lib/sinatra/rabbit.rb +279 -0
  68. data/lib/sinatra/respond_to.rb +238 -0
  69. data/lib/sinatra/static_assets.rb +83 -0
  70. data/lib/sinatra/url_for.rb +53 -0
  71. data/public/favicon.ico +0 -0
  72. data/public/images/grid.png +0 -0
  73. data/public/images/logo-wide.png +0 -0
  74. data/public/images/rails.png +0 -0
  75. data/public/images/topbar-bg.png +0 -0
  76. data/public/javascripts/application.js +32 -0
  77. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  78. data/public/stylesheets/compiled/application.css +613 -0
  79. data/public/stylesheets/compiled/ie.css +31 -0
  80. data/public/stylesheets/compiled/print.css +27 -0
  81. data/public/stylesheets/compiled/screen.css +456 -0
  82. data/server.rb +516 -0
  83. data/support/fedora/deltacloudd +68 -0
  84. data/support/fedora/rubygem-deltacloud-core.spec +91 -0
  85. data/tests/api_test.rb +37 -0
  86. data/tests/hardware_profiles_test.rb +120 -0
  87. data/tests/images_test.rb +111 -0
  88. data/tests/instance_states_test.rb +51 -0
  89. data/tests/instances_test.rb +222 -0
  90. data/tests/realms_test.rb +78 -0
  91. data/tests/url_for_test.rb +50 -0
  92. data/views/accounts/index.html.haml +11 -0
  93. data/views/accounts/show.html.haml +30 -0
  94. data/views/api/show.html.haml +15 -0
  95. data/views/api/show.xml.haml +5 -0
  96. data/views/blobs/show.html.haml +20 -0
  97. data/views/blobs/show.xml.haml +7 -0
  98. data/views/buckets/index.html.haml +33 -0
  99. data/views/buckets/index.xml.haml +10 -0
  100. data/views/buckets/new.html.haml +13 -0
  101. data/views/buckets/show.html.haml +19 -0
  102. data/views/buckets/show.xml.haml +8 -0
  103. data/views/docs/collection.html.haml +37 -0
  104. data/views/docs/collection.xml.haml +14 -0
  105. data/views/docs/index.html.haml +15 -0
  106. data/views/docs/index.xml.haml +5 -0
  107. data/views/docs/operation.html.haml +31 -0
  108. data/views/docs/operation.xml.haml +10 -0
  109. data/views/errors/auth_exception.html.haml +8 -0
  110. data/views/errors/auth_exception.xml.haml +2 -0
  111. data/views/errors/backend_error.html.haml +19 -0
  112. data/views/errors/backend_error.xml.haml +8 -0
  113. data/views/errors/not_found.html.haml +6 -0
  114. data/views/errors/not_found.xml.haml +2 -0
  115. data/views/errors/validation_failure.html.haml +11 -0
  116. data/views/errors/validation_failure.xml.haml +7 -0
  117. data/views/hardware_profiles/index.html.haml +25 -0
  118. data/views/hardware_profiles/index.xml.haml +4 -0
  119. data/views/hardware_profiles/show.html.haml +19 -0
  120. data/views/hardware_profiles/show.xml.haml +18 -0
  121. data/views/images/index.html.haml +30 -0
  122. data/views/images/index.xml.haml +8 -0
  123. data/views/images/show.html.haml +21 -0
  124. data/views/images/show.xml.haml +5 -0
  125. data/views/instance_states/show.html.haml +31 -0
  126. data/views/instance_states/show.png.erb +45 -0
  127. data/views/instance_states/show.xml.haml +8 -0
  128. data/views/instances/index.html.haml +30 -0
  129. data/views/instances/index.xml.haml +21 -0
  130. data/views/instances/new.html.haml +55 -0
  131. data/views/instances/show.html.haml +43 -0
  132. data/views/instances/show.xml.haml +49 -0
  133. data/views/keys/index.html.haml +26 -0
  134. data/views/keys/index.xml.haml +4 -0
  135. data/views/keys/new.html.haml +8 -0
  136. data/views/keys/show.html.haml +22 -0
  137. data/views/keys/show.xml.haml +20 -0
  138. data/views/layout.html.haml +26 -0
  139. data/views/realms/index.html.haml +29 -0
  140. data/views/realms/index.xml.haml +10 -0
  141. data/views/realms/show.html.haml +15 -0
  142. data/views/realms/show.xml.haml +9 -0
  143. data/views/root/index.html.haml +4 -0
  144. data/views/storage_snapshots/index.html.haml +20 -0
  145. data/views/storage_snapshots/index.xml.haml +9 -0
  146. data/views/storage_snapshots/show.html.haml +14 -0
  147. data/views/storage_snapshots/show.xml.haml +7 -0
  148. data/views/storage_volumes/index.html.haml +21 -0
  149. data/views/storage_volumes/index.xml.haml +23 -0
  150. data/views/storage_volumes/show.html.haml +20 -0
  151. data/views/storage_volumes/show.xml.haml +24 -0
  152. metadata +367 -0
data/COPYING ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
data/Rakefile ADDED
@@ -0,0 +1,106 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # Licensed to the Apache Software Foundation (ASF) under one or more
5
+ # contributor license agreements. See the NOTICE file distributed with
6
+ # this work for additional information regarding copyright ownership. The
7
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance with the
9
+ # License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ # License for the specific language governing permissions and limitations
17
+ # under the License.
18
+
19
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
20
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
21
+
22
+ require 'rake'
23
+ require 'rake/testtask'
24
+ require 'rake/gempackagetask'
25
+
26
+ begin
27
+ require 'ci/reporter/rake/test_unit'
28
+ rescue LoadError
29
+ end
30
+
31
+ desc "Run basic unit tests"
32
+ Rake::TestTask.new("test") { |t|
33
+ t.test_files = FileList[
34
+ 'tests/api_test.rb',
35
+ 'tests/hardware_profiles_test.rb',
36
+ 'tests/realms_test.rb',
37
+ 'tests/images_test.rb',
38
+ 'tests/instances_test.rb',
39
+ 'tests/instance_states_test.rb',
40
+ 'tests/url_for_test.rb'
41
+ ]
42
+ t.verbose = true
43
+ t.warning = false
44
+ }
45
+
46
+ begin
47
+ require 'yard'
48
+ YARD::Rake::YardocTask.new do |t|
49
+ t.files = ['lib/**/*.rb', '*.rb'] # optional
50
+ end
51
+ rescue LoadError
52
+ end
53
+
54
+ @specs = ['ruby', 'java'].inject({}) do |hash, spec_platform|
55
+ $platform = spec_platform
56
+ hash.update(spec_platform => Gem::Specification.load('deltacloud-core.gemspec'))
57
+ end
58
+
59
+ @specs.values.each do |spec|
60
+ Rake::GemPackageTask.new(spec) do |pkg|
61
+ pkg.need_tar = true
62
+ end
63
+ end
64
+
65
+ desc "Install API"
66
+ task :install, [:install_dir, :bin_dir] do |t, args|
67
+
68
+ require 'fileutils'
69
+ require 'pp'
70
+
71
+ files = FileList[
72
+ Dir["config/**/**"],
73
+ Dir["features/**/**"],
74
+ Dir["lib/**/**"],
75
+ Dir["public/**/**"],
76
+ Dir["views/**/**"],
77
+ "config.ru",
78
+ "COPYING",
79
+ "README",
80
+ "*.rb"
81
+ ]
82
+
83
+ INSTALL_DIR=args.install_dir || "/usr/local/share/deltacloud-core"
84
+ BIN_DIR=args.bin_dir || "/usr/local/bin"
85
+
86
+ exit(1) unless FileUtils.mkdir_p(INSTALL_DIR)
87
+ exit(1) unless FileUtils.mkdir_p(BIN_DIR)
88
+
89
+ files.each do |f|
90
+ install_path = "#{INSTALL_DIR}/#{File.dirname(f)}"
91
+ unless File.directory?(install_path)
92
+ FileUtils.mkdir_p(install_path, :mode => 0755, :verbose => true)
93
+ end
94
+ next if File.directory?(f)
95
+ FileUtils.install(f, "#{INSTALL_DIR}/#{File.dirname(f)}", :verbose => true)
96
+ end
97
+
98
+ FileUtils.install('bin/deltacloudd', BIN_DIR, :verbose => true, :mode => 0755)
99
+ end
100
+
101
+ desc "Uninstall API"
102
+ task :uninstall do
103
+ require 'fileutils'
104
+ INSTALL_DIR="/usr/share/deltacloud-core"
105
+ FileUtils.rm_rf(INSTALL_DIR)
106
+ end
data/bin/deltacloudd ADDED
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'optparse'
5
+
6
+ options = {
7
+ :env => 'development'
8
+ }
9
+ optparse = OptionParser.new do |opts|
10
+
11
+ opts.banner = <<BANNER
12
+ Usage:
13
+ deltacloudd -i <driver> [options]
14
+
15
+ Options:
16
+ BANNER
17
+ opts.on( '-i', '--driver DRIVER', 'Driver to use') do |driver|
18
+ ENV["API_DRIVER"] = driver
19
+ end
20
+ opts.on( '-r', '--hostname HOSTNAME',
21
+ 'Bind to HOST address (default: localhost)') do |host|
22
+ ENV["API_HOST"] = host
23
+ end
24
+ opts.on( '-p', '--port PORT', 'Use PORT (default: 3001)') do |port|
25
+ ENV["API_PORT"] = port
26
+ end
27
+ opts.on( '-e', '--env ENV', 'Environment (default: "development")') { |env| options[:env] = env }
28
+ opts.on( '-h', '--help', '') { options[:help] = true }
29
+ end
30
+
31
+ optparse.parse!
32
+
33
+ if options[:help]
34
+ puts optparse
35
+ exit(0)
36
+ end
37
+
38
+ unless ENV["API_DRIVER"]
39
+ puts "You need to specify a driver to use (-i <driver>)"
40
+ exit(1)
41
+ end
42
+
43
+ ENV["API_HOST"] = "localhost" unless ENV["API_HOST"]
44
+ ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
45
+
46
+ puts "Starting Deltacloud API :: #{ENV["API_DRIVER"]} :: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
47
+ puts
48
+
49
+ dirname="#{File.dirname(__FILE__)}/.."
50
+ platform = RUBY_PLATFORM[/java/] || 'ruby'
51
+
52
+ if platform == 'java'
53
+ require 'rack'
54
+
55
+ # We can't chdir with webrick so add our root directory
56
+ # onto the load path
57
+ $: << dirname
58
+
59
+ # Read in config.ru and convert it to an instance of Rack::Builder
60
+ cfgfile = File.read(File.join(dirname, 'config.ru'))
61
+ inner_app = eval("Rack::Builder.new {(" + cfgfile + "\n )}.to_app",
62
+ nil, 'config.ru')
63
+
64
+ app = Rack::Builder.new {
65
+ use Rack::CommonLogger # apache-like logging
66
+ use Rack::Reloader if options[:env] == "development"
67
+ set :root, dirname # Set Sinatra root since we can't chdir to ../
68
+ run inner_app
69
+ }.to_app
70
+
71
+ # There's a bug with string ports on JRuby so convert to int
72
+ # http://jira.codehaus.org/browse/JRUBY-4868
73
+ port = ENV["API_PORT"].to_i
74
+
75
+ puts "=> Ctrl-C to shutdown server"
76
+ Rack::Handler::WEBrick.run(app,
77
+ :Host => ENV["API_HOST"],
78
+ :Port => port,
79
+ :AccessLog => [])
80
+ else
81
+ require 'thin'
82
+
83
+ argv_opts = ARGV.clone
84
+ argv_opts << ['start'] unless Thin::Runner.commands.include?(options[0])
85
+ argv_opts << ['--address', ENV["API_HOST"] ]
86
+ argv_opts << ['--port', ENV["API_PORT"] ]
87
+ argv_opts << ['--rackup', 'config.ru' ]
88
+ argv_opts << ['--chdir', dirname ]
89
+ argv_opts << ['-e', options[:env] ]
90
+ argv_opts << ['--threaded', '-D', '--stats', '/stats']
91
+
92
+ argv_opts.flatten!
93
+
94
+ if options[:env] == "development"
95
+ use_rerun = false
96
+ begin
97
+ require "rerun"
98
+ use_rerun = true
99
+ rescue
100
+ # Do nothing
101
+ end
102
+ end
103
+
104
+ if use_rerun
105
+ argv_opts.unshift "thin"
106
+ command = argv_opts.join(" ")
107
+ topdir = File::expand_path(File::join(File::dirname(__FILE__), ".."))
108
+ rerun = Rerun::Runner.new(command, :dir => topdir)
109
+ rerun.start
110
+ rerun.join
111
+ else
112
+ thin = Thin::Runner.new(argv_opts)
113
+
114
+ begin
115
+ thin.run!
116
+ rescue Exception => e
117
+ puts "ERROR: #{e.message}"
118
+ end
119
+ end
120
+ end
data/config.ru ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+
4
+ require 'server.rb'
5
+ run Sinatra::Application
data/deltacloud.rb ADDED
@@ -0,0 +1,20 @@
1
+ # Add ./lib into load path
2
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
3
+
4
+ require 'deltacloud/base_driver'
5
+ require 'deltacloud/hardware_profile'
6
+ require 'deltacloud/state_machine'
7
+
8
+ require 'deltacloud/models/base_model'
9
+ require 'deltacloud/models/realm'
10
+ require 'deltacloud/models/image'
11
+ require 'deltacloud/models/instance'
12
+ require 'deltacloud/models/key'
13
+ require 'deltacloud/models/instance_profile'
14
+ require 'deltacloud/models/storage_snapshot'
15
+ require 'deltacloud/models/storage_volume'
16
+ require 'deltacloud/models/bucket'
17
+ require 'deltacloud/models/blob'
18
+
19
+ require 'deltacloud/validation'
20
+ require 'deltacloud/helpers'
@@ -0,0 +1,259 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # Licensed to the Apache Software Foundation (ASF) under one or more
5
+ # contributor license agreements. See the NOTICE file distributed with
6
+ # this work for additional information regarding copyright ownership. The
7
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance with the
9
+ # License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ # License for the specific language governing permissions and limitations
17
+ # under the License.
18
+
19
+ module Deltacloud
20
+
21
+ class AuthException < Exception
22
+ end
23
+
24
+ class BackendError < StandardError
25
+ attr_reader :code, :cause, :details
26
+ def initialize(code, cause, message, details)
27
+ super(message)
28
+ @code = code
29
+ @cause = cause
30
+ @details = details
31
+ end
32
+ end
33
+
34
+ class BackendFeatureUnsupported < StandardError
35
+ attr_reader :code, :cause, :details
36
+ def initialize(code, cause, message, details)
37
+ super(message)
38
+ @code = code
39
+ @cause = cause
40
+ @details = details
41
+ end
42
+ end
43
+
44
+ class BaseDriver
45
+
46
+ def self.define_hardware_profile(name,&block)
47
+ @hardware_profiles ||= []
48
+ hw_profile = @hardware_profiles.find{|e| e.name == name}
49
+ return if hw_profile
50
+ hw_profile = ::Deltacloud::HardwareProfile.new( name, &block )
51
+ @hardware_profiles << hw_profile
52
+ hw_params = hw_profile.params
53
+ unless hw_params.empty?
54
+ feature :instances, :hardware_profiles do
55
+ decl.operation(:create) { add_params(hw_params) }
56
+ end
57
+ end
58
+ end
59
+
60
+ def self.hardware_profiles
61
+ @hardware_profiles ||= []
62
+ @hardware_profiles
63
+ end
64
+
65
+ def hardware_profiles(credentials, opts = nil)
66
+ results = self.class.hardware_profiles
67
+ filter_hardware_profiles(results, opts)
68
+ end
69
+
70
+ def hardware_profile(credentials, name)
71
+ hardware_profiles(credentials, :name => name).first
72
+ end
73
+
74
+ def filter_hardware_profiles(profiles, opts)
75
+ if opts
76
+ if v = opts[:architecture]
77
+ profiles = profiles.select { |hwp| hwp.include?(:architecture, v) }
78
+ end
79
+ if v = opts[:name]
80
+ profiles = profiles.select { |hwp| hwp.name == v }
81
+ end
82
+ end
83
+ profiles
84
+ end
85
+
86
+ def find_hardware_profile(credentials, name, image_id)
87
+ hwp = nil
88
+ if name
89
+ unless hwp = hardware_profiles(credentials, :name => name).first
90
+ raise BackendError.new(400, "bad-hardware-profile-name",
91
+ "Hardware profile '#{name}' does not exist", nil)
92
+ end
93
+ else
94
+ unless image = image(credentials, :id=>image_id)
95
+ raise BackendError.new(400, "bad-image-id",
96
+ "Image with ID '#{image_id}' does not exist", nil)
97
+ end
98
+ hwp = hardware_profiles(credentials,
99
+ :architecture=>image.architecture).first
100
+ end
101
+ return hwp
102
+ end
103
+
104
+ def self.define_instance_states(&block)
105
+ machine = ::Deltacloud::StateMachine.new(&block)
106
+ @instance_state_machine = machine
107
+ end
108
+
109
+ def self.instance_state_machine
110
+ @instance_state_machine
111
+ end
112
+
113
+ def instance_state_machine
114
+ self.class.instance_state_machine
115
+ end
116
+
117
+ def instance_actions_for(state)
118
+ actions = []
119
+ state_key = state.downcase.to_sym
120
+ states = instance_state_machine.states()
121
+ current_state = states.find{|e| e.name == state.underscore.to_sym }
122
+ if ( current_state )
123
+ actions = current_state.transitions.collect{|e|e.action}
124
+ actions.reject!{|e| e.nil?}
125
+ end
126
+ actions
127
+ end
128
+
129
+ def realm(credentials, opts)
130
+ realms = realms(credentials, opts)
131
+ return realms.first unless realms.empty?
132
+ nil
133
+ end
134
+
135
+ def realms(credentials, opts=nil)
136
+ []
137
+ end
138
+
139
+ def image(credentials, opts)
140
+ images = images(credentials, opts)
141
+ return images.first unless images.empty?
142
+ nil
143
+ end
144
+
145
+ def images(credentials, ops)
146
+ []
147
+ end
148
+
149
+ def instance(credentials, opts)
150
+ instances = instances(credentials, opts)
151
+ return instances.first unless instances.empty?
152
+ nil
153
+ end
154
+
155
+ def instances(credentials, ops)
156
+ []
157
+ end
158
+
159
+ def create_instance(credentials, image_id, opts)
160
+ end
161
+ def start_instance(credentials, id)
162
+ end
163
+ def stop_instance(credentials, id)
164
+ end
165
+ def reboot_instance(credentials, id)
166
+ end
167
+
168
+ def storage_volume(credentials, opts)
169
+ volumes = storage_volumes(credentials, opts)
170
+ return volumes.first unless volumes.empty?
171
+ nil
172
+ end
173
+
174
+ def storage_volumes(credentials, ops)
175
+ []
176
+ end
177
+
178
+ def storage_snapshot(credentials, opts)
179
+ snapshots = storage_snapshots(credentials, opts)
180
+ return snapshots.first unless snapshots.empty?
181
+ nil
182
+ end
183
+
184
+ def storage_snapshots(credentials, ops)
185
+ []
186
+ end
187
+
188
+ def buckets(credentials, opts = nil)
189
+ #list of buckets belonging to account
190
+ []
191
+ end
192
+
193
+ def bucket(credentials, opts = nil)
194
+ #list of objects within bucket
195
+ list = buckets(credentials, opts)
196
+ return list.first unless list.empty?
197
+ nil
198
+ end
199
+
200
+ def create_bucket(credentials, name, opts=nil)
201
+ end
202
+
203
+ def delete_bucket(credentials, name, opts=nil)
204
+ end
205
+
206
+ def blobs(credentials, opts = nil)
207
+ []
208
+ end
209
+
210
+ def blob(credentials, opts = nil)
211
+ list = blobs(credentials, opts)
212
+ return list.first unless list.empty?
213
+ end
214
+
215
+ def blob_data(credentials, bucket_id, blob_id, opts)
216
+ end
217
+
218
+ def filter_on(collection, attribute, opts)
219
+ return collection if opts.nil?
220
+ return collection if opts[attribute].nil?
221
+ filter = opts[attribute]
222
+ if ( filter.is_a?( Array ) )
223
+ return collection.select{|e| filter.include?( e.send(attribute) ) }
224
+ else
225
+ return collection.select{|e| filter == e.send(attribute) }
226
+ end
227
+ end
228
+
229
+ def supported_collections
230
+ DEFAULT_COLLECTIONS
231
+ end
232
+
233
+ def has_collection?(collection)
234
+ return true if self.supported_collections.include?(collection)
235
+ return false
236
+ end
237
+
238
+ def catched_exceptions_list
239
+ { :error => [], :auth => [], :glob => [] }
240
+ end
241
+
242
+ def safely(&block)
243
+ begin
244
+ block.call
245
+ rescue *catched_exceptions_list[:error] => e
246
+ raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace)
247
+ rescue *catched_exceptions_list[:auth] => e
248
+ raise Deltacloud::AuthException.new
249
+ rescue => e
250
+ catched_exceptions_list[:glob].each do |ex|
251
+ raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace) if e.class.name =~ ex
252
+ end
253
+ raise e
254
+ end
255
+ end
256
+
257
+ end
258
+
259
+ end