deltacloud-core 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +145 -0
- data/NOTICE +10 -1
- data/Rakefile +50 -2
- data/bin/deltacloudd +111 -14
- data/config/addresses.xml +14 -0
- data/config/condor.yaml +30 -0
- data/config/drivers/azure.yaml +3 -0
- data/config/drivers/condor.yaml +3 -0
- data/config/{drivers.yaml → drivers/ec2.yaml} +5 -34
- data/config/drivers/eucalyptus.yaml +8 -0
- data/config/drivers/gogrid.yaml +3 -0
- data/config/drivers/mock.yaml +3 -0
- data/config/drivers/opennebula.yaml +4 -0
- data/config/drivers/rackspace.yaml +3 -0
- data/config/drivers/rhevm.yaml +3 -0
- data/config/drivers/rimuhosting.yaml +3 -0
- data/config/drivers/sbc.yaml +2 -0
- data/config/drivers/terremark.yaml +3 -0
- data/config/drivers/vsphere.yaml +8 -0
- data/deltacloud-core.gemspec +13 -5
- data/deltacloud.rb +4 -2
- data/lib/deltacloud/backend_capability.rb +2 -2
- data/lib/deltacloud/base_driver/base_driver.rb +23 -52
- data/lib/deltacloud/base_driver/exceptions.rb +168 -0
- data/lib/deltacloud/base_driver/features.rb +31 -12
- data/lib/deltacloud/base_driver/mock_driver.rb +2 -1
- data/lib/deltacloud/core_ext/string.rb +2 -0
- data/lib/deltacloud/drivers/azure/azure_driver.rb +5 -5
- data/lib/deltacloud/drivers/condor/condor_client.rb +273 -0
- data/lib/deltacloud/drivers/condor/condor_driver.rb +236 -0
- data/lib/deltacloud/drivers/condor/ip_agents/confserver.rb +75 -0
- data/lib/deltacloud/drivers/condor/ip_agents/default.rb +84 -0
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +326 -95
- data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +3 -3
- data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +40 -8
- data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +7 -7
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +42 -25
- data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob1.yml +6 -4
- data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob2.yml +7 -5
- data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob3.yml +6 -4
- data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob4.yml +6 -4
- data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob5.yml +6 -4
- data/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml +7 -1
- data/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml +6 -1
- data/lib/deltacloud/drivers/mock/data/images/img1.yml +6 -2
- data/lib/deltacloud/drivers/mock/data/images/img2.yml +6 -2
- data/lib/deltacloud/drivers/mock/data/images/img3.yml +6 -2
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +11 -10
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +14 -7
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +14 -7
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +3 -2
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +3 -2
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +3 -2
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +4 -3
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +4 -3
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +4 -3
- data/lib/deltacloud/drivers/mock/mock_client.rb +101 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +367 -429
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +59 -9
- data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +62 -8
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +100 -45
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +3 -2
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +8 -11
- data/lib/deltacloud/drivers/sbc/sbc_client.rb +6 -6
- data/lib/deltacloud/drivers/sbc/sbc_driver.rb +16 -0
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +17 -12
- data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +140 -0
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +405 -0
- data/lib/deltacloud/drivers/vsphere/vsphere_filemanager.rb +182 -0
- data/lib/deltacloud/hardware_profile.rb +1 -1
- data/lib/deltacloud/helpers.rb +2 -1
- data/lib/deltacloud/helpers/application_helper.rb +92 -20
- data/lib/deltacloud/helpers/blob_stream.rb +160 -12
- data/lib/deltacloud/helpers/conversion_helper.rb +6 -2
- data/lib/deltacloud/helpers/json_helper.rb +31 -0
- data/lib/deltacloud/models/address.rb +28 -0
- data/lib/deltacloud/models/base_model.rb +5 -1
- data/lib/deltacloud/models/blob.rb +1 -1
- data/lib/deltacloud/models/bucket.rb +10 -0
- data/lib/deltacloud/models/firewall.rb +22 -0
- data/lib/deltacloud/models/firewall_rule.rb +23 -0
- data/lib/deltacloud/models/image.rb +12 -0
- data/lib/deltacloud/models/instance.rb +20 -2
- data/lib/deltacloud/models/key.rb +1 -1
- data/lib/deltacloud/runner.rb +3 -3
- data/lib/deltacloud/validation.rb +3 -7
- data/lib/drivers.rb +7 -1
- data/lib/sinatra/body_proxy.rb +34 -0
- data/lib/sinatra/lazy_auth.rb +5 -0
- data/lib/sinatra/rabbit.rb +54 -31
- data/lib/sinatra/rack_accept.rb +157 -0
- data/lib/sinatra/rack_date.rb +38 -0
- data/lib/sinatra/rack_etag.rb +2 -3
- data/lib/sinatra/rack_matrix_params.rb +51 -29
- data/lib/sinatra/rack_runtime.rb +1 -1
- data/lib/sinatra/rack_syslog.rb +86 -0
- data/lib/sinatra/url_for.rb +14 -1
- data/public/images/address.png +0 -0
- data/public/images/balancer.png +0 -0
- data/public/images/blob.png +0 -0
- data/public/images/bucket.png +0 -0
- data/public/images/cloud.png +0 -0
- data/public/images/firewall.png +0 -0
- data/public/images/image.png +0 -0
- data/public/images/key.png +0 -0
- data/public/images/machine.png +0 -0
- data/public/images/profile.png +0 -0
- data/public/images/realm.png +0 -0
- data/public/images/snapshot.png +0 -0
- data/public/images/volume.png +0 -0
- data/public/javascripts/application.js +119 -16
- data/public/javascripts/jquery.min.js +18 -0
- data/public/javascripts/jquery.mobile-1.0b1.min.js +146 -0
- data/public/stylesheets/compiled/application.css +8 -0
- data/public/stylesheets/images/ajax-loader.png +0 -0
- data/public/{images → stylesheets/images}/bread-bg.png +0 -0
- data/public/{images → stylesheets/images}/error.png +0 -0
- data/public/{images → stylesheets/images}/grid.png +0 -0
- data/public/stylesheets/images/icon-search-black.png +0 -0
- data/public/stylesheets/images/icons-18-black.png +0 -0
- data/public/stylesheets/images/icons-18-white.png +0 -0
- data/public/stylesheets/images/icons-36-black.png +0 -0
- data/public/stylesheets/images/icons-36-white.png +0 -0
- data/public/{images → stylesheets/images}/logo-wide.png +0 -0
- data/public/{images → stylesheets/images}/pending.png +0 -0
- data/public/{images → stylesheets/images}/rails.png +0 -0
- data/public/{images → stylesheets/images}/running.png +0 -0
- data/public/{images → stylesheets/images}/stopped.png +0 -0
- data/public/{images → stylesheets/images}/topbar-bg.png +0 -0
- data/public/stylesheets/jquery.mobile-1.0b1.min.css +8 -0
- data/public/stylesheets/new.css +53 -0
- data/server.rb +487 -175
- data/support/condor/bash/cached_images.sh +8 -0
- data/support/condor/bash/cloud_exit_hook.sh +17 -0
- data/support/condor/bash/cloud_functions +175 -0
- data/support/condor/bash/cloud_prepare_hook.sh +20 -0
- data/support/condor/bash/libvirt_cloud_script.sh +13 -0
- data/support/condor/config/50condor_cloud.config +37 -0
- data/support/condor/config/50condor_cloud_node.config +37 -0
- data/support/condor/config/condor-cloud +2 -0
- data/support/condor/config/condor_config.local +44 -0
- data/support/fedora/deltacloud-core +48 -26
- data/support/fedora/deltacloud-core-config +26 -0
- data/support/fedora/deltacloud-core.spec +314 -68
- data/support/fedora/deltacloudd-fedora +5 -0
- data/tests/common.rb +34 -4
- data/tests/drivers/mock/api_test.rb +3 -3
- data/tests/drivers/mock/images_test.rb +12 -0
- data/tests/drivers/mock/instances_test.rb +2 -0
- data/tests/rabbit_test.rb +2 -2
- data/views/addresses/_address.html.haml +6 -0
- data/views/addresses/associate.html.haml +12 -0
- data/views/addresses/index.html.haml +9 -0
- data/views/addresses/index.xml.haml +4 -0
- data/views/addresses/show.html.haml +21 -0
- data/views/addresses/show.xml.haml +14 -0
- data/views/api/show.html.haml +6 -11
- data/views/api/show.xml.haml +2 -0
- data/views/blobs/new.html.haml +24 -23
- data/views/blobs/show.html.haml +30 -31
- data/views/buckets/index.html.haml +9 -21
- data/views/buckets/index.xml.haml +3 -7
- data/views/buckets/new.html.haml +13 -12
- data/views/buckets/show.html.haml +22 -22
- data/views/buckets/show.xml.haml +5 -3
- data/views/docs/collection.html.haml +23 -34
- data/views/docs/collection.xml.haml +2 -2
- data/views/docs/index.html.haml +9 -13
- data/views/docs/index.xml.haml +1 -1
- data/views/docs/operation.html.haml +28 -38
- data/views/docs/operation.xml.haml +1 -1
- data/views/drivers/index.html.haml +8 -13
- data/views/drivers/show.html.haml +18 -18
- data/views/error.html.haml +32 -27
- data/views/errors/400.html.haml +41 -0
- data/views/errors/{validation_failure.xml.haml → 400.xml.haml} +0 -4
- data/views/errors/401.html.haml +41 -0
- data/views/errors/{auth_exception.xml.haml → 401.xml.haml} +0 -0
- data/views/errors/403.html.haml +42 -0
- data/views/errors/{not_allowed.xml.haml → 403.xml.haml} +0 -0
- data/views/errors/404.html.haml +29 -0
- data/views/errors/{not_found.xml.haml → 404.xml.haml} +1 -1
- data/views/errors/405.html.haml +29 -0
- data/views/errors/405.xml.haml +5 -0
- data/views/errors/500.html.haml +43 -0
- data/views/errors/500.xml.haml +5 -0
- data/views/errors/502.html.haml +43 -0
- data/views/errors/{backend_error.xml.haml → 502.xml.haml} +1 -2
- data/views/errors/backend_capability_failure.html.haml +27 -9
- data/views/firewalls/index.html.haml +15 -0
- data/views/firewalls/index.xml.haml +28 -0
- data/views/firewalls/new.html.haml +11 -0
- data/views/firewalls/new_rule.html.haml +20 -0
- data/views/firewalls/show.html.haml +42 -0
- data/views/firewalls/show.xml.haml +26 -0
- data/views/hardware_profiles/index.html.haml +15 -23
- data/views/hardware_profiles/show.html.haml +22 -18
- data/views/images/index.html.haml +11 -23
- data/views/images/index.xml.haml +4 -13
- data/views/images/new.html.haml +12 -13
- data/views/images/show.html.haml +26 -20
- data/views/images/show.xml.haml +2 -1
- data/views/instance_states/show.html.haml +21 -25
- data/views/instances/index.html.haml +13 -30
- data/views/instances/index.xml.haml +2 -23
- data/views/instances/new.html.haml +83 -88
- data/views/instances/show.html.haml +53 -55
- data/views/instances/show.xml.haml +12 -10
- data/views/keys/index.html.haml +13 -24
- data/views/keys/new.html.haml +7 -7
- data/views/keys/show.html.haml +26 -21
- data/views/layout.html.haml +28 -27
- data/views/load_balancers/index.html.haml +11 -31
- data/views/load_balancers/index.xml.haml +0 -1
- data/views/load_balancers/new.html.haml +1 -1
- data/views/load_balancers/show.html.haml +33 -34
- data/views/load_balancers/show.xml.haml +2 -2
- data/views/realms/index.html.haml +11 -24
- data/views/realms/index.xml.haml +2 -8
- data/views/realms/show.html.haml +17 -15
- data/views/realms/show.xml.haml +2 -1
- data/views/storage_snapshots/index.html.haml +11 -21
- data/views/storage_snapshots/index.xml.haml +2 -5
- data/views/storage_snapshots/new.html.haml +1 -1
- data/views/storage_snapshots/show.html.haml +21 -13
- data/views/storage_snapshots/show.xml.haml +2 -1
- data/views/storage_volumes/index.html.haml +11 -34
- data/views/storage_volumes/new.html.haml +1 -1
- data/views/storage_volumes/show.html.haml +33 -27
- data/views/storage_volumes/show.xml.haml +2 -1
- metadata +266 -178
- data/lib/sinatra/respond_to.rb +0 -248
- data/support/fedora/deltacloudd +0 -128
- data/support/fedora/rubygem-deltacloud-core.spec +0 -127
- data/views/accounts/index.html.haml +0 -11
- data/views/accounts/show.html.haml +0 -30
- data/views/errors/auth_exception.html.haml +0 -8
- data/views/errors/backend_error.html.haml +0 -22
- data/views/errors/not_allowed.html.haml +0 -6
- data/views/errors/not_found.html.haml +0 -6
- data/views/errors/validation_failure.html.haml +0 -11
@@ -1,46 +1,17 @@
|
|
1
|
-
---
|
2
|
-
:
|
3
|
-
:name: Gogrid
|
4
|
-
:mock:
|
5
|
-
:name: Mock
|
6
|
-
:rhevm:
|
7
|
-
:name: RHEVM
|
1
|
+
---
|
2
|
+
:ec2:
|
8
3
|
:entrypoints:
|
9
|
-
|
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:
|
4
|
+
s3:
|
34
5
|
us-west-1: s3-us-west-1.amazonaws.com
|
35
6
|
ap-southeast-1: s3-ap-southeast-1.amazonaws.com
|
36
7
|
eu-west-1: s3-eu-west-1.amazonaws.com
|
37
8
|
us-east-1: s3.amazonaws.com
|
38
|
-
elb:
|
9
|
+
elb:
|
39
10
|
us-west-1: elasticloadbalancing.us-west-1.amazonaws.com
|
40
11
|
ap-southeast-1: elasticloadbalancing.ap-southeast-1.amazonaws.com
|
41
12
|
eu-west-1: elasticloadbalancing.eu-west-1.amazonaws.com
|
42
13
|
us-east-1: elasticloadbalancing.us-east-1.amazonaws.com
|
43
|
-
ec2:
|
14
|
+
ec2:
|
44
15
|
us-west-1: ec2.us-west-1.amazonaws.com
|
45
16
|
ap-southeast-1: ec2.ap-southeast-1.amazonaws.com
|
46
17
|
eu-west-1: ec2.eu-west-1.amazonaws.com
|
data/deltacloud-core.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
which implements the REST interface.
|
30
30
|
EOF
|
31
31
|
|
32
|
-
s.version = '0.
|
32
|
+
s.version = '0.4.0'
|
33
33
|
s.date = Time.now
|
34
34
|
s.summary = %q{Deltacloud REST API}
|
35
35
|
s.files = FileList[
|
@@ -38,9 +38,13 @@ Gem::Specification.new do |s|
|
|
38
38
|
'config.ru',
|
39
39
|
'*.rb',
|
40
40
|
'log',
|
41
|
-
'config/drivers
|
41
|
+
'config/drivers/*.yaml',
|
42
|
+
'config/*.yaml',
|
43
|
+
'config/*.xml',
|
42
44
|
'tmp',
|
43
45
|
'support/fedora/**',
|
46
|
+
'support/condor/bash/**',
|
47
|
+
'support/condor/config/**',
|
44
48
|
'lib/**/*.rb',
|
45
49
|
'lib/**/*.yml',
|
46
50
|
'tests/**/*.rb',
|
@@ -49,6 +53,8 @@ Gem::Specification.new do |s|
|
|
49
53
|
'public/favicon.ico',
|
50
54
|
'public/images/*.png',
|
51
55
|
'public/javascripts/*.js',
|
56
|
+
'public/stylesheets/*.css',
|
57
|
+
'public/stylesheets/images/*.png',
|
52
58
|
'public/stylesheets/compiled/*.css',
|
53
59
|
'bin/deltacloudd'
|
54
60
|
].to_a
|
@@ -62,12 +68,14 @@ Gem::Specification.new do |s|
|
|
62
68
|
s.add_dependency('rake', '>= 0.8.7')
|
63
69
|
s.add_dependency('haml', '>= 2.2.17')
|
64
70
|
s.add_dependency('sinatra', '>= 0.9.4')
|
65
|
-
s.add_dependency('rack', '>= 1.0.0'
|
66
|
-
s.add_dependency('rack-accept'
|
71
|
+
s.add_dependency('rack', '>= 1.0.0')
|
72
|
+
s.add_dependency('rack-accept')
|
67
73
|
s.add_dependency('json', '>= 1.1.9')
|
68
74
|
s.add_dependency('net-ssh', '>= 2.0.0')
|
75
|
+
s.add_dependency('thin', '>= 1.2.5')
|
76
|
+
s.add_dependency('nokogiri', ">= 1.4.3")
|
69
77
|
s.add_development_dependency('compass', '>= 0.8.17')
|
70
|
-
s.add_development_dependency('nokogiri', '>= 1.4.1'
|
78
|
+
s.add_development_dependency('nokogiri', '>= 1.4.1')
|
71
79
|
s.add_development_dependency('rack-test', '>= 0.5.3')
|
72
80
|
s.add_development_dependency('cucumber', '>= 0.6.3')
|
73
81
|
s.add_development_dependency('rcov', '>= 0.9.8')
|
data/deltacloud.rb
CHANGED
@@ -23,19 +23,21 @@ require 'deltacloud/core_ext'
|
|
23
23
|
require 'deltacloud/base_driver'
|
24
24
|
require 'deltacloud/hardware_profile'
|
25
25
|
require 'deltacloud/state_machine'
|
26
|
-
|
26
|
+
require 'deltacloud/helpers'
|
27
27
|
require 'deltacloud/models/base_model'
|
28
28
|
require 'deltacloud/models/realm'
|
29
29
|
require 'deltacloud/models/image'
|
30
30
|
require 'deltacloud/models/instance'
|
31
31
|
require 'deltacloud/models/key'
|
32
|
+
require 'deltacloud/models/address'
|
32
33
|
require 'deltacloud/models/instance_profile'
|
33
34
|
require 'deltacloud/models/storage_snapshot'
|
34
35
|
require 'deltacloud/models/storage_volume'
|
35
36
|
require 'deltacloud/models/bucket'
|
36
37
|
require 'deltacloud/models/blob'
|
37
38
|
require 'deltacloud/models/load_balancer'
|
39
|
+
require 'deltacloud/models/firewall'
|
40
|
+
require 'deltacloud/models/firewall_rule'
|
38
41
|
|
39
42
|
require 'deltacloud/validation'
|
40
|
-
require 'deltacloud/helpers'
|
41
43
|
require 'deltacloud/runner'
|
@@ -18,7 +18,7 @@ module Deltacloud::BackendCapability
|
|
18
18
|
|
19
19
|
class Failure < StandardError
|
20
20
|
attr_reader :capability
|
21
|
-
|
21
|
+
|
22
22
|
def initialize(capability, msg='')
|
23
23
|
super(msg)
|
24
24
|
@capability = capability
|
@@ -26,7 +26,7 @@ module Deltacloud::BackendCapability
|
|
26
26
|
end
|
27
27
|
|
28
28
|
attr_reader :capability
|
29
|
-
|
29
|
+
|
30
30
|
def with_capability(capability)
|
31
31
|
@capability = capability
|
32
32
|
end
|
@@ -14,33 +14,18 @@
|
|
14
14
|
# License for the specific language governing permissions and limitations
|
15
15
|
# under the License.
|
16
16
|
|
17
|
+
require 'lib/deltacloud/base_driver/exceptions'
|
18
|
+
|
17
19
|
module Deltacloud
|
18
20
|
|
19
|
-
class
|
20
|
-
end
|
21
|
+
class BaseDriver
|
21
22
|
|
22
|
-
|
23
|
-
attr_reader :code, :cause, :details
|
24
|
-
def initialize(code, cause, message, details)
|
25
|
-
super(message)
|
26
|
-
@code = code
|
27
|
-
@cause = cause
|
28
|
-
@details = details
|
29
|
-
end
|
30
|
-
end
|
23
|
+
include ExceptionHandler
|
31
24
|
|
32
|
-
|
33
|
-
|
34
|
-
def initialize(code, cause, message, details)
|
35
|
-
super(message)
|
36
|
-
@code = code
|
37
|
-
@cause = cause
|
38
|
-
@details = details
|
25
|
+
def self.exceptions(&block)
|
26
|
+
ExceptionHandler::exceptions(&block)
|
39
27
|
end
|
40
|
-
end
|
41
28
|
|
42
|
-
class BaseDriver
|
43
|
-
|
44
29
|
def self.define_hardware_profile(name,&block)
|
45
30
|
@hardware_profiles ||= []
|
46
31
|
hw_profile = @hardware_profiles.find{|e| e.name == name}
|
@@ -151,7 +136,7 @@ module Deltacloud
|
|
151
136
|
# def storage_volumes(credentials, ops)
|
152
137
|
#
|
153
138
|
# def storage_snapshots(credentials, ops)
|
154
|
-
#
|
139
|
+
#
|
155
140
|
# def buckets(credentials, opts = nil)
|
156
141
|
# def create_bucket(credentials, name, opts=nil)
|
157
142
|
# def delete_bucket(credentials, name, opts=nil)
|
@@ -164,7 +149,12 @@ module Deltacloud
|
|
164
149
|
# def keys(credentials, opts)
|
165
150
|
# def create_key(credentials, opts)
|
166
151
|
# def destroy_key(credentials, opts)
|
167
|
-
|
152
|
+
#
|
153
|
+
# def firewalls(credentials, opts)
|
154
|
+
# def create_firewall(credentials, opts)
|
155
|
+
# def delete_firewall(credentials, opts)
|
156
|
+
# def create_firewall_rule(credentials, opts)
|
157
|
+
# def delete_firewall_rule(credentials, opts)
|
168
158
|
def realm(credentials, opts)
|
169
159
|
realms = realms(credentials, opts).first if has_capability?(:realms)
|
170
160
|
end
|
@@ -189,7 +179,7 @@ module Deltacloud
|
|
189
179
|
#list of objects within bucket
|
190
180
|
buckets(credentials, opts).first if has_capability?(:buckets)
|
191
181
|
end
|
192
|
-
|
182
|
+
|
193
183
|
def blob(credentials, opts = {})
|
194
184
|
blobs(credentials, opts).first if has_capability?(:blobs)
|
195
185
|
end
|
@@ -198,9 +188,13 @@ module Deltacloud
|
|
198
188
|
keys(credentials, opts).first if has_capability?(:keys)
|
199
189
|
end
|
200
190
|
|
191
|
+
def firewall(credentials, opts={})
|
192
|
+
firewalls(credentials, opts).first if has_capability?(:firewalls)
|
193
|
+
end
|
194
|
+
|
201
195
|
MEMBER_SHOW_METHODS =
|
202
|
-
[ :realm, :image, :instance, :storage_volume, :bucket, :blob, :key ]
|
203
|
-
|
196
|
+
[ :realm, :image, :instance, :storage_volume, :bucket, :blob, :key, :firewall ]
|
197
|
+
|
204
198
|
def has_capability?(capability)
|
205
199
|
if MEMBER_SHOW_METHODS.include?(capability.to_sym)
|
206
200
|
has_capability?(capability.to_s.pluralize)
|
@@ -208,8 +202,7 @@ module Deltacloud
|
|
208
202
|
respond_to?(capability)
|
209
203
|
end
|
210
204
|
end
|
211
|
-
|
212
|
-
|
205
|
+
|
213
206
|
def filter_on(collection, attribute, opts)
|
214
207
|
return collection if opts.nil?
|
215
208
|
return collection if opts[attribute].nil?
|
@@ -233,30 +226,8 @@ module Deltacloud
|
|
233
226
|
{ :error => [], :auth => [], :glob => [] }
|
234
227
|
end
|
235
228
|
|
236
|
-
def
|
237
|
-
|
238
|
-
block.call
|
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
|
250
|
-
catched_exceptions_list[:glob].each do |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
|
254
|
-
end
|
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)
|
259
|
-
end
|
229
|
+
def api_provider
|
230
|
+
Thread.current[:provider] || ENV['API_PROVIDER']
|
260
231
|
end
|
261
232
|
|
262
233
|
end
|
@@ -0,0 +1,168 @@
|
|
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
|
+
|
17
|
+
module Deltacloud
|
18
|
+
module ExceptionHandler
|
19
|
+
|
20
|
+
class DeltacloudException < StandardError
|
21
|
+
|
22
|
+
attr_accessor :code, :name, :message, :backtrace, :request
|
23
|
+
|
24
|
+
def initialize(code, name, message, backtrace, request=nil)
|
25
|
+
@code, @name, @message = code, name, message
|
26
|
+
@backtrace = backtrace
|
27
|
+
@request = request
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class AuthenticationFailure < DeltacloudException
|
34
|
+
def initialize(e, message=nil)
|
35
|
+
message ||= e.message
|
36
|
+
super(401, e.class.name, message, e.backtrace)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class UnknownMediaTypeError < DeltacloudException
|
41
|
+
def initialize(e, message=nil)
|
42
|
+
message ||= e.message
|
43
|
+
super(406, e.class.name, message, e.backtrace)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class MethodNotAllowed < DeltacloudException
|
48
|
+
def initialize(e, message=nil)
|
49
|
+
message ||= e.message
|
50
|
+
super(405, e.class.name, message, e.backtrace)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class ValidationFailure < DeltacloudException
|
55
|
+
def initialize(e, message=nil)
|
56
|
+
message ||= e.message
|
57
|
+
super(400, e.class.name, message, e.backtrace)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class BackendError < DeltacloudException
|
62
|
+
def initialize(e, message=nil)
|
63
|
+
message ||= e.message
|
64
|
+
super(500, e.class.name, message, e.backtrace, message)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class ProviderError < DeltacloudException
|
69
|
+
def initialize(e, message)
|
70
|
+
message ||= e.message
|
71
|
+
super(502, e.class.name, message, e.backtrace)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class ObjectNotFound < DeltacloudException
|
76
|
+
def initialize(e, message)
|
77
|
+
message ||= e.message
|
78
|
+
super(404, e.class.name, message, e.backtrace)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class ExceptionDef
|
83
|
+
attr_accessor :status
|
84
|
+
attr_accessor :message
|
85
|
+
attr_reader :conditions
|
86
|
+
attr_reader :handler
|
87
|
+
|
88
|
+
def initialize(conditions, &block)
|
89
|
+
@conditions = conditions
|
90
|
+
instance_eval(&block) if block_given?
|
91
|
+
end
|
92
|
+
|
93
|
+
def status(code)
|
94
|
+
self.status = code
|
95
|
+
end
|
96
|
+
|
97
|
+
def message(message)
|
98
|
+
self.message = message
|
99
|
+
end
|
100
|
+
|
101
|
+
def exception(handler)
|
102
|
+
self.handler = handler
|
103
|
+
end
|
104
|
+
|
105
|
+
# Condition can be class or regexp
|
106
|
+
#
|
107
|
+
def match?(e)
|
108
|
+
@conditions.each do |c|
|
109
|
+
return true if c.class == Class && e.class == c
|
110
|
+
return true if c.class == Regexp && (e.class.name =~ c or e.message =~ c)
|
111
|
+
end
|
112
|
+
return false
|
113
|
+
end
|
114
|
+
|
115
|
+
def handler(e)
|
116
|
+
return @handler if @handler
|
117
|
+
case @status
|
118
|
+
when 401 then Deltacloud::ExceptionHandler::AuthenticationFailure.new(e, @message)
|
119
|
+
when 404 then Deltacloud::ExceptionHandler::ObjectNotFound.new(e, @message)
|
120
|
+
when 406 then Deltacloud::ExceptionHandler::UnknownMediaTypeError.new(e, @message)
|
121
|
+
when 405 then Deltacloud::ExceptionHandler::MethodNotAllowed.new(e, @message)
|
122
|
+
when 400 then Deltacloud::ExceptionHandler::ValidationFailure.new(e, @message)
|
123
|
+
when 500 then Deltacloud::ExceptionHandler::BackendError.new(e, @message)
|
124
|
+
when 502 then Deltacloud::ExceptionHandler::ProviderError.new(e, @message)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
class Exceptions
|
131
|
+
attr_reader :exception_definitions
|
132
|
+
|
133
|
+
def initialize(&block)
|
134
|
+
@exception_definitions = []
|
135
|
+
instance_eval(&block) if block_given?
|
136
|
+
self
|
137
|
+
end
|
138
|
+
|
139
|
+
def on(*conditions, &block)
|
140
|
+
@exception_definitions << ExceptionDef::new(conditions, &block) if block_given?
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.exceptions(&block)
|
145
|
+
@definitions = Exceptions.new(&block).exception_definitions if block_given?
|
146
|
+
@definitions
|
147
|
+
end
|
148
|
+
|
149
|
+
def safely(&block)
|
150
|
+
begin
|
151
|
+
block.call
|
152
|
+
rescue
|
153
|
+
report_method = $stderr.respond_to?(:err) ? :err : :puts
|
154
|
+
Deltacloud::ExceptionHandler::exceptions.each do |exdef|
|
155
|
+
if exdef.match?($!)
|
156
|
+
$stderr.send(report_method, "#{[$!.class.to_s, $!.message].join(':')}\n#{$!.backtrace.join("\n")}")
|
157
|
+
new_exception = exdef.handler($!)
|
158
|
+
raise exdef.handler($!) if new_exception
|
159
|
+
end
|
160
|
+
end
|
161
|
+
$stderr.send(report_method, "[NO HANDLED] #{[$!.class.to_s, $!.message].join(': ')}\n#{$!.backtrace.join("\n")}")
|
162
|
+
raise Deltacloud::ExceptionHandler::BackendError.new($!, "Unhandled exception or status code (#{$!.message})")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|