deltacloud-core 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/Rakefile +10 -12
  2. data/config/drivers/{aruba.yaml → arubacloud.yaml} +2 -2
  3. data/deltacloud-core.gemspec +4 -4
  4. data/lib/cimi/collections/address_templates.rb +1 -1
  5. data/lib/cimi/collections/addresses.rb +2 -2
  6. data/lib/cimi/collections/base.rb +1 -0
  7. data/lib/cimi/collections/credentials.rb +1 -1
  8. data/lib/cimi/collections/forwarding_group_templates.rb +1 -1
  9. data/lib/cimi/collections/forwarding_groups.rb +1 -1
  10. data/lib/cimi/collections/machine_configurations.rb +1 -1
  11. data/lib/cimi/collections/machine_images.rb +1 -1
  12. data/lib/cimi/collections/machine_templates.rb +1 -1
  13. data/lib/cimi/collections/machines.rb +2 -2
  14. data/lib/cimi/collections/network_configurations.rb +1 -1
  15. data/lib/cimi/collections/network_port_configurations.rb +1 -1
  16. data/lib/cimi/collections/network_port_templates.rb +1 -1
  17. data/lib/cimi/collections/network_ports.rb +1 -1
  18. data/lib/cimi/collections/network_templates.rb +1 -1
  19. data/lib/cimi/collections/networks.rb +1 -1
  20. data/lib/cimi/collections/volume_configurations.rb +1 -1
  21. data/lib/cimi/collections/volume_images.rb +1 -1
  22. data/lib/cimi/collections/volume_templates.rb +1 -1
  23. data/lib/cimi/collections/volumes.rb +1 -1
  24. data/lib/cimi/helpers/database_helper.rb +16 -61
  25. data/lib/cimi/helpers/filter_helper.rb +41 -0
  26. data/lib/cimi/helpers/select_helper.rb +62 -0
  27. data/lib/cimi/models.rb +21 -2
  28. data/lib/cimi/models/address.rb +9 -7
  29. data/lib/cimi/models/address_template.rb +4 -4
  30. data/lib/cimi/models/base.rb +62 -197
  31. data/lib/cimi/models/collection.rb +78 -70
  32. data/lib/cimi/models/disk.rb +15 -8
  33. data/lib/cimi/models/machine.rb +27 -29
  34. data/lib/cimi/models/machine_image.rb +10 -13
  35. data/lib/cimi/models/machine_template.rb +3 -3
  36. data/lib/cimi/models/resource.rb +190 -0
  37. data/lib/cimi/models/schema.rb +9 -0
  38. data/lib/cimi/models/volume.rb +10 -13
  39. data/lib/cimi/models/volume_configuration.rb +3 -3
  40. data/lib/cimi/models/volume_template.rb +2 -2
  41. data/lib/cimi/server.rb +1 -0
  42. data/lib/db.rb +15 -0
  43. data/lib/db/address_template.rb +15 -0
  44. data/lib/db/entity.rb +55 -0
  45. data/lib/db/machine_template.rb +15 -0
  46. data/lib/db/provider.rb +40 -0
  47. data/lib/db/volume_configuration.rb +15 -0
  48. data/lib/db/volume_template.rb +15 -0
  49. data/lib/deltacloud/collections/base.rb +1 -0
  50. data/lib/deltacloud/collections/instances.rb +2 -1
  51. data/lib/deltacloud/collections/storage_snapshots.rb +3 -1
  52. data/lib/deltacloud/core_ext/array.rb +5 -0
  53. data/lib/deltacloud/drivers/{aruba/aruba_driver.rb → arubacloud/arubacloud_driver.rb} +3 -6
  54. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +48 -75
  55. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +18 -3
  56. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +25 -0
  57. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +1 -1
  58. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +34 -14
  59. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +2 -0
  60. data/lib/deltacloud/drivers/mock/mock_driver.rb +3 -3
  61. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +93 -33
  62. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +2 -0
  63. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +2 -2
  64. data/lib/deltacloud/helpers/deltacloud_helper.rb +3 -1
  65. data/lib/deltacloud/helpers/rabbit_helper.rb +1 -2
  66. data/lib/deltacloud/models/address.rb +1 -0
  67. data/lib/deltacloud/models/blob.rb +1 -0
  68. data/lib/deltacloud/models/bucket.rb +1 -0
  69. data/lib/deltacloud/models/firewall.rb +1 -0
  70. data/lib/deltacloud/models/hardware_profile.rb +3 -1
  71. data/lib/deltacloud/models/image.rb +7 -0
  72. data/lib/deltacloud/models/instance.rb +12 -3
  73. data/lib/deltacloud/models/key.rb +1 -0
  74. data/lib/deltacloud/models/load_balancer.rb +1 -0
  75. data/lib/deltacloud/models/metric.rb +1 -0
  76. data/lib/deltacloud/models/realm.rb +10 -1
  77. data/lib/deltacloud/models/storage_snapshot.rb +1 -0
  78. data/lib/deltacloud/models/storage_volume.rb +2 -1
  79. data/lib/deltacloud/runner.rb +2 -1
  80. data/lib/deltacloud/server.rb +1 -0
  81. data/lib/deltacloud/version.rb +1 -1
  82. data/lib/deltacloud_rack.rb +4 -0
  83. data/tests/cimi/collections/machines_test.rb +80 -0
  84. data/tests/cimi/db/database_helper_test.rb +54 -99
  85. data/tests/cimi/db/db_helper.rb +2 -0
  86. data/tests/cimi/db/entity_test.rb +29 -0
  87. data/tests/cimi/model/collection_spec.rb +2 -2
  88. data/tests/cimi/model/credential_spec.rb +2 -2
  89. data/tests/cimi/model/machine_configuration_spec.rb +2 -2
  90. data/tests/cimi/model/machine_image_spec.rb +2 -2
  91. data/tests/cimi/model/machine_spec.rb +4 -4
  92. data/tests/cimi/model/machine_template_spec.rb +2 -2
  93. data/tests/cimi/model/volume_configuration_spec.rb +2 -2
  94. data/tests/cimi/model/volume_image_spec.rb +2 -2
  95. data/tests/cimi/model/volume_spec.rb +2 -2
  96. data/tests/cimi/model/volume_template_spec.rb +2 -2
  97. data/tests/cimi/spec_helper.rb +4 -0
  98. data/tests/deltacloud/collections/instances_collection_test.rb +3 -1
  99. data/tests/deltacloud/launcher_test.rb +3 -5
  100. data/tests/drivers/ec2/images_test.rb +7 -0
  101. data/tests/drivers/gogrid/images_test.rb +7 -0
  102. data/tests/drivers/openstack/instances_test.rb +8 -8
  103. data/tests/drivers/openstack/realms_test.rb +13 -13
  104. data/views/errors/403.xml.haml +2 -1
  105. data/views/images/show.html.haml +4 -1
  106. data/views/images/show.xml.haml +1 -0
  107. data/views/instances/new.html.haml +1 -1
  108. data/views/instances/show.html.haml +3 -0
  109. data/views/realms/index.html.haml +2 -0
  110. data/views/realms/show.html.haml +4 -0
  111. data/views/realms/show.xml.haml +3 -0
  112. metadata +19 -14
