deltacloud-core 0.1.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/DISCLAIMER +8 -0
  2. data/{COPYING → LICENSE} +0 -0
  3. data/NOTICE +13 -0
  4. data/Rakefile +50 -51
  5. data/bin/deltacloudd +8 -1
  6. data/config.ru +0 -2
  7. data/config/drivers.yaml +48 -0
  8. data/deltacloud-core.gemspec +75 -0
  9. data/deltacloud.rb +3 -2
  10. data/lib/deltacloud/backend_capability.rb +15 -3
  11. data/lib/deltacloud/base_driver.rb +0 -2
  12. data/lib/deltacloud/base_driver/base_driver.rb +85 -89
  13. data/lib/deltacloud/base_driver/features.rb +61 -7
  14. data/lib/deltacloud/base_driver/mock_driver.rb +42 -43
  15. data/lib/deltacloud/core_ext.rb +18 -0
  16. data/lib/deltacloud/core_ext/integer.rb +31 -0
  17. data/lib/deltacloud/core_ext/string.rb +50 -0
  18. data/lib/deltacloud/drivers/azure/azure_driver.rb +71 -22
  19. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +641 -584
  20. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +0 -2
  21. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +167 -0
  22. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +39 -1
  23. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +41 -25
  24. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml +6 -3
  25. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml +6 -3
  26. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml +4 -2
  27. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml +5 -2
  28. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml +4 -2
  29. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +1 -0
  30. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +1 -0
  31. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +1 -0
  32. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +1 -0
  33. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +1 -0
  34. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +1 -0
  35. data/lib/deltacloud/drivers/mock/mock_driver.rb +138 -30
  36. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +13 -15
  37. data/lib/deltacloud/drivers/opennebula/occi_client.rb +13 -15
  38. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +13 -15
  39. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +224 -113
  40. data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +332 -0
  41. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +221 -170
  42. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +0 -1
  43. data/lib/deltacloud/drivers/sbc/sbc_client.rb +247 -0
  44. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +297 -0
  45. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -2
  46. data/lib/deltacloud/hardware_profile.rb +1 -3
  47. data/lib/deltacloud/helpers.rb +0 -2
  48. data/lib/deltacloud/helpers/application_helper.rb +86 -12
  49. data/lib/deltacloud/helpers/blob_stream.rb +19 -2
  50. data/lib/deltacloud/helpers/conversion_helper.rb +0 -2
  51. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +0 -2
  52. data/lib/deltacloud/method_serializer.rb +0 -2
  53. data/lib/deltacloud/models/base_model.rb +0 -2
  54. data/lib/deltacloud/models/blob.rb +1 -2
  55. data/lib/deltacloud/models/bucket.rb +0 -2
  56. data/lib/deltacloud/models/image.rb +0 -2
  57. data/lib/deltacloud/models/instance.rb +19 -2
  58. data/lib/deltacloud/models/instance_profile.rb +4 -2
  59. data/lib/deltacloud/models/key.rb +0 -2
  60. data/lib/deltacloud/models/load_balancer.rb +0 -2
  61. data/lib/deltacloud/models/realm.rb +0 -2
  62. data/lib/deltacloud/models/storage_snapshot.rb +0 -2
  63. data/lib/deltacloud/models/storage_volume.rb +4 -2
  64. data/lib/deltacloud/runner.rb +132 -0
  65. data/lib/deltacloud/state_machine.rb +0 -2
  66. data/lib/deltacloud/validation.rb +9 -7
  67. data/lib/drivers.rb +36 -48
  68. data/lib/sinatra/accept_media_types.rb +26 -0
  69. data/lib/sinatra/lazy_auth.rb +16 -0
  70. data/lib/sinatra/rabbit.rb +112 -54
  71. data/lib/sinatra/rack_driver_select.rb +50 -16
  72. data/lib/sinatra/rack_etag.rb +79 -0
  73. data/lib/sinatra/rack_matrix_params.rb +84 -0
  74. data/lib/sinatra/rack_runtime.rb +47 -0
  75. data/lib/sinatra/static_assets.rb +16 -0
  76. data/lib/sinatra/url_for.rb +31 -4
  77. data/public/favicon.ico +0 -0
  78. data/public/images/bread-bg.png +0 -0
  79. data/public/images/error.png +0 -0
  80. data/public/images/pending.png +0 -0
  81. data/public/images/running.png +0 -0
  82. data/public/images/stopped.png +0 -0
  83. data/public/javascripts/application.js +35 -0
  84. data/public/stylesheets/compiled/application.css +59 -5
  85. data/public/stylesheets/compiled/screen.css +1 -1
  86. data/server.rb +293 -29
  87. data/support/fedora/deltacloud-core +78 -0
  88. data/support/fedora/deltacloud-core.spec +143 -0
  89. data/support/fedora/deltacloudd +78 -18
  90. data/support/fedora/rubygem-deltacloud-core.spec +76 -40
  91. data/tests/common.rb +172 -0
  92. data/tests/drivers/mock/api_test.rb +133 -0
  93. data/tests/drivers/mock/hardware_profiles_test.rb +134 -0
  94. data/tests/drivers/mock/images_test.rb +126 -0
  95. data/tests/drivers/mock/instance_states_test.rb +71 -0
  96. data/tests/drivers/mock/instances_test.rb +236 -0
  97. data/tests/drivers/mock/realms_test.rb +93 -0
  98. data/tests/drivers/mock/setup.rb +3 -0
  99. data/tests/drivers/mock/url_for_test.rb +67 -0
  100. data/tests/drivers/rackspace/api_test.rb +41 -0
  101. data/tests/drivers/rackspace/hardware_profiles_test.rb +53 -0
  102. data/tests/drivers/rackspace/images_test.rb +40 -0
  103. data/tests/drivers/rackspace/instances_test.rb +161 -0
  104. data/tests/drivers/rackspace/realms_test.rb +36 -0
  105. data/tests/drivers/rackspace/setup.rb +14 -0
  106. data/tests/drivers/rhevm/api_test.rb +39 -0
  107. data/tests/drivers/rhevm/hardware_profiles_test.rb +53 -0
  108. data/tests/drivers/rhevm/images_test.rb +42 -0
  109. data/tests/drivers/rhevm/instances_test.rb +179 -0
  110. data/tests/drivers/rhevm/realms_test.rb +35 -0
  111. data/tests/drivers/rhevm/setup.rb +14 -0
  112. data/tests/rabbit_test.rb +52 -0
  113. data/views/api/show.html.haml +2 -5
  114. data/views/blobs/new.html.haml +17 -1
  115. data/views/blobs/show.html.haml +6 -0
  116. data/views/blobs/show.xml.haml +5 -1
  117. data/views/buckets/index.html.haml +1 -12
  118. data/views/buckets/index.xml.haml +3 -5
  119. data/views/docs/operation.html.haml +23 -11
  120. data/views/drivers/index.html.haml +15 -0
  121. data/views/drivers/index.xml.haml +7 -0
  122. data/views/drivers/show.html.haml +20 -0
  123. data/views/drivers/show.xml.haml +7 -0
  124. data/views/error.html.haml +31 -0
  125. data/views/errors/auth_exception.xml.haml +2 -1
  126. data/views/errors/backend_capability_failure.xml.haml +2 -1
  127. data/views/errors/backend_error.html.haml +3 -0
  128. data/views/errors/backend_error.xml.haml +2 -2
  129. data/views/errors/validation_failure.xml.haml +3 -2
  130. data/views/images/index.html.haml +1 -6
  131. data/views/images/index.xml.haml +2 -0
  132. data/views/images/new.html.haml +14 -0
  133. data/views/images/show.xml.haml +2 -0
  134. data/views/instances/index.html.haml +8 -6
  135. data/views/instances/index.xml.haml +4 -0
  136. data/views/instances/new.html.haml +40 -11
  137. data/views/instances/run.html.haml +9 -0
  138. data/views/instances/run.xml.haml +7 -0
  139. data/views/instances/run_command.html.haml +16 -0
  140. data/views/instances/show.html.haml +14 -0
  141. data/views/instances/show.xml.haml +12 -4
  142. data/views/layout.html.haml +7 -2
  143. data/views/load_balancers/index.html.haml +1 -1
  144. data/views/load_balancers/new.html.haml +2 -2
  145. data/views/load_balancers/show.html.haml +1 -1
  146. data/views/storage_snapshots/index.html.haml +3 -0
  147. data/views/storage_snapshots/new.html.haml +9 -0
  148. data/views/storage_volumes/attach.html.haml +20 -0
  149. data/views/storage_volumes/index.html.haml +16 -1
  150. data/views/storage_volumes/index.xml.haml +1 -10
  151. data/views/storage_volumes/new.html.haml +17 -0
  152. data/views/storage_volumes/show.html.haml +8 -0
  153. data/views/storage_volumes/show.xml.haml +25 -3
  154. metadata +197 -127
  155. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +0 -130
  156. data/parse.rb +0 -7
  157. data/test.rb +0 -3
  158. data/views/api/drivers.xml.haml +0 -6
