deltacloud-core 1.1.1 → 1.1.2

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 (220) hide show
  1. data/Rakefile +40 -28
  2. data/bin/deltacloud-db-upgrade +24 -0
  3. data/bin/deltacloudd +20 -9
  4. data/config.ru +12 -53
  5. data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
  6. data/deltacloud-core.gemspec +11 -5
  7. data/lib/cimi/collections.rb +4 -31
  8. data/lib/cimi/collections/address_templates.rb +2 -5
  9. data/lib/cimi/collections/addresses.rb +2 -5
  10. data/lib/cimi/collections/base.rb +18 -6
  11. data/lib/cimi/collections/credentials.rb +2 -5
  12. data/lib/cimi/collections/machine_images.rb +2 -1
  13. data/lib/cimi/collections/machine_templates.rb +2 -5
  14. data/lib/cimi/collections/machines.rb +6 -9
  15. data/lib/cimi/collections/network_ports.rb +3 -3
  16. data/lib/cimi/collections/networks.rb +5 -8
  17. data/lib/cimi/collections/system_templates.rb +72 -0
  18. data/lib/cimi/collections/systems.rb +194 -0
  19. data/lib/cimi/collections/volume_configurations.rb +1 -1
  20. data/lib/cimi/collections/volume_images.rb +2 -1
  21. data/lib/cimi/collections/volume_templates.rb +3 -2
  22. data/lib/cimi/collections/volumes.rb +2 -2
  23. data/lib/cimi/dependencies.rb +0 -2
  24. data/lib/cimi/helpers/cimi_helper.rb +12 -57
  25. data/lib/cimi/helpers/database_helper.rb +0 -4
  26. data/lib/cimi/models.rb +25 -14
  27. data/lib/cimi/models/address.rb +4 -31
  28. data/lib/cimi/models/address_create.rb +51 -0
  29. data/lib/cimi/models/address_template.rb +8 -52
  30. data/lib/cimi/models/address_template_create.rb +44 -0
  31. data/lib/cimi/models/base.rb +44 -6
  32. data/lib/cimi/models/cloud_entry_point.rb +1 -1
  33. data/lib/cimi/models/credential.rb +1 -1
  34. data/lib/cimi/models/credential_create.rb +46 -0
  35. data/lib/cimi/models/credential_template.rb +24 -0
  36. data/lib/cimi/models/machine.rb +1 -71
  37. data/lib/cimi/models/machine_configuration.rb +3 -3
  38. data/lib/cimi/models/machine_create.rb +49 -0
  39. data/lib/cimi/models/machine_image.rb +2 -25
  40. data/lib/cimi/models/machine_image_create.rb +41 -0
  41. data/lib/cimi/models/machine_template.rb +14 -34
  42. data/lib/cimi/models/machine_template_create.rb +33 -0
  43. data/lib/cimi/models/network.rb +0 -38
  44. data/lib/cimi/models/network_create.rb +43 -0
  45. data/lib/cimi/models/network_port.rb +17 -17
  46. data/lib/cimi/models/network_template.rb +2 -3
  47. data/lib/cimi/models/resource.rb +22 -3
  48. data/lib/cimi/models/schema.rb +94 -8
  49. data/lib/cimi/models/system.rb +67 -0
  50. data/lib/cimi/models/system_template.rb +63 -0
  51. data/lib/cimi/models/volume.rb +2 -42
  52. data/lib/cimi/models/volume_configuration.rb +4 -4
  53. data/lib/cimi/models/volume_create.rb +58 -0
  54. data/lib/cimi/models/volume_image.rb +8 -17
  55. data/lib/cimi/models/volume_image_create.rb +47 -0
  56. data/lib/cimi/models/volume_template.rb +6 -19
  57. data/lib/cimi/models/volume_template_create.rb +33 -0
  58. data/lib/db.rb +14 -22
  59. data/lib/db/volume_template.rb +1 -1
  60. data/lib/deltacloud/api.rb +6 -5
  61. data/lib/deltacloud/collections.rb +4 -27
  62. data/lib/deltacloud/collections/base.rb +4 -0
  63. data/lib/deltacloud/collections/images.rb +1 -1
  64. data/lib/deltacloud/collections/instances.rb +2 -2
  65. data/lib/deltacloud/core_ext/array.rb +1 -0
  66. data/lib/deltacloud/core_ext/integer.rb +13 -9
  67. data/lib/deltacloud/core_ext/string.rb +45 -28
  68. data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
  69. data/lib/deltacloud/drivers/base_driver.rb +45 -16
  70. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
  71. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
  72. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
  73. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
  74. data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
  75. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
  76. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
  77. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
  78. data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
  79. data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
  80. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
  81. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
  82. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
  83. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
  84. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
  85. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
  86. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
  87. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
  88. data/lib/deltacloud/helpers/collection_helper.rb +106 -0
  89. data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
  90. data/lib/deltacloud/models/address.rb +19 -17
  91. data/lib/deltacloud/models/base_model.rb +29 -26
  92. data/lib/deltacloud/models/blob.rb +22 -20
  93. data/lib/deltacloud/models/bucket.rb +21 -16
  94. data/lib/deltacloud/models/firewall.rb +18 -16
  95. data/lib/deltacloud/models/firewall_rule.rb +22 -20
  96. data/lib/deltacloud/models/image.rb +29 -28
  97. data/lib/deltacloud/models/instance.rb +92 -94
  98. data/lib/deltacloud/models/instance_address.rb +42 -40
  99. data/lib/deltacloud/models/instance_profile.rb +28 -26
  100. data/lib/deltacloud/models/key.rb +47 -45
  101. data/lib/deltacloud/models/load_balancer.rb +32 -31
  102. data/lib/deltacloud/models/metric.rb +76 -29
  103. data/lib/deltacloud/models/provider.rb +15 -13
  104. data/lib/deltacloud/models/realm.rb +15 -21
  105. data/lib/deltacloud/models/storage_snapshot.rb +23 -19
  106. data/lib/deltacloud/models/storage_volume.rb +35 -34
  107. data/lib/deltacloud/version.rb +1 -1
  108. data/lib/deltacloud_rack.rb +22 -0
  109. data/lib/initialize.rb +28 -0
  110. data/lib/initializers/database_initialize.rb +76 -0
  111. data/lib/initializers/frontend_initialize.rb +42 -0
  112. data/lib/initializers/mock_initialize.rb +33 -0
  113. data/lib/sinatra/rack_logger.rb +35 -24
  114. data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
  115. data/tests/cimi/collections/machine_images_test.rb +2 -2
  116. data/tests/cimi/collections/machine_templates_test.rb +75 -0
  117. data/tests/cimi/collections/machines_test.rb +2 -2
  118. data/tests/cimi/collections/system_templates_test.rb +41 -0
  119. data/tests/cimi/collections/systems_test.rb +50 -0
  120. data/tests/cimi/db/database_helper_test.rb +17 -25
  121. data/tests/cimi/db/db_helper.rb +1 -12
  122. data/tests/cimi/db/entity_test.rb +7 -8
  123. data/tests/cimi/model/machine_create_spec.rb +44 -0
  124. data/tests/cimi/model/machine_template_spec.rb +29 -0
  125. data/tests/cimi/model/resource_spec.rb +40 -0
  126. data/tests/cimi/model/schema_spec.rb +37 -0
  127. data/tests/cimi/spec_helper.rb +3 -0
  128. data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
  129. data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
  130. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
  131. data/tests/deltacloud/collections/images_collection_test.rb +2 -2
  132. data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
  133. data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
  134. data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
  135. data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
  136. data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
  137. data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
  138. data/tests/deltacloud/collections_test.rb +5 -5
  139. data/tests/deltacloud/common.rb +2 -13
  140. data/tests/deltacloud/launcher_test.rb +3 -3
  141. data/tests/deltacloud/rack_test.rb +2 -2
  142. data/tests/deltacloud/server_test.rb +1 -1
  143. data/tests/drivers/base/base_driver_test.rb +5 -5
  144. data/tests/drivers/base/common.rb +2 -12
  145. data/tests/drivers/ec2/buckets_test.rb +1 -1
  146. data/tests/drivers/ec2/images_test.rb +2 -2
  147. data/tests/drivers/ec2/instance_test.rb +6 -6
  148. data/tests/drivers/ec2/keys_test.rb +3 -3
  149. data/tests/drivers/ec2/realms_test.rb +2 -2
  150. data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
  151. data/tests/drivers/fgcp/common.rb +32 -0
  152. data/tests/drivers/fgcp/firewall_test.rb +70 -0
  153. data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
  154. data/tests/drivers/fgcp/images_test.rb +46 -0
  155. data/tests/drivers/fgcp/provider_test.rb +27 -0
  156. data/tests/drivers/fgcp/realms_test.rb +53 -0
  157. data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
  158. data/tests/drivers/gogrid/images_test.rb +2 -2
  159. data/tests/drivers/gogrid/instances_test.rb +2 -2
  160. data/tests/drivers/gogrid/realms_test.rb +2 -2
  161. data/tests/drivers/mock/images_test.rb +4 -4
  162. data/tests/drivers/mock/instances_test.rb +9 -9
  163. data/tests/drivers/mock/keys_test.rb +3 -3
  164. data/tests/drivers/mock/realms_test.rb +2 -2
  165. data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
  166. data/tests/drivers/mock/storage_volumes_test.rb +4 -4
  167. data/tests/drivers/models/instance_test.rb +2 -2
  168. data/tests/drivers/openstack/images_test.rb +2 -2
  169. data/tests/drivers/openstack/instances_test.rb +2 -3
  170. data/tests/drivers/openstack/keys_test.rb +1 -1
  171. data/tests/drivers/openstack/realms_test.rb +2 -11
  172. data/tests/drivers/rhevm/common.rb +33 -12
  173. data/tests/drivers/rhevm/images_test.rb +20 -12
  174. data/tests/drivers/rhevm/instance_test.rb +62 -46
  175. data/tests/drivers/rhevm/provider_test.rb +12 -6
  176. data/tests/drivers/rhevm/realms_test.rb +15 -9
  177. data/tests/ec2/query_parser_test.rb +1 -1
  178. data/tests/test_helper.rb +68 -12
  179. data/views/addresses/show.html.haml +1 -1
  180. data/views/buckets/show.html.haml +1 -1
  181. data/views/errors/{500.html.haml → common.html.haml} +0 -0
  182. data/views/errors/common.xml.haml +17 -0
  183. data/views/firewalls/index.xml.haml +2 -2
  184. data/views/firewalls/new.html.haml +2 -2
  185. data/views/images/show.html.haml +1 -1
  186. data/views/instances/run_command.html.haml +1 -1
  187. data/views/instances/show.html.haml +3 -3
  188. data/views/keys/index.html.haml +1 -0
  189. data/views/keys/show.html.haml +8 -4
  190. data/views/keys/show.xml.haml +3 -2
  191. data/views/load_balancers/new.html.haml +1 -1
  192. data/views/load_balancers/show.html.haml +2 -2
  193. data/views/metrics/show.html.haml +1 -1
  194. data/views/realms/index.html.haml +0 -2
  195. data/views/realms/show.html.haml +0 -4
  196. data/views/realms/show.xml.haml +0 -3
  197. data/views/storage_snapshots/index.html.haml +1 -1
  198. data/views/storage_snapshots/new.html.haml +1 -1
  199. data/views/storage_volumes/new.html.haml +2 -2
  200. data/views/storage_volumes/show.html.haml +3 -3
  201. metadata +90 -41
  202. data/views/errors/400.html.haml +0 -41
  203. data/views/errors/400.xml.haml +0 -3
  204. data/views/errors/401.html.haml +0 -26
  205. data/views/errors/401.xml.haml +0 -3
  206. data/views/errors/403.html.haml +0 -42
  207. data/views/errors/403.xml.haml +0 -9
  208. data/views/errors/404.html.haml +0 -28
  209. data/views/errors/404.xml.haml +0 -3
  210. data/views/errors/405.html.haml +0 -29
  211. data/views/errors/405.xml.haml +0 -5
  212. data/views/errors/409.html.haml +0 -47
  213. data/views/errors/409.xml.haml +0 -11
  214. data/views/errors/500.xml.haml +0 -13
  215. data/views/errors/501.html.haml +0 -44
  216. data/views/errors/501.xml.haml +0 -1
  217. data/views/errors/502.html.haml +0 -44
  218. data/views/errors/502.xml.haml +0 -1
  219. data/views/errors/504.html.haml +0 -43
  220. data/views/errors/504.xml.haml +0 -1