@@ -71,7 +71,7 @@ class CIMI::Model::Volume < CIMI::Model::Base
71
71
 
72
72
  def self.delete!(id, context)
73
73
  context.driver.destroy_storage_volume(context.credentials, {:id=>id} )
74
- delete_attributes_for(StorageVolume.new(:id => id))
74
+ new(:id => id).destroy
75
75
  end
76
76
 
77
77
  def self.find_to_attach_from_json(json_in, context)
@@ -86,10 +86,6 @@ class CIMI::Model::Volume < CIMI::Model::Base
86
86
  :attachment_point=>v["attachmentPoint"] }}
87
87
  end
88
88
 
89
- def to_entity
90
- 'volume'
91
- end
92
-
93
89
  private
94
90
 
95
91
  def self.create_volume(params, data, context)
@@ -104,22 +100,23 @@ class CIMI::Model::Volume < CIMI::Model::Base
104
100
  :name=>data["name"]}
105
101
  end
106
102
  storage_volume = context.driver.create_storage_volume(context.credentials, opts)
107
- entity = store_attributes_for(storage_volume, data)
108
- from_storage_volume(storage_volume, context, entity.to_hash)
103
+ result = from_storage_volume(storage_volume, context)
104
+ result.name = data['name'] if data['name']
105
+ result.description = data['description']
106
+ result.extract_properties!(data)
107
+ result.save
108
+ result
109
109
  end
