deltacloud-core 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +40 -28
- data/bin/deltacloud-db-upgrade +24 -0
- data/bin/deltacloudd +20 -9
- data/config.ru +12 -53
- data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
- data/deltacloud-core.gemspec +11 -5
- data/lib/cimi/collections.rb +4 -31
- data/lib/cimi/collections/address_templates.rb +2 -5
- data/lib/cimi/collections/addresses.rb +2 -5
- data/lib/cimi/collections/base.rb +18 -6
- data/lib/cimi/collections/credentials.rb +2 -5
- data/lib/cimi/collections/machine_images.rb +2 -1
- data/lib/cimi/collections/machine_templates.rb +2 -5
- data/lib/cimi/collections/machines.rb +6 -9
- data/lib/cimi/collections/network_ports.rb +3 -3
- data/lib/cimi/collections/networks.rb +5 -8
- data/lib/cimi/collections/system_templates.rb +72 -0
- data/lib/cimi/collections/systems.rb +194 -0
- data/lib/cimi/collections/volume_configurations.rb +1 -1
- data/lib/cimi/collections/volume_images.rb +2 -1
- data/lib/cimi/collections/volume_templates.rb +3 -2
- data/lib/cimi/collections/volumes.rb +2 -2
- data/lib/cimi/dependencies.rb +0 -2
- data/lib/cimi/helpers/cimi_helper.rb +12 -57
- data/lib/cimi/helpers/database_helper.rb +0 -4
- data/lib/cimi/models.rb +25 -14
- data/lib/cimi/models/address.rb +4 -31
- data/lib/cimi/models/address_create.rb +51 -0
- data/lib/cimi/models/address_template.rb +8 -52
- data/lib/cimi/models/address_template_create.rb +44 -0
- data/lib/cimi/models/base.rb +44 -6
- data/lib/cimi/models/cloud_entry_point.rb +1 -1
- data/lib/cimi/models/credential.rb +1 -1
- data/lib/cimi/models/credential_create.rb +46 -0
- data/lib/cimi/models/credential_template.rb +24 -0
- data/lib/cimi/models/machine.rb +1 -71
- data/lib/cimi/models/machine_configuration.rb +3 -3
- data/lib/cimi/models/machine_create.rb +49 -0
- data/lib/cimi/models/machine_image.rb +2 -25
- data/lib/cimi/models/machine_image_create.rb +41 -0
- data/lib/cimi/models/machine_template.rb +14 -34
- data/lib/cimi/models/machine_template_create.rb +33 -0
- data/lib/cimi/models/network.rb +0 -38
- data/lib/cimi/models/network_create.rb +43 -0
- data/lib/cimi/models/network_port.rb +17 -17
- data/lib/cimi/models/network_template.rb +2 -3
- data/lib/cimi/models/resource.rb +22 -3
- data/lib/cimi/models/schema.rb +94 -8
- data/lib/cimi/models/system.rb +67 -0
- data/lib/cimi/models/system_template.rb +63 -0
- data/lib/cimi/models/volume.rb +2 -42
- data/lib/cimi/models/volume_configuration.rb +4 -4
- data/lib/cimi/models/volume_create.rb +58 -0
- data/lib/cimi/models/volume_image.rb +8 -17
- data/lib/cimi/models/volume_image_create.rb +47 -0
- data/lib/cimi/models/volume_template.rb +6 -19
- data/lib/cimi/models/volume_template_create.rb +33 -0
- data/lib/db.rb +14 -22
- data/lib/db/volume_template.rb +1 -1
- data/lib/deltacloud/api.rb +6 -5
- data/lib/deltacloud/collections.rb +4 -27
- data/lib/deltacloud/collections/base.rb +4 -0
- data/lib/deltacloud/collections/images.rb +1 -1
- data/lib/deltacloud/collections/instances.rb +2 -2
- data/lib/deltacloud/core_ext/array.rb +1 -0
- data/lib/deltacloud/core_ext/integer.rb +13 -9
- data/lib/deltacloud/core_ext/string.rb +45 -28
- data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
- data/lib/deltacloud/drivers/base_driver.rb +45 -16
- data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
- data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
- data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
- data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
- data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
- data/lib/deltacloud/helpers/collection_helper.rb +106 -0
- data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
- data/lib/deltacloud/models/address.rb +19 -17
- data/lib/deltacloud/models/base_model.rb +29 -26
- data/lib/deltacloud/models/blob.rb +22 -20
- data/lib/deltacloud/models/bucket.rb +21 -16
- data/lib/deltacloud/models/firewall.rb +18 -16
- data/lib/deltacloud/models/firewall_rule.rb +22 -20
- data/lib/deltacloud/models/image.rb +29 -28
- data/lib/deltacloud/models/instance.rb +92 -94
- data/lib/deltacloud/models/instance_address.rb +42 -40
- data/lib/deltacloud/models/instance_profile.rb +28 -26
- data/lib/deltacloud/models/key.rb +47 -45
- data/lib/deltacloud/models/load_balancer.rb +32 -31
- data/lib/deltacloud/models/metric.rb +76 -29
- data/lib/deltacloud/models/provider.rb +15 -13
- data/lib/deltacloud/models/realm.rb +15 -21
- data/lib/deltacloud/models/storage_snapshot.rb +23 -19
- data/lib/deltacloud/models/storage_volume.rb +35 -34
- data/lib/deltacloud/version.rb +1 -1
- data/lib/deltacloud_rack.rb +22 -0
- data/lib/initialize.rb +28 -0
- data/lib/initializers/database_initialize.rb +76 -0
- data/lib/initializers/frontend_initialize.rb +42 -0
- data/lib/initializers/mock_initialize.rb +33 -0
- data/lib/sinatra/rack_logger.rb +35 -24
- data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
- data/tests/cimi/collections/machine_images_test.rb +2 -2
- data/tests/cimi/collections/machine_templates_test.rb +75 -0
- data/tests/cimi/collections/machines_test.rb +2 -2
- data/tests/cimi/collections/system_templates_test.rb +41 -0
- data/tests/cimi/collections/systems_test.rb +50 -0
- data/tests/cimi/db/database_helper_test.rb +17 -25
- data/tests/cimi/db/db_helper.rb +1 -12
- data/tests/cimi/db/entity_test.rb +7 -8
- data/tests/cimi/model/machine_create_spec.rb +44 -0
- data/tests/cimi/model/machine_template_spec.rb +29 -0
- data/tests/cimi/model/resource_spec.rb +40 -0
- data/tests/cimi/model/schema_spec.rb +37 -0
- data/tests/cimi/spec_helper.rb +3 -0
- data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
- data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
- data/tests/deltacloud/collections/images_collection_test.rb +2 -2
- data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
- data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
- data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
- data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
- data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
- data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
- data/tests/deltacloud/collections_test.rb +5 -5
- data/tests/deltacloud/common.rb +2 -13
- data/tests/deltacloud/launcher_test.rb +3 -3
- data/tests/deltacloud/rack_test.rb +2 -2
- data/tests/deltacloud/server_test.rb +1 -1
- data/tests/drivers/base/base_driver_test.rb +5 -5
- data/tests/drivers/base/common.rb +2 -12
- data/tests/drivers/ec2/buckets_test.rb +1 -1
- data/tests/drivers/ec2/images_test.rb +2 -2
- data/tests/drivers/ec2/instance_test.rb +6 -6
- data/tests/drivers/ec2/keys_test.rb +3 -3
- data/tests/drivers/ec2/realms_test.rb +2 -2
- data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
- data/tests/drivers/fgcp/common.rb +32 -0
- data/tests/drivers/fgcp/firewall_test.rb +70 -0
- data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
- data/tests/drivers/fgcp/images_test.rb +46 -0
- data/tests/drivers/fgcp/provider_test.rb +27 -0
- data/tests/drivers/fgcp/realms_test.rb +53 -0
- data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
- data/tests/drivers/gogrid/images_test.rb +2 -2
- data/tests/drivers/gogrid/instances_test.rb +2 -2
- data/tests/drivers/gogrid/realms_test.rb +2 -2
- data/tests/drivers/mock/images_test.rb +4 -4
- data/tests/drivers/mock/instances_test.rb +9 -9
- data/tests/drivers/mock/keys_test.rb +3 -3
- data/tests/drivers/mock/realms_test.rb +2 -2
- data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
- data/tests/drivers/mock/storage_volumes_test.rb +4 -4
- data/tests/drivers/models/instance_test.rb +2 -2
- data/tests/drivers/openstack/images_test.rb +2 -2
- data/tests/drivers/openstack/instances_test.rb +2 -3
- data/tests/drivers/openstack/keys_test.rb +1 -1
- data/tests/drivers/openstack/realms_test.rb +2 -11
- data/tests/drivers/rhevm/common.rb +33 -12
- data/tests/drivers/rhevm/images_test.rb +20 -12
- data/tests/drivers/rhevm/instance_test.rb +62 -46
- data/tests/drivers/rhevm/provider_test.rb +12 -6
- data/tests/drivers/rhevm/realms_test.rb +15 -9
- data/tests/ec2/query_parser_test.rb +1 -1
- data/tests/test_helper.rb +68 -12
- data/views/addresses/show.html.haml +1 -1
- data/views/buckets/show.html.haml +1 -1
- data/views/errors/{500.html.haml → common.html.haml} +0 -0
- data/views/errors/common.xml.haml +17 -0
- data/views/firewalls/index.xml.haml +2 -2
- data/views/firewalls/new.html.haml +2 -2
- data/views/images/show.html.haml +1 -1
- data/views/instances/run_command.html.haml +1 -1
- data/views/instances/show.html.haml +3 -3
- data/views/keys/index.html.haml +1 -0
- data/views/keys/show.html.haml +8 -4
- data/views/keys/show.xml.haml +3 -2
- data/views/load_balancers/new.html.haml +1 -1
- data/views/load_balancers/show.html.haml +2 -2
- data/views/metrics/show.html.haml +1 -1
- data/views/realms/index.html.haml +0 -2
- data/views/realms/show.html.haml +0 -4
- data/views/realms/show.xml.haml +0 -3
- data/views/storage_snapshots/index.html.haml +1 -1
- data/views/storage_snapshots/new.html.haml +1 -1
- data/views/storage_volumes/new.html.haml +2 -2
- data/views/storage_volumes/show.html.haml +3 -3
- metadata +90 -41
- data/views/errors/400.html.haml +0 -41
- data/views/errors/400.xml.haml +0 -3
- data/views/errors/401.html.haml +0 -26
- data/views/errors/401.xml.haml +0 -3
- data/views/errors/403.html.haml +0 -42
- data/views/errors/403.xml.haml +0 -9
- data/views/errors/404.html.haml +0 -28
- data/views/errors/404.xml.haml +0 -3
- data/views/errors/405.html.haml +0 -29
- data/views/errors/405.xml.haml +0 -5
- data/views/errors/409.html.haml +0 -47
- data/views/errors/409.xml.haml +0 -11
- data/views/errors/500.xml.haml +0 -13
- data/views/errors/501.html.haml +0 -44
- data/views/errors/501.xml.haml +0 -1
- data/views/errors/502.html.haml +0 -44
- data/views/errors/502.xml.haml +0 -1
- data/views/errors/504.html.haml +0 -43
- data/views/errors/504.xml.haml +0 -1
@@ -23,7 +23,7 @@ module Deltacloud::Collections
|
|
23
23
|
|
24
24
|
new_route_for :images do
|
25
25
|
halt 404 unless params[:instance_id]
|
26
|
-
@instance = Instance.new( :id => params[:instance_id] )
|
26
|
+
@instance = Deltacloud::Instance.new( :id => params[:instance_id] )
|
27
27
|
end
|
28
28
|
|
29
29
|
collection :images do
|
@@ -22,10 +22,10 @@ module Deltacloud::Collections
|
|
22
22
|
check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
|
23
23
|
|
24
24
|
new_route_for(:instances) do
|
25
|
-
@instance = Instance.new( { :id=>params[:id], :image_id=>params[:image_id] } )
|
25
|
+
@instance = Deltacloud::Instance.new( { :id=>params[:id], :image_id=>params[:image_id] } )
|
26
26
|
@image = driver.image(credentials, :id => params[:image_id])
|
27
27
|
@hardware_profiles = driver.hardware_profiles(credentials, :architecture => @image.architecture )
|
28
|
-
@realms = [Realm.new(:id => params[:realm_id])] if params[:realm_id]
|
28
|
+
@realms = [Deltacloud::Realm.new(:id => params[:realm_id])] if params[:realm_id]
|
29
29
|
@realms ||= driver.realms(credentials)
|
30
30
|
@firewalls = driver.firewalls(credentials) if driver.class.has_feature? :instances, :firewalls
|
31
31
|
@keys = driver.keys(credentials) if driver.class.has_feature? :instances, :authentication_key
|
@@ -15,17 +15,21 @@
|
|
15
15
|
# under the License.
|
16
16
|
|
17
17
|
class Integer
|
18
|
+
|
18
19
|
# Turn integers into strings +1st+, +2nd+, +3rd+ etc.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
unless method_defined? 'ordinalize'
|
21
|
+
def ordinalize
|
22
|
+
if (11..13).include?(self % 100)
|
23
|
+
"#{self}th"
|
24
|
+
else
|
25
|
+
case self % 10
|
26
|
+
when 1; "#{self}st"
|
27
|
+
when 2; "#{self}nd"
|
28
|
+
when 3; "#{self}rd"
|
29
|
+
else "#{self}th"
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
34
|
+
|
31
35
|
end
|
@@ -15,10 +15,13 @@
|
|
15
15
|
# under the License.
|
16
16
|
|
17
17
|
class String
|
18
|
+
|
18
19
|
# Rails defines this for a number of other classes, including Object
|
19
20
|
# see activesupport/lib/active_support/core_ext/object/blank.rb
|
20
|
-
|
21
|
+
unless method_defined? 'blank?'
|
22
|
+
def blank?
|
21
23
|
self !~ /\S/
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
# Title case.
|
@@ -28,49 +31,63 @@ class String
|
|
28
31
|
#
|
29
32
|
# CREDIT: Eliazar Parra
|
30
33
|
# Copied from facets
|
31
|
-
|
32
|
-
|
34
|
+
unless method_defined? 'titlecase'
|
35
|
+
def titlecase
|
36
|
+
gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
unless method_defined? 'pluralize'
|
41
|
+
def pluralize
|
42
|
+
return self + 'es' if self =~ /ess$/
|
43
|
+
return self[0, self.length-1] + "ies" if self =~ /ty$/
|
44
|
+
return self if self =~ /data$/
|
45
|
+
self + "s"
|
46
|
+
end
|
40
47
|
end
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
unless method_defined? 'singularize'
|
50
|
+
def singularize
|
51
|
+
return self.gsub(/ies$/, 'y') if self =~ /ies$/
|
52
|
+
return self.gsub(/es$/, '') if self =~ /sses$/
|
53
|
+
self.gsub(/s$/, '')
|
54
|
+
end
|
46
55
|
end
|
47
56
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
57
|
+
unless method_defined? 'underscore'
|
58
|
+
def underscore
|
59
|
+
return self.downcase if self =~ /VSPs$/i
|
60
|
+
gsub(/::/, '/').
|
61
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
62
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
63
|
+
tr("-", "_").
|
64
|
+
downcase
|
65
|
+
end
|
55
66
|
end
|
56
67
|
|
57
|
-
|
58
|
-
|
59
|
-
|
68
|
+
unless method_defined? 'camelize'
|
69
|
+
def camelize(lowercase_first_letter=nil)
|
70
|
+
s = split('_').map { |w| w.capitalize }.join
|
71
|
+
lowercase_first_letter ? s.uncapitalize : s
|
72
|
+
end
|
60
73
|
end
|
61
74
|
|
62
|
-
|
63
|
-
|
75
|
+
unless method_defined? 'uncapitalize'
|
76
|
+
def uncapitalize
|
77
|
+
self[0, 1].downcase + self[1..-1]
|
78
|
+
end
|
64
79
|
end
|
65
80
|
|
66
81
|
def upcase_first
|
67
82
|
self[0, 1].upcase + self[1..-1]
|
68
83
|
end
|
69
84
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
85
|
+
unless method_defined? 'truncate'
|
86
|
+
def truncate(length = 10)
|
87
|
+
return self if self.length <= length
|
88
|
+
end_string = "...#{self[(self.length-(length/2))..self.length]}"
|
89
|
+
"#{self[0..(length/2)]}#{end_string}"
|
90
|
+
end
|
74
91
|
end
|
75
92
|
|
76
93
|
def remove_matrix_params
|
@@ -61,15 +61,6 @@ class ArubacloudDriver < Deltacloud::BaseDriver
|
|
61
61
|
architecture ['x86_64', 'i386']
|
62
62
|
end
|
63
63
|
|
64
|
-
def valid_credentials?(credentials)
|
65
|
-
begin
|
66
|
-
new_client(credentials)
|
67
|
-
rescue
|
68
|
-
return false
|
69
|
-
end
|
70
|
-
true
|
71
|
-
end
|
72
|
-
|
73
64
|
def realms(credentials, opts=nil)
|
74
65
|
client = new_client(credentials)
|
75
66
|
safely do
|
@@ -25,6 +25,7 @@ module Deltacloud
|
|
25
25
|
class BaseDriver
|
26
26
|
|
27
27
|
include Exceptions
|
28
|
+
include Deltacloud
|
28
29
|
|
29
30
|
STATE_MACHINE_OPTS = {
|
30
31
|
:all_states => [:start, :pending, :running, :stopping, :stopped, :finish, :error],
|
@@ -39,13 +40,15 @@ module Deltacloud
|
|
39
40
|
@features ||= {}
|
40
41
|
end
|
41
42
|
|
42
|
-
def self.feature(collection,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
def self.feature(collection, *feature_list)
|
44
|
+
feature_list.each do |feature_name|
|
45
|
+
next if has_feature?(collection, feature_name)
|
46
|
+
constraints[collection] ||= {}
|
47
|
+
constraints[collection][feature_name] ||= {}
|
48
|
+
constraints[collection][feature_name].merge!(yield) if block_given?
|
49
|
+
features[collection] ||= []
|
50
|
+
features[collection] << feature_name
|
51
|
+
end
|
49
52
|
end
|
50
53
|
|
51
54
|
def self.constraints(opts={})
|
@@ -144,7 +147,7 @@ module Deltacloud
|
|
144
147
|
end
|
145
148
|
|
146
149
|
def has_capability?(method)
|
147
|
-
method = (RUBY_VERSION
|
150
|
+
method = (RUBY_VERSION < '1.9') ? method.to_s : method
|
148
151
|
# Prevent has_capability fail when driver is inherited from another
|
149
152
|
# driver, like Eucalyptus
|
150
153
|
superclass_methods = self.class.superclass.name == 'Deltacloud::BaseDriver' ?
|
@@ -154,7 +157,7 @@ module Deltacloud
|
|
154
157
|
|
155
158
|
def supported_collections(credentials)
|
156
159
|
collection_arr = []
|
157
|
-
Deltacloud::Collections.
|
160
|
+
Deltacloud::Collections.modules(:deltacloud).each do |m|
|
158
161
|
m.collections.each do |c|
|
159
162
|
# Get the required capability for the :index operation (like 'realms' or 'instance_state_machine')
|
160
163
|
index_operation_capability = c.operation(:index).required_capability
|
@@ -260,15 +263,29 @@ module Deltacloud
|
|
260
263
|
MEMBER_SHOW_METHODS = [ :realm, :image, :instance, :storage_volume, :bucket, :blob,
|
261
264
|
:key, :firewall ] unless defined?(MEMBER_SHOW_METHODS)
|
262
265
|
|
263
|
-
def filter_on(collection,
|
266
|
+
def filter_on(collection, opts, *attributes)
|
267
|
+
opts, attributes = attributes.pop, [opts] if !opts.nil? and !(opts.is_a?(Hash))
|
268
|
+
# FIXME: ^^ This is just to keep backward compatibility until
|
269
|
+
# drivers will be fixed to use the new syntax.
|
270
|
+
#
|
271
|
+
# filter_on instances, :opts, [ :id, :state, :realm_id]
|
272
|
+
#
|
273
|
+
# instead of old:
|
274
|
+
#
|
275
|
+
# filter_on instances, :id, opts
|
276
|
+
# filter_on instances, :state, opts
|
277
|
+
# filter_on instances, :realm_id, opts
|
278
|
+
|
264
279
|
return collection if opts.nil?
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
280
|
+
attributes.each do |attribute|
|
281
|
+
next unless filter = opts[attribute]
|
282
|
+
if ( filter.is_a?( Array ) )
|
283
|
+
collection.select! { |e| filter.include?( e.send(attribute) ) }
|
284
|
+
else
|
285
|
+
collection.select! { |e| filter == e.send(attribute) }
|
286
|
+
end
|
271
287
|
end
|
288
|
+
collection
|
272
289
|
end
|
273
290
|
|
274
291
|
def catched_exceptions_list
|
@@ -284,6 +301,18 @@ module Deltacloud
|
|
284
301
|
def configured_providers
|
285
302
|
[]
|
286
303
|
end
|
304
|
+
|
305
|
+
def valid_credentials?(credentials)
|
306
|
+
begin
|
307
|
+
new_client(credentials)
|
308
|
+
rescue Deltacloud::Exceptions::AuthenticationFailure
|
309
|
+
return false
|
310
|
+
rescue => e
|
311
|
+
safely { raise e }
|
312
|
+
end
|
313
|
+
true
|
314
|
+
end
|
315
|
+
|
287
316
|
end
|
288
317
|
|
289
318
|
end
|
@@ -20,7 +20,7 @@ module Deltacloud
|
|
20
20
|
module Digitalocean
|
21
21
|
class DigitaloceanDriver < Deltacloud::BaseDriver
|
22
22
|
|
23
|
-
feature :instances, :user_name
|
23
|
+
feature :instances, :user_name, :authentication_key
|
24
24
|
feature :images, :owner_id
|
25
25
|
|
26
26
|
define_instance_states do
|
@@ -30,6 +30,7 @@ module Deltacloud
|
|
30
30
|
running.to( :stopping ) .on( :stop )
|
31
31
|
running.to( :finish ) .on( :destroy )
|
32
32
|
stopped.to( :running ) .on( :start )
|
33
|
+
stopped.to( :finish) .on( :destroy )
|
33
34
|
stopping.to( :stopped ) .automatically
|
34
35
|
stopped.to( :finish ) .automatically
|
35
36
|
error.from(:running, :pending, :stopping)
|
@@ -45,7 +46,7 @@ module Deltacloud
|
|
45
46
|
size = do_client.get("sizes/#{opts[:id]}")["size"]
|
46
47
|
results << hardware_profile_from(size)
|
47
48
|
else
|
48
|
-
|
49
|
+
do_client.get("sizes")["sizes"].each do |s|
|
49
50
|
size = do_client.get("sizes/#{s['id']}")["size"]
|
50
51
|
results << hardware_profile_from(size)
|
51
52
|
end
|
@@ -67,14 +68,15 @@ module Deltacloud
|
|
67
68
|
|
68
69
|
def realms(credentials, opts={})
|
69
70
|
safely do
|
70
|
-
new_client(credentials).get('regions')['regions'].map do |r|
|
71
|
+
realms = new_client(credentials).get('regions')['regions'].map do |r|
|
71
72
|
Realm.new(
|
72
|
-
:id => r['id'],
|
73
|
+
:id => r['id'].to_s,
|
73
74
|
:name => r['name'],
|
74
75
|
:state => 'AVAILABLE',
|
75
76
|
:limit => :unlimited
|
76
77
|
)
|
77
78
|
end
|
79
|
+
filter_on(realms, opts, :id)
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
@@ -133,9 +135,16 @@ module Deltacloud
|
|
133
135
|
safely do
|
134
136
|
client = new_client(credentials)
|
135
137
|
args = { :image_id => image_id }
|
136
|
-
|
137
|
-
|
138
|
-
args.merge!(:
|
138
|
+
# Defaults to first realm if realm_id not set
|
139
|
+
opts[:realm_id] ||= '1'
|
140
|
+
args.merge!(:region_id => opts[:realm_id])
|
141
|
+
# Defaults to first size if hwp_id not set
|
142
|
+
opts[:hwp_id] ||= '66'
|
143
|
+
args.merge!(:size_id => opts[:hwp_id])
|
144
|
+
# Default to 'inst-timestamp if name is not set'
|
145
|
+
opts[:name] ||= "inst-#{Time.now.to_i}"
|
146
|
+
args.merge!(:name => opts[:name])
|
147
|
+
args.merge!(:ssh_key_ids => opts[:keyname]) if opts[:keyname]
|
139
148
|
convert_instance(
|
140
149
|
credentials.user,
|
141
150
|
client.get("droplets/new", args)['droplet']
|
@@ -167,8 +176,48 @@ module Deltacloud
|
|
167
176
|
end
|
168
177
|
end
|
169
178
|
|
179
|
+
def keys(credentials, opts={})
|
180
|
+
client = new_client(credentials)
|
181
|
+
safely do
|
182
|
+
client.get('ssh_keys')['ssh_keys'].map do |k|
|
183
|
+
convert_key(k)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def key(credentials, opts={})
|
189
|
+
client = new_client(credentials)
|
190
|
+
safely do
|
191
|
+
convert_key(client.get("ssh_keys/#{opts[:id]}")["ssh_key"])
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def destroy_key(credentials, opts={})
|
196
|
+
client = new_client(credentials)
|
197
|
+
original_key = key(credentials, opts)
|
198
|
+
safely do
|
199
|
+
client.get("ssh_keys/#{opts[:id]}/destroy")
|
200
|
+
original_key.state = 'deleted'
|
201
|
+
original_key
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def create_key(credentials, opts={})
|
206
|
+
client = new_client(credentials)
|
207
|
+
convert_key(
|
208
|
+
client.get(
|
209
|
+
"ssh_keys/new",
|
210
|
+
:name => opts[:key_name],
|
211
|
+
:ssh_pub_key => opts[:public_key])['ssh_key']
|
212
|
+
)
|
213
|
+
end
|
214
|
+
|
170
215
|
exceptions do
|
171
216
|
|
217
|
+
on (/ERROR Unable to verify credentials.*/) do
|
218
|
+
status 401
|
219
|
+
end
|
220
|
+
|
172
221
|
on(/InternalServerError/) do
|
173
222
|
status 502
|
174
223
|
end
|
@@ -183,6 +232,17 @@ module Deltacloud
|
|
183
232
|
|
184
233
|
end
|
185
234
|
|
235
|
+
def valid_credentials?(credentials)
|
236
|
+
begin
|
237
|
+
hardware_profile_ids(credentials)
|
238
|
+
rescue Deltacloud::Exceptions::AuthenticationFailure
|
239
|
+
return false
|
240
|
+
rescue => e
|
241
|
+
safely { raise e }
|
242
|
+
end
|
243
|
+
true
|
244
|
+
end
|
245
|
+
|
186
246
|
private
|
187
247
|
|
188
248
|
class Client
|
@@ -204,7 +264,7 @@ module Deltacloud
|
|
204
264
|
json_result = JSON::parse(result)
|
205
265
|
if json_result['status'] != 'OK'
|
206
266
|
p result
|
207
|
-
error_message = json_result['error_message'] || json_result['status']
|
267
|
+
error_message = json_result['error_message'] || "#{json_result['status']} #{json_result['description']}"
|
208
268
|
raise error_message
|
209
269
|
end
|
210
270
|
json_result
|
@@ -221,6 +281,16 @@ module Deltacloud
|
|
221
281
|
return 'i386' if name.include? 'x32'
|
222
282
|
end
|
223
283
|
|
284
|
+
def convert_key(k)
|
285
|
+
Key.new(
|
286
|
+
:id => k['id'],
|
287
|
+
:name => k['name'],
|
288
|
+
:credential_type => :key,
|
289
|
+
:pem_rsa_key => k['ssh_pub_key'],
|
290
|
+
:state => 'available'
|
291
|
+
)
|
292
|
+
end
|
293
|
+
|
224
294
|
def convert_state(status)
|
225
295
|
case status
|
226
296
|
when 'active' then 'RUNNING'
|