data/Rakefile CHANGED
@@ -29,6 +29,8 @@ rescue LoadError
29
29
  exit(1)
30
30
  end
31
31
 
32
+ require 'require_relative' if RUBY_VERSION < '1.9'
33
+
32
34
  $top_srcdir = File.dirname(__FILE__)
33
35
  $:.unshift File.join($top_srcdir, 'lib')
34
36
 
@@ -46,40 +48,44 @@ Gem::PackageTask.new(spec) do |pkg|
46
48
  pkg.need_tar = true
47
49
  end
48
50
 
51
+ # Not meant for enduser consumption; make sure we run our initializers
52
+ task :initialize do
53
+ require_relative 'lib/initialize.rb'
54
+ end
55
+
56
+ namespace :db do
57
+ desc 'Execute the database migrations'
58
+ task 'migrate' do
59
+ load File.join(File.dirname(__FILE__), 'bin', 'deltacloud-db-upgrade')
60
+ end
61
+ end
62
+
49
63
  namespace :mock do
50
64
  namespace :fixtures do
51
65
  desc "Setup Mock driver fixtures"
52
- task 'setup' do
53
- if ENV["DELTACLOUD_MOCK_STORAGE"]
54
- storage_root = ENV["DELTACLOUD_MOCK_STORAGE"]
55
- elsif ENV["USER"]
56
- storage_root = File::join("/var/tmp", "deltacloud-mock-#{ENV["USER"]}")
57
- else
58
- raise "Please set either the DELTACLOUD_MOCK_STORAGE or USER environment variable"
59
- end
60
- data = Dir::glob(File::join(File::dirname(__FILE__), "lib", "deltacloud", "drivers", "mock", "data", "*"))
61
- FileUtils::mkdir_p(storage_root, :verbose => true)
62
- FileUtils::cp_r(data, storage_root, :verbose => true)
66
+ task 'setup' => :initialize do
67
+ srcdir = File::join(File::dirname(__FILE__), "lib", "deltacloud", "drivers", "mock", "data")
68
+ data = Dir::glob(File::join(srcdir, "*"))
69
+ srcdir.gsub!(/^#{ENV["PWD"]}/, ".")
70
+ srcdir.gsub!(/^#{ENV["HOME"]}/, "~")
71
+ puts "Copy mock data to #{MOCK_STORAGE_DIR}"
72
+ puts " (from #{srcdir})"
73
+ FileUtils::cp_r(data, MOCK_STORAGE_DIR, :verbose => false)
63
74
  end
64
75
 
65
76
  desc "Remove Mock driver fixtures"
66
- task 'clean' do
67
- if ENV["DELTACLOUD_MOCK_STORAGE"]
68
- storage_root = ENV["DELTACLOUD_MOCK_STORAGE"]
69
- elsif ENV["USER"]
70
- storage_root = File::join("/var/tmp", "deltacloud-mock-#{ENV["USER"]}")
71
- else
72
- raise "Please set either the DELTACLOUD_MOCK_STORAGE or USER environment variable"
73
- end
74
- FileUtils::rm_rf(storage_root, :verbose => true)
77
+ task 'clean' => :initialize do
78
+ puts "Remove mock data in #{MOCK_STORAGE_DIR}"
79
+ files = Dir::glob(File::join(MOCK_STORAGE_DIR, "*"))
80
+ FileUtils::rm_rf(files, :verbose => false)
75
81
  end
76
82
 
77
83
  desc "Reset Mock driver fixtures"
78
- task 'reset' do
79
- Rake::Task["mock:fixtures:clean"].reenable
80
- Rake::Task["mock:fixtures:clean"].invoke
81
- Rake::Task["mock:fixtures:setup"].reenable
82
- Rake::Task["mock:fixtures:setup"].invoke
84
+ task 'reset' => :initialize do
85
+ ["mock:fixtures:clean", "mock:fixtures:setup"].each do |t|
86
+ Rake::Task[t].reenable
87
+ Rake::Task[t].invoke
88
+ end
83
89
  end
84
90
 
85
91
  end
@@ -91,7 +97,8 @@ desc "List the routes defined by Rabbit"
91
97
  desc "Print all routes defined for #{frontend.to_s.capitalize}"
92
98
  task :routes do
93
99
  ENV['API_FRONTEND'] = frontend.to_s
94
- load File.join(File.dirname(__FILE__), 'config.ru')
100
+ require_relative './lib/initialize'
101
+ Deltacloud.generate_routes
95
102
  f_class = (frontend == :cimi) ? CIMI : Deltacloud
96
103
  f_class.collections.each do |c|
97
104
  puts "\033[1;32;m#{c.name}\33[0m"
@@ -132,9 +139,9 @@ end
132
139
  # need to investigate in future.
133
140
  #
134
141
  if RUBY_PLATFORM == 'java'
135
- DRIVERS = [:mock, :ec2, :rhevm, :gogrid, :openstack]
142
+ DRIVERS = [:mock, :ec2, :rhevm, :gogrid, :openstack, :fgcp]
136
143
  else
137
- DRIVERS = [:mock, :ec2, :rhevm, :google, :gogrid, :openstack]
144
+ DRIVERS = [:mock, :ec2, :rhevm, :google, :gogrid, :openstack, :fgcp]
138
145
  end
139
146
 
140
147
  desc 'Run all tests'
@@ -149,6 +156,11 @@ task :test do
149
156
  puts "\n[ \033[1;37;mrake test:cimi\33[0m ]\n"
150
157
  Rake::Task["test:cimi"].invoke
151
158
  DRIVERS.each do |driver|
159
+ #
160
+ # FIXME: Skip FGCP tests under jRuby as jRuby openssl lacks
161
+ # the OpenSSL::PKCS12::PKCS12Error class
162
+ #
163
+ next if RUBY_PLATFORM == 'java' and driver == :fgcp
152
164
  puts "\n[ \033[1;37;mrake drivers:#{driver}\33[0m ]\n"
153
165
  Rake::Task["test:drivers:#{driver}"].invoke
154
166
  end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # Licensed to the Apache Software Foundation (ASF) under one or more
3
+ # contributor license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright ownership. The
5
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance with the
7
+ # License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations
15
+ # under the License.
16
+
17
+ require 'rubygems'
18
+ require 'require_relative' if RUBY_VERSION < '1.9'
19
+
20
+ # Force DB upgrade
21
+ ENV['DB_UPGRADE'] = 'true'
22
+
23
+ require_relative './../lib/initializers/mock_initialize'
24
+ require_relative './../lib/initializers/database_initialize'
@@ -178,7 +178,6 @@ if !options[:daemon] || options[:daemon] && !have_thin
178
178
  msg << ":: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/#{api_uri}"
179
179
  end
180
180
  puts msg
181
- puts
182
181
  end
183
182
 
184
183
  if ENV['API_USER'] && ENV['API_PASSWORD']
@@ -192,11 +191,11 @@ unless have_thin
192
191
 
193
192
  puts "To start Deltacloud as a daemon, install 'thin' (gem install thin)\n\n" if options[:daemon]
194
193
 
194
+ port = ENV["API_PORT"].to_i
195
195
  # Read in config.ru and convert it to an instance of Rack::Builder
196
196
  cfgfile = File.read(File.join($top_srcdir, 'config.ru'))
197
197
  inner_app = eval("Rack::Builder.new {(" + cfgfile + "\n )}.to_app",
198
198
  nil, 'config.ru')
199
-
200
199
  app = Rack::Builder.new {
201
200
  use Rack::CommonLogger # apache-like logging
202
201
  use Rack::Reloader #if options[:env] == "development"
@@ -208,11 +207,20 @@ unless have_thin
208
207
  port = ENV["API_PORT"].to_i
209
208
  puts "=> Ctrl-C to shutdown server"
210
209
  Dir::chdir($top_srcdir)
211
- Rack::Server::start(:app => app,
212
- :server => :webrick,
213
- :Host => ENV["API_HOST"],
214
- :Port => port,
215
- :AccessLog => [])
210
+
211
+ if RUBY_PLATFORM == 'java'
212
+ require 'puma'
213
+ events = Puma::Events.new STDOUT, STDERR
214
+ server = Puma::Server.new app, events
215
+ server.add_tcp_listener ENV['API_HOST'], port
216
+ server.run(false)
217
+ else
218
+ Rack::Server::start(:app => app,
219
+ :Host => ENV["API_HOST"],
220
+ :Port => port,
221
+ :server => 'webrick',
222
+ :AccessLog => [])
223
+ end
216
224
  else
217
225
  argv_opts = ARGV.clone
218
226
  argv_opts << ['start'] unless Thin::Runner.commands.include?(options[0])
@@ -231,7 +239,9 @@ else
231
239
  argv_opts << [ "--daemonize", "--user", options[:user] || 'nobody', "--tag", "deltacloud-#{ENV['API_DRIVER']}"]
232
240
  argv_opts << [ "--pid", options[:pid]] if options[:pid]
233
241
  argv_opts << [ "--group", options[:group] || 'nobody' ]
234
- argv_opts << [ "--log", File.join(options[:logdir], "#{ENV['API_DRIVER']}.log")]
242
+ unless ENV['API_LOG']
243
+ argv_opts << [ "--log", File.join(options[:logdir], "#{ENV['API_DRIVER']}.log")]
244
+ end
235
245
  end
236
246
  argv_opts.flatten!
237
247
 
@@ -240,7 +250,8 @@ else
240
250
  command = argv_opts.join(" ")
241
251
  Dir::chdir($top_srcdir)
242
252
  rerun = Rerun::Runner.new(command,
243
- :dir => File::join($top_srcdir, "lib"))
253
+ :dir => File::join($top_srcdir, "lib"),
254
+ :pattern => "**/*")
244
255
  rerun.start
245
256
  rerun.join
246
257
  else
data/config.ru CHANGED
@@ -14,56 +14,7 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
- # The default URL prefix (where to mount Deltacloud API)
18
-
19
- # The default driver is 'mock'
20
- ENV['API_DRIVER'] ||= 'mock'
21
- ENV['API_FRONTEND'] ||= 'deltacloud'
22
-
23
- load File.join(File.dirname(__FILE__), 'lib', 'deltacloud_rack.rb')
24
-
25
- Deltacloud::configure do |server|
26
- server.root_url '/api'
27
- server.version Deltacloud::API_VERSION
28
- server.klass 'Deltacloud::API'
29
- end
30
-
31
- Deltacloud::configure(:cimi) do |server|
32
- server.root_url '/cimi'
33
- server.version Deltacloud::CIMI_API_VERSION
34
- server.klass 'CIMI::API'
35
- end
36
-
37
- Deltacloud::configure(:ec2) do |server|
38
- server.root_url '/ec2'
39
- server.version '2012-04-01'
40
- server.klass 'Deltacloud::EC2::API'
41
- end
42
-
43
- routes = {}
44
-
45
- def frontends
46
- ENV['API_FRONTEND'].split(',').size > 1 ?
47
- ENV['API_FRONTEND'].split(',') : [ENV['API_FRONTEND']]
48
- end
49
-
50
- # If user wants to launch multiple frontends withing a single instance of DC API
51
- # then require them and prepare the routes for Rack
52
- #
53
- # NOTE: The '/' will not be generated, since multiple frontends could have
54
- # different root_url's
55
- #
56
- frontends.each do |frontend|
57
- frontend = frontend.strip
58
- if Deltacloud[frontend.to_sym].nil?
59
- puts "ERROR: Unknown frontend (#{frontend}). Valid values are 'deltacloud,cimi,ec2'"
60
- exit(1)
61
- end
62
- Deltacloud[frontend.to_sym].require!
63
- routes.merge!({
64
- Deltacloud[frontend].root_url => Deltacloud[frontend].klass
65
- })
66
- end
17
+ load File.join(File.dirname(__FILE__), 'lib', 'initialize.rb')
67
18
 
68
19
  def static_dir_for(name)
69
20
  Rack::Directory.new( File.join(File.dirname(__FILE__), "public", name))
@@ -71,14 +22,22 @@ end
71
22
 
72
23
  # Mount static assets directories and index entrypoint
73
24
  #
74
- routes.merge!({
25
+ # The 'IndexApp' is small Sinatra::Base application that
26
+ # sits on the '/' route and display list of available frontends.
27
+ #
28
+ static_files = {
75
29
  '/' => Deltacloud::IndexApp,
76
30
  '/stylesheets' => static_dir_for('stylesheets'),
77
31
  '/javascripts' => static_dir_for('javascripts'),
78
32
  '/images' => static_dir_for('images')
79
- })
33
+ }
34
+
35
+ # The 'generate_routes_for' also require the frontend
36
+ # servers and all dependencies.
37
+ #
38
+ routes = Deltacloud.generate_routes
80
39
 
81
40
  run Rack::Builder.new {
82
41
  use Rack::MatrixParams
83
- run Rack::URLMap.new(routes)
42
+ run Rack::URLMap.new(routes.merge(static_files))
84
43
  }
@@ -0,0 +1,23 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. 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, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ Sequel.migration do
17
+ up do
18
+ add_column :entities, :realm, String
19
+ end
20
+ down do
21
+ drop_column :entities, :realm
22
+ end
23
+ end
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
48
48
  'lib/**/*.rb',
49
49
  'lib/**/*.yml',
50
50
  'lib/**/*.haml',
51
+ 'db/**/*.rb',
51
52
  'tests/**/*.rb',
52
53
  'views/**/*.haml',
53
54
  'views/instance_states/*.erb',
@@ -61,24 +62,29 @@ Gem::Specification.new do |s|
61
62
  ].map { |f| Dir[f] }.flatten
62
63
 
63
64
  s.bindir = 'bin'
64
- s.executables = 'deltacloudd'
65
+ s.executables = ['deltacloudd', 'deltacloud-db-upgrade']
65
66
  s.test_files= Dir.glob("tests/**/*_test.rb")
66
67
  s.extra_rdoc_files = Dir["LICENSE", "DISCLAIMER", "NOTICE"]
67
68
  s.required_ruby_version = '>= 1.8.6'
68
69
  s.has_rdoc = 'false'
69
70
  s.add_dependency('rake', '>= 0.8.7')
70
71
  s.add_dependency('haml', '>= 2.2.17')
71
- s.add_dependency('sinatra', '>= 1.3.0')
72
- s.add_dependency('sinatra-rabbit', '>= 1.0.11')
72
+ s.add_dependency('sinatra-rabbit', '>= 1.1.6')
73
73
  s.add_dependency('rack', '>= 1.0.0')
74
74
  s.add_dependency('rack-accept')
75
75
  s.add_dependency('json_pure', '>= 1.5.0')
76
76
  s.add_dependency('net-ssh', '>= 2.0.0')
77
77
  s.add_dependency('nokogiri', '>= 1.4.3')
78
78
  s.add_dependency('require_relative') if RUBY_VERSION < '1.9'
79
-
80
79
  s.add_dependency('sequel', '<= 3.42.0')
81
80
 
81
+ # FIXME: These dependencies are locked due to bugs that
82
+ # we will not address in this release.
83
+ #
84
+ s.add_dependency('tilt', '<=1.3.3')
85
+ s.add_dependency('sinatra', '<=1.3.5')
86
+
87
+
82
88
  if RUBY_PLATFORM == 'java'
83
89
  s.add_dependency('jdbc-sqlite3')
84
90
  else
@@ -102,7 +108,7 @@ Gem::Specification.new do |s|
102
108
 
103
109
  # Terremark Vcloud Express
104
110
  s.add_dependency('fog', '>= 1.4.0')
105
- s.add_dependency('excon', '>= 0.14.2' )
111
+ s.add_dependency('excon', '>= 0.14.2', '<0.17.0' )
106
112
 
107
113
  # Rhevm and Condor Cloud
108
114
  s.add_dependency('rest-client')
@@ -15,45 +15,18 @@
15
15
  # under the License.
16
16
 
17
17
  require_relative './collections/base'
18
+ require_relative './../deltacloud/helpers/collection_helper'
18
19
 
19
20
  module CIMI
20
21
 
21
- def self.collection_names
22
- @collections.map { |c| c.collection_name }
23
- end
24
-
25
- def self.collections
26
- @collections ||= []
27
- end
28
-
29
22
  module Collections
23
+ extend Deltacloud::CollectionHelper
30
24
 
31
- def self.collection(name)
32
- CIMI.collections.find { |c| c.collection_name == name }
33
- end
34
-
35
- def self.cimi_modules
36
- @cimi_modules ||= []
37
- end
38
-
39
- Dir[File.join(File::dirname(__FILE__), "collections", "*.rb")].each do |collection|
40
- base_collection_name = File.basename(collection).gsub('.rb', '')
41
- next if base_collection_name == 'base'
42
- require collection
43
- cimi_module_class = CIMI::Collections.const_get(base_collection_name.camelize)
44
- cimi_modules << cimi_module_class
45
- unless cimi_module_class.collections.nil?
46
- cimi_module_class.collections.each do |c|
47
- CIMI.collections << c
48
- end
49
- else
50
- warn "WARNING: File %s placed in collections directory but does not have any collections defined" % base_collection_name
51
- end
52
- end
25
+ load_collections_for :cimi, :from => File.join(File.dirname(__FILE__), 'collections')
53
26
 
54
27
  def self.included(klass)
55
28
  klass.class_eval do
56
- CIMI::Collections.cimi_modules.each { |c| use c }
29
+ CIMI::Collections.modules(:cimi).each { |c| use c }
57
30
  end
58
31
  end
59
32
 
@@ -45,11 +45,8 @@ module CIMI::Collections
45
45
  operation :create do
46
46
  description "Create new AddressTemplate"
47
47
  control do
48
- if grab_content_type(request.content_type, request.body) == :json
49
- new_address_template = CIMI::Model::AddressTemplate.create_from_json(request.body.read, self)
50
- else
51
- new_address_template = CIMI::Model::AddressTemplate.create_from_xml(request.body.read, self)
52
- end
48
+ addr_templ = CIMI::Model::AddressTemplateCreate.parse(request.body, request.content_type)
49
+ new_address_template = addr_templ.create(self)
53
50
  headers_for_create new_address_template
54
51
  respond_to do |format|
55
52
  format.json { new_address_template.to_json }
@@ -47,11 +47,8 @@ module CIMI::Collections
47
47
  operation :create, :with_capability => :create_address do
48
48
  description "Create a new Address"
49
49
  control do
50
- if grab_content_type(request.content_type, request.body) == :json
51
- address = CIMI::Model::Address.create(request.body.read, self, :json)
52
- else
53
- address = CIMI::Model::Address.create(request.body.read, self, :xml)
54
- end
50
+ addr = CIMI::Model::AddressCreate.parse(request.body, request.content_type)
51
+ address = addr.create(self)
55
52
  respond_to do |format|
56
53
  format.xml { address.to_xml }
57
54
  format.json { address.to_json }
@@ -18,6 +18,10 @@ require_relative '../models'
18
18
  module CIMI::Collections
19
19
  class Base < Sinatra::Base
20
20
 
21
+ Sinatra::Rabbit.configure do
22
+ enable :use_namespace
23
+ end
24
+
21
25
  include Sinatra::Rabbit
22
26
  include Sinatra::Rabbit::Features
23
27
  include CIMI::Model
@@ -40,8 +44,8 @@ module CIMI::Collections
40
44
  set :root_path, config.root_url
41
45
  set :version, config.version
42
46
  set :root, File.join(File.dirname(__FILE__), '..', '..', '..')
43
- set :views, root + '/views/cimi'
44
- set :public_folder, root + '/public'
47
+ set :views, File.join(root, 'views')
48
+ set :public_folder, File.join(root, 'public')
45
49
  set :documentation_class, CIMI
46
50
  set :haml, :format => :xhtml
47
51
 
@@ -53,14 +57,22 @@ module CIMI::Collections
53
57
  report_error
54
58
  end
55
59
 
60
+ error CIMI::Model::ValidationError do
61
+ report_error
62
+ end
63
+
64
+ error JSON::ParserError do
65
+ report_error(400, "Bad request (#{request.env['sinatra.error'].message})")
66
+ end
67
+
68
+ error REXML::ParseException do
69
+ report_error(400)
70
+ end
71
+
56
72
  before do
57
73
  # Respond with 400, If we don't get a http Host header,
58
74
  halt 400, "Unable to find HTTP Host header" if @env['HTTP_HOST'] == nil
59
75
  end
60
76
 
61
- after do
62
- headers 'CIMI-Specification-Version' => Deltacloud[:cimi].version
63
- end
64
-
65
77
  end
66
78
  end