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
@@ -14,14 +14,53 @@
|
|
14
14
|
# License for the specific language governing permissions and limitations
|
15
15
|
# under the License.
|
16
16
|
|
17
|
-
require 'deltacloud/base_driver/exceptions'
|
18
|
-
|
19
17
|
module Deltacloud
|
20
18
|
|
21
19
|
class BaseDriver
|
22
20
|
|
23
21
|
include ExceptionHandler
|
24
22
|
|
23
|
+
STATE_MACHINE_OPTS = {
|
24
|
+
:all_states => [:start, :pending, :running, :stopping, :stopped, :finish],
|
25
|
+
:all_actions => [:create, :reboot, :stop, :start, :destroy]
|
26
|
+
} unless defined?(STATE_MACHINE_OPTS)
|
27
|
+
|
28
|
+
def self.driver_name
|
29
|
+
name.split('::').last.gsub('Driver', '').downcase
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.features
|
33
|
+
@features ||= {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.features_for(entity)
|
37
|
+
features.inject([]) do |result, item|
|
38
|
+
result << item[entity] if item.has_key? entity
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.feature(collection, feature_name)
|
44
|
+
return if has_feature?(collection, feature_name)
|
45
|
+
constraints[collection] ||= {}
|
46
|
+
constraints[collection][feature_name] ||= {}
|
47
|
+
constraints[collection][feature_name].merge!(yield) if block_given?
|
48
|
+
features[collection] ||= []
|
49
|
+
features[collection] << feature_name
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.constraints(opts={})
|
53
|
+
if opts[:collection] and opts[:feature]
|
54
|
+
return [] unless @constraints.has_key? opts[:collection]
|
55
|
+
return @constraints[opts[:collection]][opts[:feature]]
|
56
|
+
end
|
57
|
+
@constraints ||= {}
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.has_feature?(collection, feature_name)
|
61
|
+
features.has_key?(collection) and features[collection].include?(feature_name)
|
62
|
+
end
|
63
|
+
|
25
64
|
def name
|
26
65
|
self.class.name.split('::').last.gsub('Driver', '').downcase
|
27
66
|
end
|
@@ -37,11 +76,12 @@ module Deltacloud
|
|
37
76
|
hw_profile = ::Deltacloud::HardwareProfile.new( name, &block )
|
38
77
|
@hardware_profiles << hw_profile
|
39
78
|
hw_params = hw_profile.params
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
79
|
+
# FIXME: Features
|
80
|
+
#unless hw_params.empty?
|
81
|
+
# feature :instances, :hardware_profiles do
|
82
|
+
# decl.operation(:create) { add_params(hw_params) }
|
83
|
+
# end
|
84
|
+
#end
|
45
85
|
end
|
46
86
|
|
47
87
|
def self.hardware_profiles
|
@@ -55,6 +95,7 @@ module Deltacloud
|
|
55
95
|
end
|
56
96
|
|
57
97
|
def hardware_profile(credentials, name)
|
98
|
+
name = name[:id] if name.kind_of? Hash
|
58
99
|
hardware_profiles(credentials, :id => name).first
|
59
100
|
end
|
60
101
|
|
@@ -90,7 +131,7 @@ module Deltacloud
|
|
90
131
|
end
|
91
132
|
|
92
133
|
def self.define_instance_states(&block)
|
93
|
-
machine = ::Deltacloud::StateMachine.new(&block)
|
134
|
+
machine = ::Deltacloud::StateMachine.new(STATE_MACHINE_OPTS, &block)
|
94
135
|
@instance_state_machine = machine
|
95
136
|
end
|
96
137
|
|
@@ -114,6 +155,11 @@ module Deltacloud
|
|
114
155
|
actions
|
115
156
|
end
|
116
157
|
|
158
|
+
def has_capability?(method)
|
159
|
+
method = (RUBY_VERSION =~ /^1\.9/) ? method : method.to_s
|
160
|
+
(self.class.instance_methods - self.class.superclass.instance_methods).include? method
|
161
|
+
end
|
162
|
+
|
117
163
|
## Capabilities
|
118
164
|
# The rabbit dsl supports declaring a capability that is required
|
119
165
|
# in the backend driver for the call to succeed. A driver can
|
@@ -197,16 +243,8 @@ module Deltacloud
|
|
197
243
|
firewalls(credentials, opts).first if has_capability?(:firewalls)
|
198
244
|
end
|
199
245
|
|
200
|
-
MEMBER_SHOW_METHODS =
|
201
|
-
|
202
|
-
|
203
|
-
def has_capability?(capability)
|
204
|
-
if MEMBER_SHOW_METHODS.include?(capability.to_sym)
|
205
|
-
has_capability?(capability.to_s.pluralize)
|
206
|
-
else
|
207
|
-
respond_to?(capability)
|
208
|
-
end
|
209
|
-
end
|
246
|
+
MEMBER_SHOW_METHODS = [ :realm, :image, :instance, :storage_volume, :bucket, :blob,
|
247
|
+
:key, :firewall ] unless defined?(MEMBER_SHOW_METHODS)
|
210
248
|
|
211
249
|
def filter_on(collection, attribute, opts)
|
212
250
|
return collection if opts.nil?
|
@@ -14,9 +14,6 @@
|
|
14
14
|
# under the License.
|
15
15
|
#
|
16
16
|
|
17
|
-
require 'deltacloud/base_driver'
|
18
|
-
|
19
|
-
|
20
17
|
class Instance
|
21
18
|
def self.convert_condor_state(state_id)
|
22
19
|
case state_id
|
@@ -44,10 +41,6 @@ module Deltacloud
|
|
44
41
|
feature :instances, :user_data
|
45
42
|
feature :instances, :authentication_password
|
46
43
|
|
47
|
-
def supported_collections
|
48
|
-
DEFAULT_COLLECTIONS - [ :storage_volumes, :storage_snapshots ]
|
49
|
-
end
|
50
|
-
|
51
44
|
CONDOR_MAPPER_DIR = ENV['CONDOR_MAPPER_DIR'] || '/var/tmp'
|
52
45
|
|
53
46
|
def hardware_profiles(credentials, opts={})
|
@@ -175,7 +168,7 @@ module Deltacloud
|
|
175
168
|
pending.to( :running ) .automatically
|
176
169
|
pending.to( :finish ) .on(:destroy)
|
177
170
|
running.to( :running ) .on( :reboot )
|
178
|
-
running.to( :
|
171
|
+
running.to( :stopping ) .on( :destroy )
|
179
172
|
pending.to( :finish ) .automatically
|
180
173
|
end
|
181
174
|
|
@@ -14,9 +14,10 @@
|
|
14
14
|
# under the License.
|
15
15
|
#
|
16
16
|
|
17
|
-
require 'deltacloud/base_driver'
|
18
17
|
require 'aws'
|
19
18
|
|
19
|
+
require_relative '../../runner'
|
20
|
+
|
20
21
|
class Instance
|
21
22
|
attr_accessor :keyname
|
22
23
|
attr_accessor :authn_error
|
@@ -29,19 +30,17 @@ end
|
|
29
30
|
|
30
31
|
module Deltacloud
|
31
32
|
module Drivers
|
32
|
-
module
|
33
|
-
class
|
34
|
-
|
35
|
-
def supported_collections
|
36
|
-
|
37
|
-
DEFAULT_COLLECTIONS + [ :keys, :buckets, :load_balancers, :addresses, :firewalls ]
|
38
|
-
end
|
33
|
+
module Ec2
|
34
|
+
class Ec2Driver < Deltacloud::BaseDriver
|
39
35
|
|
40
36
|
feature :instances, :user_data
|
41
37
|
feature :instances, :authentication_key
|
42
38
|
feature :instances, :firewalls
|
43
39
|
feature :instances, :instance_count
|
40
|
+
feature :instances, :metrics
|
44
41
|
feature :images, :owner_id
|
42
|
+
feature :images, :image_name
|
43
|
+
feature :images, :image_description
|
45
44
|
feature :buckets, :bucket_location
|
46
45
|
feature :instances, :attach_snapshot
|
47
46
|
|
@@ -49,7 +48,7 @@ module Deltacloud
|
|
49
48
|
|
50
49
|
define_hardware_profile('t1.micro') do
|
51
50
|
cpu 1
|
52
|
-
memory
|
51
|
+
memory 613
|
53
52
|
storage 160
|
54
53
|
architecture ['i386','x86_64']
|
55
54
|
end
|
@@ -58,7 +57,14 @@ module Deltacloud
|
|
58
57
|
cpu 1
|
59
58
|
memory 1.7 * 1024
|
60
59
|
storage 160
|
61
|
-
architecture 'i386'
|
60
|
+
architecture ['i386', 'x86_64']
|
61
|
+
end
|
62
|
+
|
63
|
+
define_hardware_profile('m1.medium') do
|
64
|
+
cpu 2
|
65
|
+
memory 3.75 * 1024
|
66
|
+
storage 410
|
67
|
+
architecture ['i386', 'x86_64']
|
62
68
|
end
|
63
69
|
|
64
70
|
define_hardware_profile('m1.large') do
|
@@ -79,7 +85,7 @@ module Deltacloud
|
|
79
85
|
cpu 5
|
80
86
|
memory 1.7 * 1024
|
81
87
|
storage 350
|
82
|
-
architecture 'i386'
|
88
|
+
architecture ['i386', 'x86_64']
|
83
89
|
end
|
84
90
|
|
85
91
|
define_hardware_profile('c1.xlarge') do
|
@@ -118,7 +124,8 @@ module Deltacloud
|
|
118
124
|
stopped.to( :running ) .on( :start )
|
119
125
|
running.to( :running ) .on( :reboot )
|
120
126
|
running.to( :stopping ) .on( :stop )
|
121
|
-
|
127
|
+
stopping.to(:stopped) .automatically
|
128
|
+
stopping.to(:finish) .automatically
|
122
129
|
stopped.to( :finish ) .automatically
|
123
130
|
end
|
124
131
|
|
@@ -132,10 +139,11 @@ module Deltacloud
|
|
132
139
|
ec2 = new_client(credentials)
|
133
140
|
img_arr = []
|
134
141
|
opts ||= {}
|
142
|
+
profiles = hardware_profiles(nil)
|
135
143
|
if opts[:id]
|
136
144
|
safely do
|
137
145
|
img_arr = ec2.describe_images([opts[:id]]).collect do |image|
|
138
|
-
convert_image(image)
|
146
|
+
convert_image(image, profiles)
|
139
147
|
end
|
140
148
|
end
|
141
149
|
return img_arr
|
@@ -143,7 +151,7 @@ module Deltacloud
|
|
143
151
|
owner_id = opts[:owner_id] || default_image_owner
|
144
152
|
safely do
|
145
153
|
img_arr = ec2.describe_images_by_owner([owner_id], default_image_type).collect do |image|
|
146
|
-
convert_image(image)
|
154
|
+
convert_image(image, profiles)
|
147
155
|
end
|
148
156
|
end
|
149
157
|
img_arr = filter_on( img_arr, :architecture, opts )
|
@@ -152,12 +160,19 @@ module Deltacloud
|
|
152
160
|
|
153
161
|
def realms(credentials, opts={})
|
154
162
|
ec2 = new_client(credentials)
|
155
|
-
|
163
|
+
realms = []
|
156
164
|
safely do
|
157
|
-
|
158
|
-
|
165
|
+
if opts[:id] and !opts[:id].empty?
|
166
|
+
ec2.describe_availability_zones([opts[:id]]).collect do |realm|
|
167
|
+
realms << convert_realm(realm) unless realm.empty?
|
168
|
+
end
|
169
|
+
else
|
170
|
+
ec2.describe_availability_zones.collect do |realm|
|
171
|
+
realms << convert_realm(realm) unless realm.empty?
|
172
|
+
end
|
159
173
|
end
|
160
174
|
end
|
175
|
+
realms
|
161
176
|
end
|
162
177
|
|
163
178
|
def create_image(credentials, opts={})
|
@@ -183,6 +198,7 @@ module Deltacloud
|
|
183
198
|
inst_arr = []
|
184
199
|
safely do
|
185
200
|
ec2_inst = ec2.describe_instances([opts[:id]]).first
|
201
|
+
raise "Instance #{opts[:id]} NotFound" if ec2_inst.nil?
|
186
202
|
instance = convert_instance(ec2_inst)
|
187
203
|
return nil unless instance
|
188
204
|
if ec2_inst[:aws_platform] == 'windows'
|
@@ -215,6 +231,9 @@ module Deltacloud
|
|
215
231
|
if opts[:user_data]
|
216
232
|
instance_options[:user_data] = Base64::decode64(opts[:user_data])
|
217
233
|
end
|
234
|
+
if opts[:metrics] and !opts[:metrics].empty?
|
235
|
+
instance_options[:monitoring_enabled] = true
|
236
|
+
end
|
218
237
|
instance_options[:key_name] = opts[:keyname] if opts[:keyname]
|
219
238
|
instance_options[:availability_zone] = opts[:realm_id] if opts[:realm_id]
|
220
239
|
instance_options[:instance_type] = opts[:hwp_id] if opts[:hwp_id] && opts[:hwp_id].length > 0
|
@@ -249,7 +268,7 @@ module Deltacloud
|
|
249
268
|
:username => 'root', # Default for EC2 Linux instances
|
250
269
|
}
|
251
270
|
param[:port] = opts[:port] || '22'
|
252
|
-
param[:ip] = target.public_addresses
|
271
|
+
param[:ip] = opts[:ip] || target.public_addresses.first.address
|
253
272
|
param[:private_key] = (opts[:private_key].length > 1) ? opts[:private_key] : nil
|
254
273
|
safely do
|
255
274
|
Deltacloud::Runner.execute(opts[:cmd], param)
|
@@ -276,11 +295,41 @@ module Deltacloud
|
|
276
295
|
|
277
296
|
alias :stop_instance :destroy_instance
|
278
297
|
|
298
|
+
def metrics(credentials, opts={})
|
299
|
+
cw = new_client(credentials, :mon)
|
300
|
+
metrics_arr = []
|
301
|
+
cw.list_metrics( :namespace => 'AWS/EC2' ).each do |metric|
|
302
|
+
if metrics_arr.any? { |m| m.id == metric[:value] }
|
303
|
+
i = metrics_arr.index { |m| m.id == metric[:value] }
|
304
|
+
metrics_arr[i] = metrics_arr[i].add_property(metric[:measure_name])
|
305
|
+
else
|
306
|
+
metrics_arr << convert_metric(metric)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
metrics_arr.reject! { |m| m.unknown? }
|
310
|
+
filter_on(metrics_arr, :id, opts)
|
311
|
+
end
|
312
|
+
|
313
|
+
def metric(credentials, opts={})
|
314
|
+
cw = new_client(credentials, :mon)
|
315
|
+
m = metrics(credentials, :id => opts[:id])
|
316
|
+
return [] if m.empty?
|
317
|
+
m = m.first
|
318
|
+
# Get statistics from last 1 hour
|
319
|
+
start_time = (Time.now - 3600).utc.iso8601.to_s
|
320
|
+
end_time = Time.now.utc.iso8601.to_s
|
321
|
+
m.properties.each do |p|
|
322
|
+
p.values = cw.get_metric_statistics(p.name, ['Minimum', 'Maximum', 'Average'],
|
323
|
+
start_time, end_time, metric_unit_for(p.name), { m.entity => opts[:id]})
|
324
|
+
end
|
325
|
+
m
|
326
|
+
end
|
327
|
+
|
279
328
|
def keys(credentials, opts={})
|
280
329
|
ec2 = new_client(credentials)
|
281
330
|
opts ||= {}
|
282
331
|
safely do
|
283
|
-
ec2.describe_key_pairs(opts[:id]
|
332
|
+
ec2.describe_key_pairs(opts[:id] ? [opts[:id]] : nil).collect do |key|
|
284
333
|
convert_key(key)
|
285
334
|
end
|
286
335
|
end
|
@@ -335,6 +384,7 @@ module Deltacloud
|
|
335
384
|
|
336
385
|
def destroy_load_balancer(credentials, id)
|
337
386
|
ec2 = new_client( credentials, :elb )
|
387
|
+
return 'InvalidLoadBalancer' if load_balancer(credentials, :id => id).nil?
|
338
388
|
safely do
|
339
389
|
ec2.delete_load_balancer(id)
|
340
390
|
end
|
@@ -361,7 +411,7 @@ module Deltacloud
|
|
361
411
|
safely do
|
362
412
|
s3_client = new_client(credentials, :s3)
|
363
413
|
unless (opts[:id].nil?)
|
364
|
-
bucket = s3_client
|
414
|
+
bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, opts[:id])
|
365
415
|
buckets << convert_bucket(bucket)
|
366
416
|
else
|
367
417
|
bucket_list = s3_client.buckets
|
@@ -399,7 +449,7 @@ module Deltacloud
|
|
399
449
|
s3_client = new_client(credentials, :s3)
|
400
450
|
blobs = []
|
401
451
|
safely do
|
402
|
-
s3_bucket = s3_client
|
452
|
+
s3_bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, opts['bucket'])
|
403
453
|
if(opts[:id])
|
404
454
|
blobs << convert_object(s3_bucket.key(opts[:id], true))
|
405
455
|
else
|
@@ -456,7 +506,8 @@ module Deltacloud
|
|
456
506
|
s3_client = new_client(credentials, :s3)
|
457
507
|
blob_meta = {}
|
458
508
|
safely do
|
459
|
-
|
509
|
+
the_bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, opts['bucket'])
|
510
|
+
the_blob = the_bucket.key(opts[:id], true)
|
460
511
|
blob_meta = the_blob.meta_headers
|
461
512
|
end
|
462
513
|
end
|
@@ -465,13 +516,15 @@ module Deltacloud
|
|
465
516
|
s3_client = new_client(credentials, :s3)
|
466
517
|
meta_hash = BlobHelper::rename_metadata_headers(opts['meta_hash'], '')
|
467
518
|
safely do
|
468
|
-
|
519
|
+
the_bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, opts['bucket'])
|
520
|
+
the_blob = the_bucket.key(opts[:id])
|
469
521
|
the_blob.save_meta(meta_hash)
|
470
522
|
end
|
471
523
|
end
|
472
524
|
|
473
525
|
def blob_data(credentials, bucket_id, blob_id, opts={})
|
474
526
|
s3_client = new_client(credentials, :s3)
|
527
|
+
bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, bucket_id)
|
475
528
|
safely do
|
476
529
|
s3_client.interface.get(bucket_id, blob_id) do |chunk|
|
477
530
|
yield chunk
|
@@ -704,7 +757,7 @@ module Deltacloud
|
|
704
757
|
def providers(credentials, opts={})
|
705
758
|
ec2 = new_client(credentials)
|
706
759
|
providers = ec2.describe_regions.map{|r| Provider.new( {:id=>r, :name=>r,
|
707
|
-
:url=>"#{ENV['API_HOST']}:#{ENV['API_PORT']}#{
|
760
|
+
:url=>"#{ENV['API_HOST']}:#{ENV['API_PORT']}#{Deltacloud[ENV['API_FRONTEND'] || :deltacloud].root_url}\;provider=#{r}" }) }
|
708
761
|
end
|
709
762
|
|
710
763
|
def configured_providers
|
@@ -712,23 +765,30 @@ module Deltacloud
|
|
712
765
|
end
|
713
766
|
|
714
767
|
def valid_credentials?(credentials)
|
715
|
-
retval = true
|
716
768
|
begin
|
717
|
-
realms(credentials)
|
718
|
-
rescue
|
719
|
-
|
769
|
+
realms(credentials) && true
|
770
|
+
rescue => e
|
771
|
+
if e.class.name =~ /AuthFailure/
|
772
|
+
retval = false
|
773
|
+
else
|
774
|
+
safely { raise e }
|
775
|
+
end
|
720
776
|
end
|
721
|
-
retval
|
722
777
|
end
|
723
778
|
|
724
779
|
private
|
725
|
-
def new_client(credentials, type = :ec2)
|
780
|
+
def new_client(credentials, type = :ec2, endpoint = nil)
|
726
781
|
klass = case type
|
727
782
|
when :elb then Aws::Elb
|
728
783
|
when :ec2 then Aws::Ec2
|
729
784
|
when :s3 then Aws::S3
|
785
|
+
when :mon then Aws::Mon
|
730
786
|
end
|
731
|
-
klass.new(credentials.user, credentials.password, {
|
787
|
+
klass.new(credentials.user, credentials.password, {
|
788
|
+
:server => endpoint || endpoint_for_service(type),
|
789
|
+
:connection_mode => :per_thread,
|
790
|
+
:logger => ENV['RACK_ENV'] == 'test' ? Logger.new('/dev/null') : Logger.new(STDOUT)
|
791
|
+
})
|
732
792
|
end
|
733
793
|
|
734
794
|
def default_image_owner
|
@@ -746,6 +806,16 @@ module Deltacloud
|
|
746
806
|
Deltacloud::Drivers::driver_config[:ec2][:entrypoints][service.to_s][endpoint] || endpoint
|
747
807
|
end
|
748
808
|
|
809
|
+
def get_bucket_with_endpoint(s3_client, credentials, s3_bucket_name)
|
810
|
+
s3_bucket = s3_client.bucket(s3_bucket_name)
|
811
|
+
endpoint_for_bucket = Deltacloud::Drivers::driver_config[:ec2][:entrypoints]["s3"]["#{s3_bucket.location}"]
|
812
|
+
if (s3_client.interface.params[:server] != endpoint_for_bucket)
|
813
|
+
s3_client = new_client(credentials, :s3, endpoint_for_bucket)
|
814
|
+
s3_bucket = s3_client.bucket(s3_bucket_name)
|
815
|
+
end
|
816
|
+
[s3_bucket, s3_client]
|
817
|
+
end
|
818
|
+
|
749
819
|
def convert_bucket(s3_bucket)
|
750
820
|
#get blob list:
|
751
821
|
blob_list = []
|
@@ -781,7 +851,7 @@ module Deltacloud
|
|
781
851
|
)
|
782
852
|
end
|
783
853
|
|
784
|
-
def convert_image(image)
|
854
|
+
def convert_image(image, profiles)
|
785
855
|
# There is not support for 'name' for now
|
786
856
|
Image.new(
|
787
857
|
:id => image[:aws_id],
|
@@ -789,6 +859,7 @@ module Deltacloud
|
|
789
859
|
:description => image[:aws_description] || image[:aws_location],
|
790
860
|
:owner_id => image[:aws_owner],
|
791
861
|
:architecture => image[:aws_architecture],
|
862
|
+
:hardware_profiles => image_profiles(image, profiles),
|
792
863
|
:state => image[:aws_state]
|
793
864
|
)
|
794
865
|
end
|
@@ -852,8 +923,16 @@ module Deltacloud
|
|
852
923
|
)
|
853
924
|
end
|
854
925
|
|
926
|
+
def image_profiles(image, profiles)
|
927
|
+
profiles = filter_hardware_profiles(profiles, :architecture => image[:aws_architecture])
|
928
|
+
if image[:aws_root_device_type] != 'ebs'
|
929
|
+
profiles.reject { |p| p.name == 't1.micro' }
|
930
|
+
else
|
931
|
+
profiles
|
932
|
+
end
|
933
|
+
end
|
934
|
+
|
855
935
|
def convert_load_balancer(credentials, loadbalancer)
|
856
|
-
puts loadbalancer.inspect
|
857
936
|
realms = []
|
858
937
|
balancer_realms = loadbalancer[:availability_zones].each do |zone|
|
859
938
|
realms << realm(credentials, zone)
|
@@ -951,6 +1030,24 @@ module Deltacloud
|
|
951
1030
|
} )
|
952
1031
|
end
|
953
1032
|
|
1033
|
+
def metric_unit_for(name)
|
1034
|
+
case name
|
1035
|
+
when /Bytes/ then 'Bytes'
|
1036
|
+
when /Ops/ then 'Count'
|
1037
|
+
when /Count/ then 'Count'
|
1038
|
+
when /Utilization/ then 'Percent'
|
1039
|
+
when /Network/ then 'Bytes'
|
1040
|
+
else 'None'
|
1041
|
+
end
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
def convert_metric(metric)
|
1045
|
+
Metric.new(
|
1046
|
+
:id => metric[:value],
|
1047
|
+
:entity => metric[:name] || :unknown
|
1048
|
+
).add_property(metric[:measure_name])
|
1049
|
+
end
|
1050
|
+
|
954
1051
|
def convert_state(ec2_state)
|
955
1052
|
case ec2_state
|
956
1053
|
when "terminated"
|
@@ -971,6 +1068,18 @@ module Deltacloud
|
|
971
1068
|
status 401
|
972
1069
|
end
|
973
1070
|
|
1071
|
+
on /(NotFound|InvalidInstanceID|InvalidAMIID|InvalidLoadBalancer|LoadBalancerNotFound)/ do
|
1072
|
+
status 404
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
on /Bad Request.*elasticloadbalancing/ do
|
1076
|
+
status 404
|
1077
|
+
end
|
1078
|
+
|
1079
|
+
on /Invalid availability zone/ do
|
1080
|
+
status 404
|
1081
|
+
end
|
1082
|
+
|
974
1083
|
on /Error/ do
|
975
1084
|
status 502
|
976
1085
|
end
|