110
110
 
111
- def self.from_storage_volume(volume, context, stored_attributes=nil)
112
- stored_attributes ||= load_attributes_for(volume)
113
- self.new( { :name => stored_attributes[:name] || volume.id,
114
- :description => stored_attributes[:description] || 'Description of Volume',
115
- :property => stored_attributes[:property],
111
+ def self.from_storage_volume(volume, context)
112
+ self.new( { :name => volume.id,
116
113
  :created => volume.created.nil? ? nil : Time.parse(volume.created).xmlschema,
117
114
  :id => context.volume_url(volume.id),
118
115
  :capacity => context.to_kibibyte(volume.capacity, 'GB'),
119
116
  :bootable => "false", #fixme ... will vary... ec2 doesn't expose this
120
117
  :snapshots => [], #fixme...
121
118
  :type => 'http://schemas.dmtf.org/cimi/1/mapped',
122
- :state => volume.state,
119
+ :state => volume.state == 'IN-USE' ? 'AVAILABLE' : volume.state,
123
120
  :meters => [],
124
121
  :operations => [{:href=> context.volume_url(volume.id), :rel => "delete"}]
125
122
  } )
@@ -32,7 +32,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
32
32
  :description => json['description'],
33
33
  :format => json['format'],
34
34
  :capacity => json['capacity'],
35
- :ent_properties => json['properties'].to_json
35
+ :ent_properties => json['properties'] ? json['properties'].to_json : {}
36
36
  )
37
37
  from_db(new_config, context)
38
38
  end
@@ -45,7 +45,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
45
45
  :description => xml['description'].first,
46
46
  :format => xml['format'].first,
47
47
  :capacity => xml['capacity'].first,
48
- :ent_properties => JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r })
48
+ :ent_properties => xml['property'] ? JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
49
49
  )
50
50
  from_db(new_config, context)
51
51
  end
@@ -81,7 +81,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
81
81
  :description => model.description,
82
82
  :format => model.format,
83
83
  :capacity => context.to_kibibyte(model.capacity, "GB"),
