deltacloud-core 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NOTICE +1 -1
- data/Rakefile +63 -21
- data/bin/deltacloudd +10 -6
- data/config.ru +62 -6
- data/config/drivers/ec2.yaml +8 -0
- data/config/drivers/fgcp.yaml +13 -0
- data/deltacloud-core.gemspec +10 -2
- data/lib/cimi/collections.rb +58 -0
- data/lib/cimi/collections/address_templates.rb +49 -0
- data/lib/cimi/collections/addresses.rb +74 -0
- data/lib/cimi/collections/cloud_entry_point.rb +37 -0
- data/lib/{deltacloud/helpers/conversion_helper.rb → cimi/collections/entity_metadata.rb} +24 -16
- data/lib/cimi/collections/machine_admins.rb +74 -0
- data/lib/cimi/collections/machine_configurations.rb +49 -0
- data/lib/cimi/collections/machine_images.rb +50 -0
- data/lib/cimi/collections/machines.rb +157 -0
- data/lib/cimi/collections/network_configurations.rb +47 -0
- data/lib/cimi/collections/network_templates.rb +48 -0
- data/lib/cimi/collections/networks.rb +125 -0
- data/lib/cimi/collections/routing_group_templates.rb +47 -0
- data/lib/cimi/collections/routing_groups.rb +48 -0
- data/lib/cimi/collections/volume_configurations.rb +48 -0
- data/lib/cimi/collections/volume_images.rb +50 -0
- data/lib/cimi/collections/volumes.rb +80 -0
- data/lib/cimi/collections/vsp_configurations.rb +48 -0
- data/lib/cimi/collections/vsp_templates.rb +50 -0
- data/lib/cimi/collections/vsps.rb +108 -0
- data/lib/cimi/dependencies.rb +1 -0
- data/lib/cimi/helpers.rb +116 -0
- data/lib/cimi/helpers/cimi_helper.rb +6 -2
- data/lib/cimi/models.rb +72 -0
- data/lib/cimi/{model → models}/action.rb +1 -1
- data/lib/cimi/models/address.rb +72 -0
- data/lib/cimi/models/address_collection.rb +34 -0
- data/lib/cimi/models/address_template.rb +54 -0
- data/lib/cimi/models/address_template_collection.rb +34 -0
- data/lib/cimi/{model → models}/base.rb +2 -2
- data/lib/cimi/{model → models}/cloud_entry_point.rb +3 -5
- data/lib/cimi/{model → models}/entity_metadata.rb +7 -6
- data/lib/cimi/{model → models}/entity_metadata_collection.rb +2 -2
- data/lib/cimi/{model → models}/errors.rb +8 -0
- data/lib/cimi/{model → models}/machine.rb +10 -10
- data/lib/cimi/{model → models}/machine_admin.rb +1 -1
- data/lib/cimi/{model → models}/machine_admin_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_configuration.rb +9 -6
- data/lib/cimi/{model → models}/machine_configuration_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_image.rb +1 -1
- data/lib/cimi/{model → models}/machine_image_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_template.rb +0 -0
- data/lib/cimi/{model → models}/machine_template_collection.rb +2 -2
- data/lib/cimi/models/network.rb +109 -0
- data/lib/cimi/{model → models}/network_collection.rb +2 -2
- data/lib/cimi/{model → models}/network_configuration.rb +3 -4
- data/lib/cimi/{model → models}/network_configuration_collection.rb +2 -2
- data/lib/cimi/models/network_template.rb +36 -0
- data/lib/cimi/models/network_template_collection.rb +35 -0
- data/lib/cimi/models/routing_group.rb +34 -0
- data/lib/cimi/models/routing_group_collection.rb +34 -0
- data/lib/cimi/models/routing_group_template.rb +34 -0
- data/lib/cimi/models/routing_group_template_collection.rb +35 -0
- data/lib/cimi/{model → models}/schema.rb +0 -0
- data/lib/cimi/{model → models}/volume.rb +4 -4
- data/lib/cimi/{model → models}/volume_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_configuration.rb +1 -1
- data/lib/cimi/{model → models}/volume_configuration_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_image.rb +1 -1
- data/lib/cimi/{model → models}/volume_image_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_template.rb +0 -0
- data/lib/cimi/{model → models}/volume_template_collection.rb +2 -2
- data/lib/cimi/models/vsp.rb +102 -0
- data/lib/cimi/models/vsp_collection.rb +34 -0
- data/lib/cimi/models/vsp_configuration.rb +40 -0
- data/lib/cimi/models/vsp_configuration_collection.rb +34 -0
- data/lib/cimi/models/vsp_template.rb +34 -0
- data/lib/cimi/models/vsp_template_collection.rb +34 -0
- data/lib/cimi/server.rb +27 -549
- data/lib/deltacloud/api.rb +79 -0
- data/lib/deltacloud/collections.rb +54 -0
- data/lib/deltacloud/collections/addresses.rb +91 -0
- data/lib/deltacloud/collections/buckets.rb +273 -0
- data/lib/deltacloud/collections/drivers.rb +51 -0
- data/lib/deltacloud/collections/firewalls.rb +116 -0
- data/lib/deltacloud/collections/hardware_profiles.rb +29 -0
- data/lib/deltacloud/collections/images.rb +73 -0
- data/lib/deltacloud/collections/instance_states.rb +59 -0
- data/lib/deltacloud/collections/instances.rb +113 -0
- data/lib/deltacloud/collections/keys.rb +61 -0
- data/lib/deltacloud/collections/load_balancers.rb +102 -0
- data/lib/deltacloud/collections/metrics.rb +28 -0
- data/lib/deltacloud/collections/realms.rb +28 -0
- data/lib/deltacloud/collections/storage_snapshots.rb +51 -0
- data/lib/deltacloud/collections/storage_volumes.rb +99 -0
- data/lib/deltacloud/core_ext.rb +14 -6
- data/lib/deltacloud/core_ext/string.rb +17 -5
- data/lib/deltacloud/drivers.rb +6 -42
- data/lib/deltacloud/drivers/azure/azure_driver.rb +0 -4
- data/lib/deltacloud/{base_driver → drivers}/base_driver.rb +56 -18
- data/lib/deltacloud/drivers/condor/condor_driver.rb +1 -8
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +142 -33
- data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +2 -6
- data/lib/deltacloud/{base_driver → drivers}/exceptions.rb +25 -2
- data/lib/deltacloud/drivers/features.rb +154 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +387 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1435 -0
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +8 -11
- data/lib/deltacloud/drivers/google/google_driver.rb +2 -5
- data/lib/deltacloud/drivers/mock/data/keys/test-key.yml +28 -0
- data/lib/deltacloud/drivers/mock/mock_client.rb +2 -2
- data/lib/deltacloud/drivers/mock/mock_driver.rb +58 -40
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +145 -0
- data/lib/deltacloud/drivers/opennebula/cloud_client.rb +107 -73
- data/lib/deltacloud/drivers/opennebula/occi_client.rb +285 -145
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +189 -126
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +427 -8
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +7 -9
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +48 -66
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +44 -51
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +7 -8
- data/lib/deltacloud/drivers/sbc/sbc_client.rb +1 -1
- data/lib/deltacloud/drivers/sbc/sbc_driver.rb +3 -3
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +8 -8
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +39 -13
- data/lib/deltacloud/drivers/vsphere/vsphere_filemanager.rb +1 -0
- data/lib/deltacloud/helpers.rb +79 -7
- data/lib/{sinatra/lazy_auth.rb → deltacloud/helpers/auth_helper.rb} +5 -9
- data/lib/deltacloud/helpers/{blob_stream.rb → blob_stream_helper.rb} +7 -7
- data/lib/deltacloud/helpers/deltacloud_helper.rb +286 -0
- data/lib/deltacloud/helpers/driver_helper.rb +58 -0
- data/lib/deltacloud/helpers/rabbit_helper.rb +34 -0
- data/lib/{sinatra/url_for.rb → deltacloud/helpers/url_helper.rb} +31 -9
- data/lib/deltacloud/models.rb +19 -17
- data/lib/deltacloud/models/bucket.rb +4 -0
- data/lib/deltacloud/{hardware_profile.rb → models/hardware_profile.rb} +4 -2
- data/lib/deltacloud/models/image.rb +1 -0
- data/lib/deltacloud/models/instance.rb +4 -2
- data/lib/deltacloud/models/instance_address.rb +4 -0
- data/lib/deltacloud/models/key.rb +4 -0
- data/lib/deltacloud/models/metric.rb +40 -0
- data/lib/deltacloud/{state_machine.rb → models/state_machine.rb} +18 -1
- data/lib/deltacloud/server.rb +41 -1222
- data/lib/deltacloud_rack.rb +79 -0
- data/lib/{cimi/model/network_template.rb → ec2/helpers.rb} +7 -10
- data/lib/{deltacloud/backend_capability.rb → ec2/helpers/errors.rb} +24 -29
- data/lib/ec2/helpers/result.rb +31 -0
- data/lib/ec2/query_parser.rb +152 -0
- data/lib/ec2/server.rb +70 -0
- data/lib/{deltacloud.rb → sinatra.rb} +7 -12
- data/lib/sinatra/rack_accept.rb +13 -7
- data/lib/sinatra/rack_driver_select.rb +1 -1
- data/lib/sinatra/rack_matrix_params.rb +1 -3
- data/public/images/metric.png +0 -0
- data/public/javascripts/jquery.mobile-1.0.1.min.js +177 -0
- data/public/stylesheets/jquery.mobile-1.0.1.min.css +2 -0
- data/public/stylesheets/new.css +10 -0
- data/support/fedora/deltacloud-core.spec +1 -1
- data/tests/api/common.rb +1 -0
- data/tests/api/driver_test.rb +79 -0
- data/tests/api/library_test.rb +48 -0
- data/tests/cimi/features/step_definitions/common_steps.rb +2 -2
- data/tests/cimi/features/step_definitions/machines_steps.rb +5 -4
- data/tests/cimi/features/step_definitions/volumes_steps.rb +8 -8
- data/tests/cimi/features/support/env.rb +33 -11
- data/tests/common.rb +7 -8
- data/tests/drivers/ec2/api_test.rb +19 -0
- data/tests/drivers/ec2/common.rb +23 -0
- data/tests/drivers/ec2/drivers_test.rb +120 -0
- data/tests/drivers/ec2/hardware_profiles_test.rb +224 -0
- data/tests/drivers/ec2/images_test.rb +230 -0
- data/tests/drivers/ec2/instances_test.rb +356 -0
- data/tests/drivers/ec2/keys_test.rb +181 -0
- data/tests/drivers/ec2/realms_test.rb +146 -0
- data/tests/drivers/fgcp/api_test.rb +47 -0
- data/tests/drivers/fgcp/hardware_profiles_test.rb +54 -0
- data/tests/drivers/fgcp/realms_test.rb +42 -0
- data/tests/drivers/{rackspace → fgcp}/setup.rb +5 -6
- data/tests/drivers/google/api_test.rb +10 -26
- data/tests/drivers/google/buckets_test.rb +79 -95
- data/tests/drivers/google/common.rb +54 -0
- data/tests/drivers/mock/api_test.rb +4 -127
- data/tests/drivers/mock/buckets_test.rb +195 -0
- data/tests/drivers/mock/common.rb +7 -0
- data/tests/drivers/mock/drivers_test.rb +123 -0
- data/tests/drivers/mock/hardware_profiles_test.rb +190 -100
- data/tests/drivers/mock/images_test.rb +162 -103
- data/tests/drivers/mock/instances_test.rb +310 -220
- data/tests/drivers/mock/keys_test.rb +161 -0
- data/tests/drivers/mock/realms_test.rb +109 -70
- data/tests/drivers/mock/storage_snapshots_test.rb +114 -0
- data/tests/drivers/mock/storage_volumes_test.rb +122 -0
- data/tests/drivers/openstack/api_test.rb +8 -3
- data/tests/drivers/openstack/common.rb +21 -0
- data/tests/drivers/openstack/hardware_profiles_test.rb +20 -9
- data/tests/drivers/openstack/images_test.rb +11 -5
- data/tests/drivers/openstack/instances_test.rb +61 -16
- data/tests/drivers/openstack/realms_test.rb +11 -7
- data/tests/drivers/rackspace/api_test.rb +7 -2
- data/tests/drivers/rackspace/buckets_test.rb +7 -2
- data/tests/drivers/rackspace/common.rb +16 -0
- data/tests/drivers/rackspace/hardware_profiles_test.rb +7 -2
- data/tests/drivers/rackspace/images_test.rb +7 -2
- data/tests/drivers/rackspace/instances_test.rb +10 -5
- data/tests/drivers/rackspace/realms_test.rb +7 -2
- data/tests/drivers/rhevm/api_test.rb +12 -6
- data/tests/drivers/rhevm/{setup.rb → common.rb} +8 -1
- data/tests/drivers/rhevm/hardware_profiles_test.rb +7 -2
- data/tests/drivers/rhevm/images_test.rb +8 -2
- data/tests/drivers/rhevm/instances_test.rb +7 -2
- data/tests/drivers/rhevm/realms_test.rb +7 -2
- data/tests/minitest_common.rb +58 -0
- data/tests/minitest_common_api_test.rb +115 -0
- data/views/addresses/associate.html.haml +1 -1
- data/views/addresses/index.html.haml +1 -1
- data/views/addresses/show.html.haml +2 -3
- data/views/api/show.html.haml +22 -9
- data/views/api/show.xml.haml +8 -7
- data/views/blobs/show.xml.haml +7 -4
- data/views/buckets/new.html.haml +2 -2
- data/views/cimi/errors/401.xml.haml +1 -1
- data/views/error.html.haml +3 -3
- data/views/errors/400.html.haml +1 -1
- data/views/errors/400.xml.haml +1 -2
- data/views/errors/401.html.haml +8 -7
- data/views/errors/401.xml.haml +1 -1
- data/views/errors/404.xml.haml +1 -0
- data/views/errors/500.xml.haml +4 -2
- data/views/{cimi/errors/403.html.haml → errors/501.html.haml} +4 -2
- data/views/errors/501.xml.haml +1 -0
- data/views/errors/502.xml.haml +1 -7
- data/views/{cimi/errors/500.html.haml → errors/504.html.haml} +0 -0
- data/views/errors/504.xml.haml +1 -0
- data/views/firewalls/new.html.haml +2 -2
- data/views/firewalls/new_rule.html.haml +1 -1
- data/views/firewalls/show.html.haml +1 -1
- data/views/hardware_profiles/index.html.haml +3 -1
- data/views/hardware_profiles/index.xml.haml +2 -2
- data/views/hardware_profiles/show.html.haml +3 -3
- data/views/hardware_profiles/show.xml.haml +3 -3
- data/views/images/show.html.haml +5 -0
- data/views/images/show.xml.haml +6 -1
- data/views/instance_states/show.html.haml +1 -1
- data/views/instances/index.html.haml +1 -1
- data/views/instances/new.html.haml +54 -39
- data/views/instances/run_command.html.haml +24 -15
- data/views/instances/show.html.haml +7 -3
- data/views/instances/show.xml.haml +2 -2
- data/views/keys/show.xml.haml +1 -0
- data/views/layout.html.haml +5 -9
- data/views/load_balancers/show.html.haml +12 -6
- data/views/metrics/index.html.haml +13 -0
- data/views/metrics/index.xml.haml +5 -0
- data/views/metrics/show.html.haml +23 -0
- data/views/metrics/show.xml.haml +9 -0
- data/views/realms/show.xml.haml +2 -1
- data/views/root/index.html.haml +1 -1
- data/views/storage_snapshots/show.html.haml +1 -1
- data/views/storage_snapshots/show.xml.haml +1 -0
- data/views/storage_volumes/attach.html.haml +1 -2
- data/views/storage_volumes/index.html.haml +1 -1
- data/views/storage_volumes/new.html.haml +22 -16
- data/views/storage_volumes/show.html.haml +10 -4
- data/views/storage_volumes/show.xml.haml +3 -4
- metadata +547 -519
- data/DISCLAIMER +0 -8
- data/lib/cimi/model.rb +0 -52
- data/lib/cimi/model/network.rb +0 -69
- data/lib/deltacloud/base_driver.rb +0 -18
- data/lib/deltacloud/base_driver/features.rb +0 -262
- data/lib/deltacloud/base_driver/mock_driver.rb +0 -78
- data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +0 -186
- data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +0 -521
- data/lib/deltacloud/helpers/application_helper.rb +0 -267
- data/lib/deltacloud/helpers/hardware_profiles_helper.rb +0 -50
- data/lib/deltacloud/helpers/json_helper.rb +0 -31
- data/lib/deltacloud/method_serializer.rb +0 -83
- data/lib/deltacloud/validation.rb +0 -107
- data/lib/sinatra/rabbit.rb +0 -441
- data/lib/sinatra/rack_runtime.rb +0 -47
- data/lib/sinatra/rack_syslog.rb +0 -86
- data/lib/sinatra/sinatra_verbose.rb +0 -73
- data/lib/sinatra/static_assets.rb +0 -99
- data/public/javascripts/jquery.mobile-1.0rc1.min.js +0 -170
- data/public/stylesheets/jquery.mobile-1.0rc1.min.css +0 -12
- data/tests/drivers/google/setup.rb +0 -38
- data/tests/drivers/mock/instance_states_test.rb +0 -71
- data/tests/drivers/mock/setup.rb +0 -3
- data/tests/drivers/mock/url_for_test.rb +0 -67
- data/tests/drivers/openstack/setup.rb +0 -20
- data/views/cimi/errors/400.html.haml +0 -41
- data/views/cimi/errors/401.html.haml +0 -41
- data/views/cimi/errors/404.html.haml +0 -29
- data/views/cimi/errors/405.html.haml +0 -29
- data/views/cimi/errors/502.html.haml +0 -43
- data/views/cimi/errors/backend_capability_failure.html.haml +0 -29
@@ -0,0 +1,79 @@
|
|
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
|
+
unless Kernel.respond_to?(:require_relative)
|
17
|
+
module Kernel
|
18
|
+
def require_relative(path)
|
19
|
+
require File.join(File.dirname(caller[0]), path.to_str)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require_relative './deltacloud/core_ext'
|
25
|
+
|
26
|
+
module Deltacloud
|
27
|
+
|
28
|
+
def self.config
|
29
|
+
@config ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.configure(frontend=:deltacloud, &block)
|
33
|
+
frontend = frontend.to_sym
|
34
|
+
config[frontend] = Server.new(&block)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.[](frontend=:deltacloud)
|
39
|
+
config[frontend.to_sym]
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.require_frontend!(frontend=:deltacloud)
|
43
|
+
frontend = frontend.to_sym
|
44
|
+
require File.join(File.dirname(__FILE__), frontend.to_s, 'server.rb')
|
45
|
+
Deltacloud[frontend].klass eval('::'+Deltacloud[frontend].klass)
|
46
|
+
end
|
47
|
+
|
48
|
+
class Server
|
49
|
+
|
50
|
+
attr_reader :root_url
|
51
|
+
attr_reader :version
|
52
|
+
attr_reader :klass
|
53
|
+
|
54
|
+
def initialize(opts={}, &block)
|
55
|
+
@root_url = opts[:root_url]
|
56
|
+
@version = opts[:version]
|
57
|
+
@klass = opts[:klass]
|
58
|
+
instance_eval(&block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def root_url(url=nil)
|
62
|
+
return @root_url if url.nil?
|
63
|
+
raise "[Core] The server URL must start with / (#{url})" unless url =~ /^\//
|
64
|
+
@root_url = url
|
65
|
+
end
|
66
|
+
|
67
|
+
def version(version=nil)
|
68
|
+
return @version if version.nil?
|
69
|
+
@version = version
|
70
|
+
end
|
71
|
+
|
72
|
+
def klass(k=nil)
|
73
|
+
return @klass if k.nil?
|
74
|
+
@klass = k
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -13,14 +13,11 @@
|
|
13
13
|
# License for the specific language governing permissions and limitations
|
14
14
|
# under the License.
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
href :network_config
|
19
|
-
|
20
|
-
href :routing_group
|
21
|
-
|
22
|
-
array :operations do
|
23
|
-
scalar :rel, :href
|
24
|
-
end
|
25
|
-
|
16
|
+
module Deltacloud
|
17
|
+
module EC2; end
|
26
18
|
end
|
19
|
+
|
20
|
+
require_relative './helpers/errors'
|
21
|
+
require_relative './helpers/result'
|
22
|
+
require_relative '../deltacloud/helpers/driver_helper'
|
23
|
+
require_relative '../deltacloud/helpers/auth_helper'
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#
|
2
1
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
3
2
|
# contributor license agreements. See the NOTICE file distributed with
|
4
3
|
# this work for additional information regarding copyright ownership. The
|
@@ -14,38 +13,34 @@
|
|
14
13
|
# License for the specific language governing permissions and limitations
|
15
14
|
# under the License.
|
16
15
|
|
17
|
-
module Deltacloud::
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
module Deltacloud::EC2
|
17
|
+
module Errors
|
18
|
+
|
19
|
+
def report_error(code)
|
20
|
+
error = (request.env['sinatra.error'] || @exception)
|
21
|
+
code = 500 if not code and not error.class.method_defined? :code
|
22
|
+
Nokogiri::XML::Builder.new do |xml|
|
23
|
+
xml.send(:Response) {
|
24
|
+
xml.send(:Errors) {
|
25
|
+
xml.send(:Code, error_for_code(code))
|
26
|
+
xml.send(:Message, error.respond_to?(:message) ? error.message : '')
|
27
|
+
}
|
28
|
+
xml.send(:RequestID, request_id)
|
29
|
+
}
|
30
|
+
end.to_xml
|
25
31
|
end
|
26
|
-
end
|
27
|
-
|
28
|
-
attr_reader :capability
|
29
|
-
|
30
|
-
def with_capability(capability)
|
31
|
-
@capability = capability
|
32
|
-
end
|
33
|
-
|
34
|
-
def has_capability?(backend)
|
35
|
-
!capability or backend.has_capability?(capability)
|
36
|
-
end
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
raise Failure.new(capability, "#{capability} capability not supported by backend #{backend.class.name}")
|
33
|
+
def request_id
|
34
|
+
Digest::MD5.hexdigest("#{request.env['REMOTE_ADDR']}#{request.env['HTTP_USER_AGENT']}#{Time.now.to_i}#{rand(250)}")
|
41
35
|
end
|
42
|
-
end
|
43
36
|
|
44
|
-
|
45
|
-
|
46
|
-
|
37
|
+
def error_for_code(code)
|
38
|
+
case code
|
39
|
+
when 401 then 'AuthFailure'
|
40
|
+
when 500 then 'InternalError'
|
41
|
+
else "Unavailable (#{code})"
|
42
|
+
end
|
47
43
|
end
|
48
|
-
end
|
49
44
|
|
50
|
-
|
45
|
+
end
|
51
46
|
end
|
@@ -0,0 +1,31 @@
|
|
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
|
+
module Deltacloud::EC2
|
17
|
+
module ResultHelper
|
18
|
+
|
19
|
+
def instance_state_code(state)
|
20
|
+
case state
|
21
|
+
when 'running' then '16'
|
22
|
+
when 'pending' then '0'
|
23
|
+
when 'stopping' then '64'
|
24
|
+
when 'stopped' then '80'
|
25
|
+
when 'shutting-down' then '32'
|
26
|
+
else '-1'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,152 @@
|
|
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
|
+
module Deltacloud::EC2
|
17
|
+
|
18
|
+
class ActionHandler
|
19
|
+
|
20
|
+
MAPPINGS = {
|
21
|
+
:describe_availability_zones => { :method => :realms, :params => { 'ZoneName.1' => :id } },
|
22
|
+
:describe_images => { :method => :images, :params => { 'ImageId.1' => :id }},
|
23
|
+
:describe_instances => { :method => :instances, :params => {} },
|
24
|
+
:describe_key_pairs => { :method => :keys, :params => {} },
|
25
|
+
:create_key_pair => { :method => :create_key, :params => { 'KeyName' => :key_name }},
|
26
|
+
:delete_key_pair => { :method => :destroy_key, :params => { 'KeyName' => :id }},
|
27
|
+
:run_instances => { :method => :create_instance, :params => { 'ImageId' => :image_id, 'InstanceType' => :hwp_id, 'Placement.AvailabilityZone' => :realm_id }},
|
28
|
+
:stop_instances => { :method => :stop_instance, :params => { 'InstanceId.1' => :id }},
|
29
|
+
:start_instances => { :method => :start_instance, :params => { 'InstanceId.1' => :id }},
|
30
|
+
:reboot_instances => { :method => :reboot_instance, :params => { 'InstanceId.1' => :id }},
|
31
|
+
:terminate_instances => { :method => :destroy_instance, :params => { 'InstanceId.1' => :id }},
|
32
|
+
}
|
33
|
+
|
34
|
+
attr_reader :action
|
35
|
+
|
36
|
+
def initialize(action)
|
37
|
+
@action = action
|
38
|
+
end
|
39
|
+
|
40
|
+
def deltacloud_method
|
41
|
+
MAPPINGS[action.action][:method]
|
42
|
+
end
|
43
|
+
|
44
|
+
def deltacloud_method_params
|
45
|
+
MAPPINGS[action.action][:params].inject({}) do |result, p|
|
46
|
+
result[p.last] = action.parameters.delete(p.first)
|
47
|
+
result.delete_if { |k,v| v.nil? }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def perform!(credentials, driver)
|
52
|
+
@result = case deltacloud_method
|
53
|
+
when :create_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:image_id), deltacloud_method_params)
|
54
|
+
when :stop_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
|
55
|
+
when :start_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
|
56
|
+
when :destroy_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
|
57
|
+
when :reboot_instance then driver.send(deltacloud_method, credentials, deltacloud_method_params.delete(:id))
|
58
|
+
else driver.send(deltacloud_method, credentials, deltacloud_method_params)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_xml(context)
|
63
|
+
ResultParser.parse(action, @result, context)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
class ResultParser
|
69
|
+
|
70
|
+
include ResultHelper
|
71
|
+
|
72
|
+
attr_reader :query
|
73
|
+
attr_reader :object
|
74
|
+
attr_reader :context
|
75
|
+
|
76
|
+
def self.parse(query, result, context)
|
77
|
+
parser = new(query, result, context)
|
78
|
+
layout = "%#{query.action.to_s.camelize}Response{:xmlns => 'http://ec2.amazonaws.com/doc/2012-04-01/'}\n"+
|
79
|
+
"\t%requestId #{query.request_id}\n" +
|
80
|
+
"\t=render(:#{query.action}, object)\n"
|
81
|
+
Haml::Engine.new(layout, :filename => 'layout').render(parser)
|
82
|
+
end
|
83
|
+
|
84
|
+
def initialize(query, object, context)
|
85
|
+
@context = context
|
86
|
+
@query = query
|
87
|
+
@object = object
|
88
|
+
end
|
89
|
+
|
90
|
+
def build_xml
|
91
|
+
Converter.convert(query.action, object)
|
92
|
+
end
|
93
|
+
|
94
|
+
def render(template, obj)
|
95
|
+
template_filename = File.join(File.dirname(__FILE__), 'views', '%s.haml' % template.to_s)
|
96
|
+
Haml::Engine.new(File.read(template_filename), :filename => template_filename).render(self, :object => obj)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
class QueryParser
|
102
|
+
|
103
|
+
class InvalidAction < StandardError; end
|
104
|
+
|
105
|
+
def self.parse(params, request_id)
|
106
|
+
parser = new(request_id, params)
|
107
|
+
unless parser.valid_action?
|
108
|
+
raise InvalidAction.new('Invalid action (%s)' % parser.action)
|
109
|
+
else
|
110
|
+
ActionHandler.new(parser)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
attr_reader :action
|
115
|
+
attr_reader :parameters
|
116
|
+
attr_reader :version
|
117
|
+
attr_reader :expiration
|
118
|
+
attr_reader :authentication
|
119
|
+
attr_reader :request_id
|
120
|
+
|
121
|
+
def initialize(request_id, params={})
|
122
|
+
@request_id = request_id
|
123
|
+
@action = (params.delete('Action') || 'Unknown').underscore.intern
|
124
|
+
@version = params.delete('Version')
|
125
|
+
@authentication = {
|
126
|
+
:security_token => params.delete('SecurityToken'),
|
127
|
+
:access_key_id => params.delete('AWSAccessKeyId'),
|
128
|
+
:signature => {
|
129
|
+
:version => params.delete('SignatureVersion'),
|
130
|
+
:value => params.delete('Signature'),
|
131
|
+
:method => params.delete('SignatureMethod'),
|
132
|
+
:timestamp => params.delete('Timestamp')
|
133
|
+
}
|
134
|
+
}
|
135
|
+
@expiration = params.delete('Expires')
|
136
|
+
@parameters = params
|
137
|
+
end
|
138
|
+
|
139
|
+
def valid_actions
|
140
|
+
ActionHandler::MAPPINGS.keys
|
141
|
+
end
|
142
|
+
|
143
|
+
def valid_action?
|
144
|
+
return false if @action == :unknown
|
145
|
+
return false unless valid_actions.include?(@action)
|
146
|
+
true
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
data/lib/ec2/server.rb
ADDED
@@ -0,0 +1,70 @@
|
|
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
|
+
require 'rubygems'
|
17
|
+
require 'sinatra/base'
|
18
|
+
require 'haml'
|
19
|
+
|
20
|
+
require_relative '../sinatra'
|
21
|
+
require_relative './helpers'
|
22
|
+
require_relative './query_parser'
|
23
|
+
require_relative '../deltacloud/models'
|
24
|
+
require_relative '../deltacloud/drivers'
|
25
|
+
|
26
|
+
module Deltacloud::EC2
|
27
|
+
class API < Sinatra::Base
|
28
|
+
|
29
|
+
extend Deltacloud::Helpers::Drivers
|
30
|
+
|
31
|
+
use Rack::ETag
|
32
|
+
use Rack::CommonLogger
|
33
|
+
|
34
|
+
helpers Sinatra::AuthHelper
|
35
|
+
helpers Deltacloud::Helpers::Drivers
|
36
|
+
helpers Deltacloud::EC2::Errors
|
37
|
+
|
38
|
+
enable :xhtml
|
39
|
+
enable :dump_errors
|
40
|
+
enable :show_errors
|
41
|
+
enable :method_override
|
42
|
+
disable :show_exceptions
|
43
|
+
|
44
|
+
set :version, Deltacloud[:ec2].version
|
45
|
+
set :root_url, Deltacloud[:ec2].root_url
|
46
|
+
set :root, File.join(File.dirname(__FILE__), '..', '..')
|
47
|
+
set :views, File.join(File.dirname(__FILE__), 'views')
|
48
|
+
|
49
|
+
error Deltacloud::EC2::QueryParser::InvalidAction do
|
50
|
+
status 400
|
51
|
+
haml :error, :locals => { :code => 'InvalidAction', :message => 'The requested action is not valid for this web service' }
|
52
|
+
end
|
53
|
+
|
54
|
+
after do
|
55
|
+
headers 'Server' => 'Apache-Deltacloud-EC2/' + settings.version
|
56
|
+
end
|
57
|
+
|
58
|
+
get '/' do
|
59
|
+
headers 'Connection' => 'close'
|
60
|
+
unless params['Action']
|
61
|
+
redirect settings.root_url, 301
|
62
|
+
halt
|
63
|
+
end
|
64
|
+
ec2_action = QueryParser.parse(params, request_id)
|
65
|
+
ec2_action.perform!(credentials, driver)
|
66
|
+
ec2_action.to_xml(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#
|
2
1
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
3
2
|
# contributor license agreements. See the NOTICE file distributed with
|
4
3
|
# this work for additional information regarding copyright ownership. The
|
@@ -14,14 +13,10 @@
|
|
14
13
|
# License for the specific language governing permissions and limitations
|
15
14
|
# under the License.
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
require 'deltacloud/helpers'
|
25
|
-
require 'deltacloud/models'
|
26
|
-
require 'deltacloud/validation'
|
27
|
-
require 'deltacloud/runner'
|
16
|
+
require_relative 'sinatra/body_proxy'
|
17
|
+
require_relative 'sinatra/rack_date'
|
18
|
+
require_relative 'sinatra/rack_etag'
|
19
|
+
require_relative 'sinatra/rack_matrix_params'
|
20
|
+
require_relative 'sinatra/rack_driver_select'
|
21
|
+
require_relative 'sinatra/accept_media_types'
|
22
|
+
require_relative 'sinatra/rack_accept'
|