@@ -0,0 +1,8 @@
1
+ Apache Deltacloud is an effort undergoing incubation at The Apache Software
2
+ Foundation (ASF), sponsored by the Incubator PMC. Incubation is required of
3
+ all newly accepted projects until a further review indicates that the
4
+ infrastructure, communications, and decision making process have stabilized
5
+ in a manner consistent with other successful ASF projects. While
6
+ incubation status is not necessarily a reflection of the completeness or
7
+ stability of the code, it does indicate that the project has yet to be
8
+ fully endorsed by the ASF.
File without changes
data/NOTICE ADDED
@@ -0,0 +1,13 @@
1
+ Apache Deltacloud
2
+ Copyright 2010 The Apache Software Foundation
3
+
4
+ This product includes software developed at The Apache Software Foundation
5
+ (http://www.apache.org/).
6
+
7
+ This product includes software developed by Red Hat,
8
+ Inc. (http://www.redhat.com/)
9
+
10
+ This product includes software developed by IBM Corporation
11
+
12
+ This product includes software developed by the OpenNebula Project
13
+ (http://opennebula.org/)
data/Rakefile CHANGED
@@ -1,6 +1,4 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
3
- #
4
2
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
3
  # contributor license agreements. See the NOTICE file distributed with
6
4
  # this work for additional information regarding copyright ownership. The
@@ -28,65 +26,66 @@ begin
28
26
  rescue LoadError
29
27
  end
30
28
 
31
- desc "Run basic unit tests"
32
- Rake::TestTask.new("test") { |t|
33
- t.test_files = FileList.new('tests/**/*_test.rb')
34
- t.verbose = true
35
- t.warning = false
36
- }
37
-
38
29
  begin
39
- require 'yard'
40
- YARD::Rake::YardocTask.new do |t|
41
- t.files = ['lib/**/*.rb', '*.rb'] # optional
30
+ require 'cucumber'
31
+ require 'cucumber/rake/task'
32
+ namespace :cucumber do
33
+ %w(mock ec2 sbc).each do |driver|
34
+ namespace driver do
35
+ Cucumber::Rake::Task.new(:test) do |t|
36
+ t.cucumber_opts = "../tests/#{driver} --format pretty"
37
+ t.rcov = false
38
+ end
39
+ Cucumber::Rake::Task.new(:features) do |t|
40
+ t.cucumber_opts = "../tests/#{driver} --format html --out ../tests/tmp/cucumber_#{driver}.html"
41
+ t.rcov = false
42
+ end
43
+ Cucumber::Rake::Task.new(:junit) do |t|
44
+ t.cucumber_opts = "../tests/#{driver} --format junit --out #{File.join(File.dirname(__FILE__), "tmp", "junit_#{driver}")}"
45
+ end
46
+ end
47
+ end
42
48
  end
43
49
  rescue LoadError
44
50
  end
45
51
 
46
- spec = Gem::Specification.load('deltacloud-core.gemspec')
47
- Rake::GemPackageTask.new(spec) do |pkg|
48
- pkg.need_tar = true
52
+ namespace :test do
53
+ %w(mock rackspace rhevm).each do |driver|
54
+ desc "Run #{driver} unit tests"
55
+ Rake::TestTask.new(driver) { |t|
56
+ t.test_files = ['tests/common.rb', "tests/drivers/#{driver}/setup.rb"] + FileList.new("tests/drivers/#{driver}/*_test.rb") + FileList.new('tests/rabbit_test.rb')
57
+ t.options = "-v -v"
58
+ t.verbose = true
59
+ t.warning = false
60
+ }
61
+ end
49
62
  end
50
63
 
51
- desc "Install API"
52
- task :install, [:install_dir, :bin_dir] do |t, args|
53
-
54
- require 'fileutils'
55
- require 'pp'
56
-
57
- files = FileList[
58
- Dir["config/**/**"],
59
- Dir["features/**/**"],
60
- Dir["lib/**/**"],
61
- Dir["public/**/**"],
62
- Dir["views/**/**"],
63
- "config.ru",
64
- "COPYING",
65
- "README",
66
- "*.rb"
67
- ]
68
-
69
- INSTALL_DIR=args.install_dir || "/usr/local/share/deltacloud-core"
70
- BIN_DIR=args.bin_dir || "/usr/local/bin"
71
-
72
- exit(1) unless FileUtils.mkdir_p(INSTALL_DIR)
73
- exit(1) unless FileUtils.mkdir_p(BIN_DIR)
64
+ desc "Call our Test::Unit suite"
65
+ task :test do
66
+ %w(mock rackspace rhevm).each do |driver|
67
+ Rake::Task["test:#{driver}"].reenable
68
+ Rake::Task["test:#{driver}"].invoke
69
+ end
70
+ end
74
71
 
75
- files.each do |f|
76
- install_path = "#{INSTALL_DIR}/#{File.dirname(f)}"
77
- unless File.directory?(install_path)
78
- FileUtils.mkdir_p(install_path, :mode => 0755, :verbose => true)
79
- end
80
- next if File.directory?(f)
81
- FileUtils.install(f, "#{INSTALL_DIR}/#{File.dirname(f)}", :verbose => true)
72
+ desc "Call our Cucumber suite"
73
+ task :cucumber do
74
+ %w(mock ec2 sbc).each do |driver|
75
+ Rake::Task["cucumber:#{driver}:test"].reenable
76
+ Rake::Task["cucumber:#{driver}:test"].invoke
82
77
  end
78
+ end
83
79
 
84
- FileUtils.install('bin/deltacloudd', BIN_DIR, :verbose => true, :mode => 0755)
80
+ begin
81
+ require 'yard'
82
+ YARD::Rake::YardocTask.new do |t|
83
+ t.files = ['lib/**/*.rb', '*.rb'] # optional
84
+ end
85
+ rescue LoadError
85
86
  end
86
87
 
87
- desc "Uninstall API"
88
- task :uninstall do
89
- require 'fileutils'
90
- INSTALL_DIR="/usr/share/deltacloud-core"
91
- FileUtils.rm_rf(INSTALL_DIR)
88
+ spec = Gem::Specification.load('deltacloud-core.gemspec')
89
+ Rake::GemPackageTask.new(spec) do |pkg|
90
+ pkg.need_tar = true
92
91
  end
@@ -36,6 +36,9 @@ BANNER
36
36
  opts.on( '-p', '--port PORT', 'Use PORT (default: 3001)') do |port|
37
37
  ENV["API_PORT"] = port
38
38
  end
39
+ opts.on( '-P', '--provider PROVIDER', 'Use PROVIDER (default is set in the driver)') do |provider|
40
+ ENV['API_PROVIDER'] = provider
41
+ end
39
42
  opts.on( '-e', '--env ENV', 'Environment (default: "development")') { |env| options[:env] = env }
40
43
  opts.on( '-h', '--help', '') { options[:help] = true }
41
44
  end
@@ -55,7 +58,10 @@ end
55
58
  ENV["API_HOST"] = "localhost" unless ENV["API_HOST"]
56
59
  ENV["API_PORT"] = "3001" unless ENV["API_PORT"]
57
60
 
58
- puts "Starting Deltacloud API :: #{ENV["API_DRIVER"]} :: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
61
+ msg = "Starting Deltacloud API :: #{ENV["API_DRIVER"]} "
62
+ msg << ":: #{ENV['API_PROVIDER']} " if ENV['API_PROVIDER']
63
+ msg << ":: http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
64
+ puts msg
59
65
  puts
60
66
 
61
67
  dirname="#{File.dirname(__FILE__)}/.."
@@ -99,6 +105,7 @@ else
99
105
  argv_opts << ['--rackup', 'config.ru' ]
100
106
  argv_opts << ['--chdir', dirname ]
101
107
  argv_opts << ['-e', options[:env] ]
108
+ argv_opts << ['--timeout', '60']
102
109
  argv_opts << ['--threaded', '-D', '--stats', '/stats']
103
110
 
104
111
  argv_opts.flatten!
data/config.ru CHANGED
@@ -1,6 +1,4 @@
1
1
  #
2
- # Copyright (C) 2009,2010 Red Hat, Inc.
3
- #
4
2
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
3
  # contributor license agreements. See the NOTICE file distributed with
6
4
  # this work for additional information regarding copyright ownership. The
@@ -0,0 +1,48 @@
1
+ ---
2
+ :gogrid:
3
+ :name: Gogrid
4
+ :mock:
5
+ :name: Mock
6
+ :rhevm:
7
+ :name: RHEVM
8
+ :entrypoints:
9
+ default:
10
+ default: "https://rhev-m.localhost:8443/rhevm-api-powershell"
11
+ :rimuhosting:
12
+ :name: RimuHosting
13
+ :opennebula:
14
+ :class: OpennebulaDriver
15
+ :name: Opennebula
16
+ :sbc:
17
+ :name: SBC
18
+ :terremark:
19
+ :name: Terremark
20
+ :rackspace:
21
+ :name: Rackspace
22
+ :azure:
23
+ :name: Azure
24
+ :eucalyptus:
25
+ :name: Eucalyptus
26
+ :username: Access Key ID
27
+ :password: Secret Access Key
28
+ :entrypoints:
29
+ default:
30
+ default: "ec2=EUCALYPTUS_IP[:PORT];s3=WALRUS_IP[:PORT]"
31
+ :ec2:
32
+ :entrypoints:
33
+ s3:
34
+ us-west-1: s3-us-west-1.amazonaws.com
35
+ ap-southeast-1: s3-ap-southeast-1.amazonaws.com
36
+ eu-west-1: s3-eu-west-1.amazonaws.com
37
+ us-east-1: s3.amazonaws.com
38
+ elb:
39
+ us-west-1: elasticloadbalancing.us-west-1.amazonaws.com
40
+ ap-southeast-1: elasticloadbalancing.ap-southeast-1.amazonaws.com
41
+ eu-west-1: elasticloadbalancing.eu-west-1.amazonaws.com
42
+ us-east-1: elasticloadbalancing.us-east-1.amazonaws.com
43
+ ec2:
44
+ us-west-1: ec2.us-west-1.amazonaws.com
45
+ ap-southeast-1: ec2.ap-southeast-1.amazonaws.com
46
+ eu-west-1: ec2.eu-west-1.amazonaws.com
47
+ us-east-1: ec2.us-east-1.amazonaws.com
48
+ :name: EC2
@@ -0,0 +1,75 @@
1
+ #
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 'rake'
18
+
19
+ Gem::Specification.new do |s|
20
+ s.author = 'Red Hat, Inc.'
21
+ s.homepage = "http://www.deltacloud.org"
22
+ s.email = 'deltacloud-users@lists.fedorahosted.org'
23
+ s.name = 'deltacloud-core'
24
+
25
+ s.description = <<-EOF
26
+ The Deltacloud API is built as a service-based REST API.
27
+ You do not directly link a Deltacloud library into your program to use it.
28
+ Instead, a client speaks the Deltacloud API over HTTP to a server
29
+ which implements the REST interface.
30
+ EOF
31
+
32
+ s.version = '0.3.0'
33
+ s.date = Time.now
34
+ s.summary = %q{Deltacloud REST API}
35
+ s.files = FileList[
36
+ 'Rakefile',
37
+ '*.gemspec',
38
+ 'config.ru',
39
+ '*.rb',
40
+ 'log',
41
+ 'config/drivers.yaml',
42
+ 'tmp',
43
+ 'support/fedora/**',
44
+ 'lib/**/*.rb',
45
+ 'lib/**/*.yml',
46
+ 'tests/**/*.rb',
47
+ 'views/**/*.haml',
48
+ 'views/instance_states/*.erb',
49
+ 'public/favicon.ico',
50
+ 'public/images/*.png',
51
+ 'public/javascripts/*.js',
52
+ 'public/stylesheets/compiled/*.css',
53
+ 'bin/deltacloudd'
54
+ ].to_a
55
+
56
+ s.bindir = 'bin'
57
+ s.executables = 'deltacloudd'
58
+ s.test_files= Dir.glob("tests/*_test.rb")
59
+ s.extra_rdoc_files = Dir["LICENSE", "DISCLAIMER", "NOTICE"]
60
+ s.required_ruby_version = '>= 1.8.1'
61
+
62
+ s.add_dependency('rake', '>= 0.8.7')
63
+ s.add_dependency('haml', '>= 2.2.17')
64
+ s.add_dependency('sinatra', '>= 0.9.4')
65
+ s.add_dependency('rack', '>= 1.0.0', '<=1.1.0')
66
+ s.add_dependency('rack-accept', '~> 0.4.3')
67
+ s.add_dependency('json', '>= 1.1.9')
68
+ s.add_dependency('net-ssh', '>= 2.0.0')
69
+ s.add_development_dependency('compass', '>= 0.8.17')
70
+ s.add_development_dependency('nokogiri', '>= 1.4.1', '< 1.4.4')
71
+ s.add_development_dependency('rack-test', '>= 0.5.3')
72
+ s.add_development_dependency('cucumber', '>= 0.6.3')
73
+ s.add_development_dependency('rcov', '>= 0.9.8')
74
+
75
+ end
@@ -1,6 +1,4 @@
1
1
  #
2
- # Copyright (C) 2009,2010 Red Hat, Inc.
3
- #
4
2
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
3
  # contributor license agreements. See the NOTICE file distributed with
6
4
  # this work for additional information regarding copyright ownership. The
@@ -20,6 +18,8 @@ $:.unshift File.join(File.dirname(__FILE__), 'lib')
20
18
 
21
19
  require 'drivers'
22
20
 
21
+ require 'deltacloud/core_ext'
22
+
23
23
  require 'deltacloud/base_driver'
24
24
  require 'deltacloud/hardware_profile'
25
25
  require 'deltacloud/state_machine'
@@ -38,3 +38,4 @@ require 'deltacloud/models/load_balancer'
38
38
 
39
39
  require 'deltacloud/validation'
40
40
  require 'deltacloud/helpers'
41
+ require 'deltacloud/runner'
@@ -1,6 +1,4 @@
1
1
  #
2
- # Copyright (C) 2009, 2010 Red Hat, Inc.
3
- #
4
2
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
3
  # contributor license agreements. See the NOTICE file distributed with
6
4
  # this work for additional information regarding copyright ownership. The
@@ -20,6 +18,7 @@ module Deltacloud::BackendCapability
20
18
 
21
19
  class Failure < StandardError
22
20
  attr_reader :capability
21
+
23
22
  def initialize(capability, msg='')
24
23
  super(msg)
25
24
  @capability = capability
@@ -27,13 +26,26 @@ module Deltacloud::BackendCapability
27
26
  end
28
27
 
29
28
  attr_reader :capability
29
+
30
30
  def with_capability(capability)
31
31
  @capability = capability
32
32
  end
33
33
 
34
+ def has_capability?(backend)
35
+ !capability or backend.has_capability?(capability)
36
+ end
37
+
34
38
  def check_capability(backend)
35
- if capability and !backend.respond_to?(capability)
39
+ if !has_capability?(backend)
36
40
  raise Failure.new(capability, "#{capability} capability not supported by backend #{backend.class.name}")
37
41
  end
38
42
  end
43
+
44
+ module Helpers
45
+ def operations_for_collection(collection)
46
+ collections[collection].operations.values.select { |op| op.has_capability?(driver) }
47
+ end
48
+ end
49
+
50
+ helpers Helpers
39
51
  end
@@ -1,6 +1,4 @@
1
1
  #
2
- # Copyright (C) 2009,2010 Red Hat, Inc.
3
- #
4
2
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
3
  # contributor license agreements. See the NOTICE file distributed with
6
4
  # this work for additional information regarding copyright ownership. The
@@ -1,6 +1,4 @@
1
1
  #
2
- # Copyright (C) 2009 Red Hat, Inc.
3
- #
4
2
  # Licensed to the Apache Software Foundation (ASF) under one or more
5
3
  # contributor license agreements. See the NOTICE file distributed with
6
4
  # this work for additional information regarding copyright ownership. The
@@ -42,7 +40,7 @@ module Deltacloud
42
40
  end
43
41
 
44
42
  class BaseDriver
45
-
43
+
46
44
  def self.define_hardware_profile(name,&block)
47
45
  @hardware_profiles ||= []
48
46
  hw_profile = @hardware_profiles.find{|e| e.name == name}
@@ -68,7 +66,7 @@ module Deltacloud
68
66
  end
69
67
 
70
68
  def hardware_profile(credentials, name)
71
- hardware_profiles(credentials, :name => name).first
69
+ hardware_profiles(credentials, :id => name).first
72
70
  end
73
71
 
74
72
  def filter_hardware_profiles(profiles, opts)
@@ -76,7 +74,8 @@ module Deltacloud
76
74
  if v = opts[:architecture]
77
75
  profiles = profiles.select { |hwp| hwp.include?(:architecture, v) }
78
76
  end
79
- if v = opts[:name]
77
+ # As a request param, we call 'name' 'id'
78
+ if v = opts[:id]
80
79
  profiles = profiles.select { |hwp| hwp.name == v }
81
80
  end
82
81
  end
@@ -86,7 +85,7 @@ module Deltacloud
86
85
  def find_hardware_profile(credentials, name, image_id)
87
86
  hwp = nil
88
87
  if name
89
- unless hwp = hardware_profiles(credentials, :name => name).first
88
+ unless hwp = hardware_profiles(credentials, :id => name).first
90
89
  raise BackendError.new(400, "bad-hardware-profile-name",
91
90
  "Hardware profile '#{name}' does not exist", nil)
92
91
  end
@@ -126,100 +125,90 @@ module Deltacloud
126
125
  actions
127
126
  end
128
127
 
128
+ ## Capabilities
129
+ # The rabbit dsl supports declaring a capability that is required
130
+ # in the backend driver for the call to succeed. A driver can
131
+ # provide a capability by implementing the method with the same
132
+ # name as the capability. Below is a list of the capabilities as
133
+ # the expected method signatures.
134
+ #
135
+ # Following the capability list are the resource member show
136
+ # methods. They each require that the corresponding collection
137
+ # method be defined
138
+ #
139
+ # TODO: standardize all of these to the same signature (credentials, opts)
140
+ #
141
+ # def realms(credentials, opts=nil)
142
+ #
143
+ # def images(credentials, ops)
144
+ #
145
+ # def instances(credentials, ops)
146
+ # def create_instance(credentials, image_id, opts)
147
+ # def start_instance(credentials, id)
148
+ # def stop_instance(credentials, id)
149
+ # def reboot_instance(credentials, id)
150
+ #
151
+ # def storage_volumes(credentials, ops)
152
+ #
153
+ # def storage_snapshots(credentials, ops)
154
+ #
155
+ # def buckets(credentials, opts = nil)
156
+ # def create_bucket(credentials, name, opts=nil)
157
+ # def delete_bucket(credentials, name, opts=nil)
158
+ #
159
+ # def blobs(credentials, opts = nil)
160
+ # def blob_data(credentials, bucket_id, blob_id, opts)
161
+ # def create_blob(credentials, bucket_id, blob_id, blob_data, opts=nil)
162
+ # def delete_blob(credentials, bucket_id, blob_id, opts=nil)
163
+ #
164
+ # def keys(credentials, opts)
165
+ # def create_key(credentials, opts)
166
+ # def destroy_key(credentials, opts)
167
+
129
168
  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
- []
169
+ realms = realms(credentials, opts).first if has_capability?(:realms)
137
170
  end
138
171
 
139
172
  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
- []
173
+ images(credentials, opts).first if has_capability?(:images)
147
174
  end
148
175
 
149
176
  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)
177
+ instances(credentials, opts).first if has_capability?(:instances)
166
178
  end
167
179
 
168
180
  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
- []
181
+ storage_volumes(credentials, opts).first if has_capability?(:storage_volumes)
176
182
  end
177
183
 
178
184
  def storage_snapshot(credentials, opts)
179
- snapshots = storage_snapshots(credentials, opts)
180
- return snapshots.first unless snapshots.empty?
181
- nil
185
+ storage_snapshots(credentials, opts).first if has_capability?(:storage_snapshots)
182
186
  end
183
187
 
184
- def storage_snapshots(credentials, ops)
185
- []
188
+ def bucket(credentials, opts = {})
189
+ #list of objects within bucket
190
+ buckets(credentials, opts).first if has_capability?(:buckets)
186
191
  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?
192
+
193
+ def blob(credentials, opts = {})
194
+ blobs(credentials, opts).first if has_capability?(:blobs)
213
195
  end
214
196
 
215
- def blob_data(credentials, bucket_id, blob_id, opts)
197
+ def key(credentials, opts=nil)
198
+ keys(credentials, opts).first if has_capability?(:keys)
216
199
  end
217
200
 
218
- def create_blob(credentials, bucket_id, blob_id, blob_data, opts=nil)
219
- end
201
+ MEMBER_SHOW_METHODS =
202
+ [ :realm, :image, :instance, :storage_volume, :bucket, :blob, :key ]
220
203
 
221
- def delete_blob(credentials, bucket_id, blob_id, opts=nil)
204
+ def has_capability?(capability)
205
+ if MEMBER_SHOW_METHODS.include?(capability.to_sym)
206
+ has_capability?(capability.to_s.pluralize)
207
+ else
208
+ respond_to?(capability)
209
+ end
222
210
  end
211
+
223
212
 
224
213
  def filter_on(collection, attribute, opts)
225
214
  return collection if opts.nil?
@@ -237,8 +226,7 @@ module Deltacloud
237
226
  end
238
227
 
239
228
  def has_collection?(collection)
240
- return true if self.supported_collections.include?(collection)
241
- return false
229
+ supported_collections.include?(collection)
242
230
  end
243
231
 
244
232
  def catched_exceptions_list
@@ -248,18 +236,26 @@ module Deltacloud
248
236
  def safely(&block)
249
237
  begin
250
238
  block.call
251
- rescue *catched_exceptions_list[:error] => e
252
- raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace)
253
- rescue *catched_exceptions_list[:auth] => e
254
- raise Deltacloud::AuthException.new
255
239
  rescue => e
240
+ catched_exceptions_list[:auth].each do |ex|
241
+ if e.class == ex or e.class.name =~ ex or e.message =~ ex
242
+ raise Deltacloud::AuthException.new
243
+ end
244
+ end
245
+ catched_exceptions_list[:error].each do |ex|
246
+ if e.class == ex or e.class.name =~ ex or e.message =~ ex
247
+ raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace) if e.class.name =~ ex
248
+ end
249
+ end
256
250
  catched_exceptions_list[:glob].each do |ex|
257
- raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace) if e.class.name =~ ex
251
+ if e.class == ex or e.class.name =~ ex or e.message =~ ex
252
+ raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
253
+ end
258
254
  end
259
- puts "======= UNHANDLED EXCEPTION ============"
260
- puts e.inspect
261
- puts "========================================"
262
- raise e
255
+ $stderr.puts "# UNCAUGHT EXCEPTION # -> '#{e.class}' - '#{e.message}'"
256
+ $stderr.puts "# #{e.backtrace.join("\n")}"
257
+ $stderr.puts "##############"
258
+ raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
263
259
  end
264
260
  end
265
261