84
- :property => JSON::parse(model.ent_properties),
84
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
85
85
  :operations => [
86
86
  { :href => context.destroy_volume_configuration_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
87
87
  ]
@@ -56,7 +56,7 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
56
56
  :description => input['description'],
57
57
  :volume_config => input['volumeConfig']['href'],
58
58
  :volume_image => vol_image,
59
- :ent_properties => JSON::dump(input['property'].inject({}) { |r, p| r[p['key']]=p['content']; r })
59
+ :ent_properties => input['property'] ? JSON::dump(input['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
60
60
  )
61
61
  from_db(new_template, context)
62
62
  end
@@ -74,7 +74,7 @@ private
74
74
  :description => model.description,
75
75
  :volume_config => {:href => model.volume_config},
76
76
  :volume_image => {:href => model.volume_image},
77
- :property => JSON::parse(model.ent_properties),
77
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
78
78
  :operations => [
79
79
  { :href => context.destroy_volume_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
80
80
  ]
@@ -44,6 +44,7 @@ module CIMI
44
44
  enable :method_override
45
45
  disable :show_exceptions
46
46
  disable :dump_errors
47
+ set :haml, :format => :xhtml
47
48
 
48
49
  helpers Sinatra::Rabbit::URLFor(CIMI.collections)
49
50
 
data/lib/db.rb CHANGED
@@ -1,3 +1,18 @@
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
+
1
16
  module Deltacloud
2
17
 
3
18
  def self.test_environment?
@@ -1,3 +1,18 @@
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
+
1
16
  module Deltacloud
2
17
  module Database
3
18
 
@@ -1,8 +1,25 @@
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
+
1
16
  module Deltacloud
2
17
  module Database
3
18
 
4
19
  class Entity < Sequel::Model
5
20
 
21
+ attr_accessor :properties
22
+
6
23
  many_to_one :provider
7
24
 
8
25
  plugin :single_table_inheritance, :model
@@ -16,6 +33,44 @@ module Deltacloud
16
33
  retval
17
34
  end
18
35
 
36
+ def properties=(v)
37
+ # Make sure @properties is always a Hash
38
+ @properties = v || {}
39
+ end
40
+
41
+ def before_save
42
+ self.ent_properties = properties.to_json
43
+ super
44
+ end
45
+
46
+ def after_initialize
47
+ if ent_properties
48
+ self.properties = JSON::parse(ent_properties)
49
+ else
50
+ self.properties = {}
51
+ end
52
+ end
53
+
54
+ # Load the entity for the CIMI::Model +model+, or create a new one if
55
+ # none exists yet
56
+ def self.retrieve(model)
57
+ unless model.id
58
+ raise "Can not retrieve entity for #{model.class.name} without an id"
59
+ end
60
+ h = model_hash(model)
61
+ entity = Provider::lookup.entities_dataset.first(h)
62
+ unless entity
63
+ h[:provider_id] = Provider::lookup.id
64
+ entity = Entity.new(h)
65
+ end
66
+ entity
67
+ end
68
+
69
+ private
70
+ def self.model_hash(model)
71
+ { :be_kind => model.class.name,
72
+ :be_id => model.id.split("/").last }
73
+ end
19
74
  end
20
75
 
21
76
  end
@@ -1,3 +1,18 @@
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
+
1
16
  module Deltacloud
2
17
  module Database
3
18
 
@@ -1,12 +1,52 @@
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_relative '../deltacloud/helpers/driver_helper'
17
+
1
18
  module Deltacloud
2
19
  module Database
3
20
 
4
21
  class Provider < Sequel::Model
22
+ extend Deltacloud::Helpers::Drivers
23
+
5
24
  one_to_many :entities
6
25
  one_to_many :machine_templates
7
26
  one_to_many :address_templates
8
27
  one_to_many :volume_templates
9
28
  one_to_many :volume_configurations
29
+
30
+ # Find the DB provider set in the environment/request
31
+ def self.lookup
32
+ prov = Thread.current[:provider] || ENV['API_PROVIDER'] || 'default'
33
+ find_or_create(:driver => current_driver_name, :url => prov)
34
+ end
35
+
36
+ private
37
+
38
+ # In case this model is used outside the Deltacloud server (CIMI tests, CIMI
39
+ # client, etc), the 'Deltacloud.default_frontend' is not initialized.
40
+ # In that case we have to use the 'fallback' way to retrieve current
41
+ # driver name.
42
+ #
43
+ def self.current_driver_name
44
+ if Deltacloud.respond_to?(:default_frontend)
45
+ self.driver_symbol.to_s
46
+ else
47
+ Thread.current[:driver] || ENV['API_DRIVER'] || 'mock'
48
+ end
49
+ end
10
50
  end
11
51
 
12
52
  end
@@ -1,3 +1,18 @@
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
+
1
16
  module Deltacloud
2
17
  module Database
3
18
 
@@ -1,3 +1,18 @@
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
+
1
16
  module Deltacloud
2
17
  module Database
3
18
 
@@ -38,6 +38,7 @@ module Deltacloud::Collections
38
38
  set :public_folder, root + '/public'
39
39
  # A class where the Rabbit will look up for 'collections'
40
40
  set :documentation_class, Deltacloud
41
+ set :haml, :format => :xhtml
41
42
 
42
43
  error do
43
44
  report_error
@@ -23,7 +23,7 @@ module Deltacloud::Collections
23
23
 
24
24
  new_route_for(:instances) do
25
25
  @instance = Instance.new( { :id=>params[:id], :image_id=>params[:image_id] } )
26
- @image = Image.new( :id => params[:image_id] )
26
+ @image = driver.image(credentials, :id => params[:image_id])
27
27
  @hardware_profiles = driver.hardware_profiles(credentials, :architecture => @image.architecture )
28
28
  @realms = [Realm.new(:id => params[:realm_id])] if params[:realm_id]
29
29
  @realms ||= driver.realms(credentials)
@@ -115,6 +115,7 @@ module Deltacloud::Collections
115
115
  respond_to do |format|
116
116
  format.xml { haml :"instances/run" }
117
117
  format.html { haml :"instances/run" }
118
+ format.json { JSON::dump({:instance => { :id => params[:id], :public_address => @output.ssh.network.ip, :command => @output.ssh.command, :output => @output.body}})}
118
119
  end
119
120
  end
120
121
  end
@@ -26,7 +26,9 @@ module Deltacloud::Collections
26
26
  standard_show_operation
27
27
 
28
28
  operation :create, :with_capability => :create_storage_snapshot do
29
- param :volume_id, :string, :required
29
+ param :volume_id, :string, :required
30
+ param :name, :string, :optional
31
+ param :description, :string, :optional
30
32
  control do
31
33
  @storage_snapshot = driver.create_storage_snapshot(credentials, params)
32
34
  status 201 # Created
@@ -22,4 +22,9 @@ class Array
22
22
  def extract_opts!
23
23
  last.is_a?(Hash) ? pop : {}
24
24
  end
25
+
26
+ unless [].respond_to? :sample
27
+ alias :sample :choice
28
+ end
29
+
25
30
  end
@@ -17,17 +17,14 @@
17
17
 
18
18
  require "savon"
19
19
 
20
- Savon.configure do |config|
21
- config.log = false
22
- end
23
20
  HTTPI.log = false
24
21
 
25
22
 
26
23
  module Deltacloud
27
24
  module Drivers
28
- module Aruba
25
+ module Arubacloud
29
26
 
30
- class ArubaDriver < Deltacloud::BaseDriver
27
+ class ArubacloudDriver < Deltacloud::BaseDriver
31
28
 
32
29
  DEFAULT_DC = 'dc1'
33
30
  feature :instances, :authentication_password
@@ -307,7 +304,7 @@ class ArubaDriver < Deltacloud::BaseDriver
307
304
  def new_client(credentials, realm_id=nil)
308
305
  safely do
309
306
  wsdl = realm_id ? Deltacloud::Drivers::driver_config[:aruba][:entrypoints]["compute"]["dc#{realm_id}"] : endpoint
310
- client = Savon.client(wsdl)
307
+ client = Savon.client({wsdl: wsdl, log: false})
311
308
  client.wsse.credentials credentials.user, credentials.password
312
309
  client.request :get_user_authentication_token
313
310
  client
@@ -23,76 +23,6 @@ module Deltacloud
23
23
  feature :instances, :user_name
24
24
  feature :images, :owner_id
25
25
 
26
- define_hardware_profile '66' do
27
- cpu 1
28
- memory 512
29
- storage 20 * 1024
30
- architecture ['i386', 'x86_64']
31
- end
32
-
33
- define_hardware_profile '63' do
34
- cpu 1
35
- memory 1024
36
- storage 30 * 1024
37
- architecture ['i386', 'x86_64']
38
- end
39
-
40
- define_hardware_profile '62' do
41
- cpu 2
42
- memory 2 * 1024
43
- storage 40 * 1024
44
- architecture ['i386', 'x86_64']
45
- end
46
-
47
- define_hardware_profile '64' do
48
- cpu 2
49
- memory 4 * 1024
50
- storage 60 * 1024
51
- architecture ['i386', 'x86_64']
52
- end
53
-
54
- define_hardware_profile '65' do
55
- cpu 4
56
- memory 8 * 1024
57
- storage 80 * 1024
58
- architecture ['i386', 'x86_64']
59
- end
60
-
61
- define_hardware_profile '61' do
62
- cpu 8
63
- memory 16 * 1024
64
- storage 160 * 1024
65
- architecture ['i386', 'x86_64']
66
- end
67
-
68
- define_hardware_profile '60' do
69
- cpu 12
70
- memory 32 * 1024
71
- storage 320 * 1024
72
- architecture ['i386', 'x86_64']
73
- end
74
-
75
- define_hardware_profile '70' do
76
- cpu 16
77
- memory 48 * 1024
78
- storage 480 * 1024
79
- architecture ['i386', 'x86_64']
80
- end
81
-
82
- define_hardware_profile '69' do
83
- cpu 16
84
- memory 64 * 1024
85
- storage 640 * 1024
86
- architecture ['i386', 'x86_64']
87
- end
88
-
89
- define_hardware_profile '68' do
90
- cpu 24
91
- memory 96 * 1024
92
- storage 960 * 1024
93
- architecture ['i386', 'x86_64']
94
- end
95
-
96
26
  define_instance_states do
97
27
  start.to( :pending ) .on( :create )
98
28
  pending.to( :running ) .automatically
@@ -105,6 +35,36 @@ module Deltacloud
105
35
  error.from(:running, :pending, :stopping)
106
36
  end
107
37
 
38
+ define_hardware_profile('default')
39
+
40
+ def hardware_profiles(credentials, opts={})
41
+ do_client = new_client(credentials)
42
+ results = []
43
+ safely do
44
+ if opts[:id]
45
+ size = do_client.get("sizes/#{opts[:id]}")["size"]
46
+ results << hardware_profile_from(size)
47
+ else
48
+ sizes = do_client.get("sizes")["sizes"].each do |s|
49
+ size = do_client.get("sizes/#{s['id']}")["size"]
50
+ results << hardware_profile_from(size)
51
+ end
52
+ end
53
+ filter_hardware_profiles(results, opts)
54
+ end
55
+ end
56
+
57
+ def hardware_profile_ids(credentials)
58
+ do_client = new_client(credentials)
59
+ hwps = []
60
+ safely do
61
+ do_client.get("sizes")["sizes"].each do |s|
62
+ hwps << HardwareProfile.new(s["id"].to_s)
63
+ end
64
+ end
65
+ hwps
66
+ end
67
+
108
68
  def realms(credentials, opts={})
109
69
  safely do
110
70
  new_client(credentials).get('regions')['regions'].map do |r|
@@ -124,18 +84,19 @@ module Deltacloud
124
84
  # values to get less images.
125
85
  #
126
86
  def images(credentials, opts={})
87
+ hwps = hardware_profile_ids(credentials)
127
88
  unless opts[:id]
128
- filter = opts[:owner_id] ? { :filter => opts[:owner_id] } : {}
89
+ filter = opts[:owner_id] ? { :filter => "my_images" } : {}
129
90
  img_arr = safely do
130
91
  new_client(credentials).get('images', filter)['images'].map do |i|
131
- convert_image(credentials, i)
92
+ convert_image(hwps, i)
132
93
  end
133
94
  end
134
95
  filter_on( img_arr, :architecture, opts )
135
96
  else
136
97
  safely do
137
98
  [convert_image(
138
- credentials,
99
+ hwps,
139
100
  new_client(credentials).get('images/%s' % opts[:id])['image']
140
101
  )]
141
102
  end
@@ -289,7 +250,7 @@ module Deltacloud
289
250
  )
290
251
  end
291
252
 
292
- def convert_image(credentials, i)
253
+ def convert_image(hwps, i)
293
254
  Image.new(
294
255
  :id => i['id'].to_s,
295
256
  :name => i['name'],
@@ -297,10 +258,22 @@ module Deltacloud
297
258
  :owner_id => 'global',
298
259
  :state => 'AVAILABLE',
299
260
  :architecture => extract_arch_from_name(i['name']),
300
- :hardware_profiles => hardware_profiles(credentials)
261
+ :hardware_profiles => hwps
301
262
  )
302
263
  end
303
264
 
265
+ #{"cost_per_hour"=>0.00744, "cpu"=>1, "disk"=>20, "id"=>66, "memory"=>512, "name"=>"512MB"}
266
+ def hardware_profile_from(size)
267
+ hwp = HardwareProfile.new(size["id"].to_s) do
268
+ architecture 'x86_64'
269
+ memory size["memory"]
270
+ storage size["disk"]
271
+ cpu size["cpu"]
272
+ end
273
+ hwp.name=size["name"]
274
+ return hwp
275
+ end
276
+
304
277
  end
305
278
  end
306
279
  end