deltacloud-core 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/Rakefile +2 -1
  2. data/bin/deltacloudd +11 -5
  3. data/config.ru +3 -3
  4. data/deltacloud-core.gemspec +24 -18
  5. data/lib/cimi/collections/address_templates.rb +3 -3
  6. data/lib/cimi/collections/addresses.rb +6 -5
  7. data/lib/cimi/collections/entity_metadata.rb +0 -2
  8. data/lib/cimi/collections/machine_admins.rb +5 -5
  9. data/lib/cimi/collections/machine_configurations.rb +2 -2
  10. data/lib/cimi/collections/machine_images.rb +3 -3
  11. data/lib/cimi/collections/machines.rb +32 -10
  12. data/lib/cimi/collections/network_configurations.rb +4 -3
  13. data/lib/cimi/collections/network_templates.rb +4 -3
  14. data/lib/cimi/collections/networks.rb +8 -8
  15. data/lib/cimi/collections/routing_group_templates.rb +4 -3
  16. data/lib/cimi/collections/routing_groups.rb +4 -3
  17. data/lib/cimi/collections/volume_configurations.rb +3 -3
  18. data/lib/cimi/collections/volume_images.rb +3 -3
  19. data/lib/cimi/collections/volumes.rb +4 -3
  20. data/lib/cimi/collections/vsp_configurations.rb +4 -3
  21. data/lib/cimi/collections/vsp_templates.rb +4 -3
  22. data/lib/cimi/collections/vsps.rb +8 -7
  23. data/lib/cimi/helpers.rb +1 -1
  24. data/lib/cimi/helpers/cimi_helper.rb +11 -1
  25. data/lib/cimi/models.rb +4 -0
  26. data/lib/cimi/models/base.rb +11 -1
  27. data/lib/cimi/models/cloud_entry_point.rb +7 -14
  28. data/lib/cimi/models/disk.rb +40 -0
  29. data/lib/cimi/models/disk_collection.rb +38 -0
  30. data/lib/cimi/models/machine.rb +9 -43
  31. data/lib/cimi/models/machine_collection.rb +7 -4
  32. data/lib/cimi/models/machine_configuration.rb +8 -15
  33. data/lib/cimi/models/machine_configuration_collection.rb +6 -4
  34. data/lib/cimi/models/machine_image_collection.rb +6 -4
  35. data/lib/cimi/models/machine_template_collection.rb +6 -4
  36. data/lib/cimi/models/machine_volume.rb +42 -0
  37. data/lib/cimi/models/machine_volume_collection.rb +34 -0
  38. data/lib/cimi/models/network.rb +5 -9
  39. data/lib/cimi/models/network_collection.rb +6 -5
  40. data/lib/cimi/models/schema.rb +20 -0
  41. data/lib/cimi/models/volume_collection.rb +6 -4
  42. data/lib/cimi/models/volume_configuration_collection.rb +6 -4
  43. data/lib/cimi/models/volume_image_collection.rb +6 -4
  44. data/lib/cimi/models/volume_template_collection.rb +6 -4
  45. data/lib/deltacloud/api.rb +3 -3
  46. data/lib/deltacloud/collections/addresses.rb +1 -1
  47. data/lib/deltacloud/collections/firewalls.rb +4 -2
  48. data/lib/deltacloud/collections/keys.rb +1 -1
  49. data/lib/deltacloud/collections/load_balancers.rb +1 -1
  50. data/lib/deltacloud/collections/storage_volumes.rb +4 -4
  51. data/lib/deltacloud/drivers/base_driver.rb +12 -20
  52. data/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb +294 -0
  53. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +38 -6
  54. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +4 -0
  55. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +40 -4
  56. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +8 -7
  57. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +422 -416
  58. data/lib/deltacloud/drivers/google/google_driver.rb +2 -1
  59. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +30 -16
  60. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +1 -0
  61. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +3 -9
  62. data/lib/deltacloud/helpers/deltacloud_helper.rb +0 -2
  63. data/lib/deltacloud/models/firewall_rule.rb +2 -0
  64. data/lib/deltacloud/models/hardware_profile.rb +61 -59
  65. data/{tests/deprecated/core_ext/string.rb → lib/deltacloud/version.rb} +3 -15
  66. data/lib/deltacloud_rack.rb +1 -0
  67. data/lib/ec2/server.rb +5 -3
  68. data/lib/sinatra/rack_accept.rb +53 -53
  69. data/lib/sinatra/rack_etag.rb +1 -1
  70. data/tests/cimi/collections/cloud_entry_point_test.rb +11 -2
  71. data/tests/deltacloud/common.rb +1 -1
  72. data/tests/deltacloud/rack_test.rb +3 -3
  73. data/tests/drivers/base/base_driver_test.rb +6 -2
  74. data/tests/drivers/base/common.rb +1 -0
  75. data/tests/drivers/base/library_test.rb +6 -2
  76. data/tests/drivers/ec2/common.rb +34 -15
  77. data/tests/drivers/ec2/images_test.rb +2 -3
  78. data/tests/drivers/ec2/instance_test.rb +12 -2
  79. data/tests/drivers/ec2/keys_test.rb +2 -2
  80. data/tests/drivers/ec2/realms_test.rb +7 -3
  81. data/tests/drivers/ec2/storage_snapshots_test.rb +2 -3
  82. data/tests/drivers/gogrid/common.rb +24 -0
  83. data/tests/drivers/gogrid/hardware_profiles_test.rb +51 -0
  84. data/tests/drivers/gogrid/images_test.rb +57 -0
  85. data/tests/drivers/gogrid/instances_test.rb +92 -0
  86. data/tests/drivers/gogrid/realms_test.rb +45 -0
  87. data/tests/drivers/google/buckets_test.rb +105 -0
  88. data/tests/drivers/google/common.rb +20 -0
  89. data/tests/drivers/mock/common.rb +1 -0
  90. data/tests/drivers/mock/images_test.rb +3 -2
  91. data/tests/drivers/mock/instances_test.rb +3 -2
  92. data/tests/drivers/mock/keys_test.rb +3 -2
  93. data/tests/drivers/mock/realms_test.rb +3 -2
  94. data/tests/drivers/mock/storage_snapshots_test.rb +3 -2
  95. data/tests/drivers/mock/storage_volumes_test.rb +3 -2
  96. data/tests/drivers/models/address_test.rb +3 -3
  97. data/tests/drivers/models/base_test.rb +4 -2
  98. data/tests/drivers/models/blob_test.rb +3 -3
  99. data/tests/drivers/models/common.rb +3 -0
  100. data/tests/drivers/models/hardware_profile_test.rb +5 -4
  101. data/tests/drivers/models/instance_address_test.rb +3 -3
  102. data/tests/drivers/models/instance_profile_test.rb +3 -3
  103. data/tests/drivers/models/instance_test.rb +3 -3
  104. data/tests/drivers/models/keys_test.rb +3 -3
  105. data/tests/drivers/models/metrics_test.rb +3 -3
  106. data/tests/drivers/openstack/common.rb +26 -0
  107. data/tests/drivers/openstack/hardware_profiles_test.rb +46 -0
  108. data/tests/drivers/openstack/images_test.rb +50 -0
  109. data/tests/drivers/openstack/instances_test.rb +66 -0
  110. data/tests/drivers/openstack/keys_test.rb +61 -0
  111. data/tests/drivers/openstack/realms_test.rb +46 -0
  112. data/tests/drivers/rhevm/common.rb +2 -0
  113. data/tests/drivers/rhevm/images_test.rb +3 -4
  114. data/tests/drivers/rhevm/instance_test.rb +2 -2
  115. data/tests/drivers/rhevm/provider_test.rb +2 -2
  116. data/tests/drivers/rhevm/realms_test.rb +2 -3
  117. data/tests/ec2/common.rb +5 -4
  118. data/tests/ec2/server_test.rb +3 -2
  119. data/tests/helpers/rack/common.rb +3 -0
  120. data/tests/helpers/rack/rack_accept_test.rb +65 -0
  121. data/tests/helpers/rack/rack_date_test.rb +27 -0
  122. data/tests/helpers/rack/rack_driver_select_test.rb +53 -0
  123. data/tests/helpers/rack/rack_etag_test.rb +29 -0
  124. data/tests/helpers/rack/rack_matrix_params_test.rb +72 -0
  125. data/tests/test_helper.rb +44 -36
  126. data/views/hardware_profiles/index.html.haml +1 -1
  127. data/views/hardware_profiles/show.html.haml +2 -2
  128. data/views/hardware_profiles/show.xml.haml +2 -1
  129. data/views/images/show.html.haml +6 -5
  130. metadata +74 -117
  131. data/tests/deprecated/api/common.rb +0 -1
  132. data/tests/deprecated/api/driver_test.rb +0 -79
  133. data/tests/deprecated/api/library_test.rb +0 -6
  134. data/tests/deprecated/cimi/features/step_definitions/common_steps.rb +0 -59
  135. data/tests/deprecated/cimi/features/step_definitions/machine_images_steps.rb +0 -0
  136. data/tests/deprecated/cimi/features/step_definitions/machines_steps.rb +0 -100
  137. data/tests/deprecated/cimi/features/step_definitions/volumes_steps.rb +0 -115
  138. data/tests/deprecated/cimi/features/support/env.rb +0 -75
  139. data/tests/deprecated/common.rb +0 -279
  140. data/tests/deprecated/drivers/ec2/api_test.rb +0 -19
  141. data/tests/deprecated/drivers/ec2/common.rb +0 -23
  142. data/tests/deprecated/drivers/ec2/drivers_test.rb +0 -120
  143. data/tests/deprecated/drivers/ec2/hardware_profiles_test.rb +0 -224
  144. data/tests/deprecated/drivers/ec2/images_test.rb +0 -230
  145. data/tests/deprecated/drivers/ec2/instances_test.rb +0 -356
  146. data/tests/deprecated/drivers/ec2/keys_test.rb +0 -181
  147. data/tests/deprecated/drivers/ec2/realms_test.rb +0 -146
  148. data/tests/deprecated/drivers/fgcp/api_test.rb +0 -47
  149. data/tests/deprecated/drivers/fgcp/hardware_profiles_test.rb +0 -54
  150. data/tests/deprecated/drivers/fgcp/realms_test.rb +0 -42
  151. data/tests/deprecated/drivers/fgcp/setup.rb +0 -13
  152. data/tests/deprecated/drivers/google/api_test.rb +0 -19
  153. data/tests/deprecated/drivers/google/buckets_test.rb +0 -100
  154. data/tests/deprecated/drivers/google/common.rb +0 -54
  155. data/tests/deprecated/drivers/mock/api_test.rb +0 -10
  156. data/tests/deprecated/drivers/mock/buckets_test.rb +0 -195
  157. data/tests/deprecated/drivers/mock/common.rb +0 -7
  158. data/tests/deprecated/drivers/mock/drivers_test.rb +0 -123
  159. data/tests/deprecated/drivers/mock/hardware_profiles_test.rb +0 -224
  160. data/tests/deprecated/drivers/mock/images_test.rb +0 -197
  161. data/tests/deprecated/drivers/mock/instances_test.rb +0 -343
  162. data/tests/deprecated/drivers/mock/keys_test.rb +0 -161
  163. data/tests/deprecated/drivers/mock/realms_test.rb +0 -132
  164. data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +0 -114
  165. data/tests/deprecated/drivers/mock/storage_volumes_test.rb +0 -122
  166. data/tests/deprecated/drivers/openstack/api_test.rb +0 -46
  167. data/tests/deprecated/drivers/openstack/common.rb +0 -21
  168. data/tests/deprecated/drivers/openstack/hardware_profiles_test.rb +0 -64
  169. data/tests/deprecated/drivers/openstack/images_test.rb +0 -46
  170. data/tests/deprecated/drivers/openstack/instances_test.rb +0 -208
  171. data/tests/deprecated/drivers/openstack/realms_test.rb +0 -40
  172. data/tests/deprecated/drivers/rackspace/api_test.rb +0 -46
  173. data/tests/deprecated/drivers/rackspace/buckets_test.rb +0 -150
  174. data/tests/deprecated/drivers/rackspace/common.rb +0 -16
  175. data/tests/deprecated/drivers/rackspace/hardware_profiles_test.rb +0 -58
  176. data/tests/deprecated/drivers/rackspace/images_test.rb +0 -45
  177. data/tests/deprecated/drivers/rackspace/instances_test.rb +0 -166
  178. data/tests/deprecated/drivers/rackspace/realms_test.rb +0 -41
  179. data/tests/deprecated/drivers/rhevm/api_test.rb +0 -45
  180. data/tests/deprecated/drivers/rhevm/common.rb +0 -21
  181. data/tests/deprecated/drivers/rhevm/hardware_profiles_test.rb +0 -58
  182. data/tests/deprecated/drivers/rhevm/images_test.rb +0 -48
  183. data/tests/deprecated/drivers/rhevm/instances_test.rb +0 -182
  184. data/tests/deprecated/drivers/rhevm/realms_test.rb +0 -40
  185. data/tests/deprecated/minitest_common.rb +0 -58
  186. data/tests/deprecated/minitest_common_api_test.rb +0 -115
  187. data/tests/deprecated/rabbit_test.rb +0 -52
@@ -17,17 +17,19 @@ class CIMI::Model::VolumeCollection < CIMI::Model::Base
17
17
 
18
18
  act_as_root_entity :volume
19
19
 
20
- array :volumes do
21
- scalar :href
22
- end
20
+ text :count
21
+
22
+ self.schema.add_collection_member_array(CIMI::Model::Volume)
23
23
 
24
24
  def self.default(context)
25
+ volumes = CIMI::Model::Volume.all(context)
25
26
  self.new(
26
27
  :id => context.volumes_url,
27
28
  :name => 'default',
28
29
  :created => Time.now,
29
30
  :description => "#{context.driver.name.capitalize} VolumeCollection",
30
- :volumes => CIMI::Model::Volume.all_uri(context)
31
+ :count => volumes.count,
32
+ :volumes => volumes
31
33
  )
32
34
  end
33
35
 
@@ -17,17 +17,19 @@ class CIMI::Model::VolumeConfigurationCollection < CIMI::Model::Base
17
17
 
18
18
  act_as_root_entity :volume_configuration
19
19
 
20
- array :volume_configurations do
21
- scalar :href
22
- end
20
+ text :count
21
+
22
+ self.schema.add_collection_member_array(CIMI::Model::VolumeConfiguration)
23
23
 
24
24
  def self.default(context)
25
+ volume_configurations = CIMI::Model::VolumeConfiguration.all(context)
25
26
  self.new(
26
27
  :id => context.volume_configurations_url,
27
28
  :name => 'default',
28
29
  :created => Time.now,
29
30
  :description => "#{context.driver.name.capitalize} VolumeConfigurationCollection",
30
- :volume_configurations => CIMI::Model::VolumeConfiguration.all_uri(context)
31
+ :count => volume_configurations.size,
32
+ :volume_configurations => volume_configurations
31
33
  )
32
34
  end
33
35
 
@@ -17,17 +17,19 @@ class CIMI::Model::VolumeImageCollection < CIMI::Model::Base
17
17
 
18
18
  act_as_root_entity :volume_image
19
19
 
20
- array :volume_images do
21
- scalar :href
22
- end
20
+ text :count
21
+
22
+ self.schema.add_collection_member_array(CIMI::Model::VolumeImage)
23
23
 
24
24
  def self.default(context)
25
+ volume_images = CIMI::Model::VolumeImage.all(context)
25
26
  self.new(
26
27
  :id => context.volume_images_url,
27
28
  :name => 'default',
28
29
  :created => Time.now,
29
30
  :description => "#{context.driver.name.capitalize} VolumeImageCollection",
30
- :volume_images => CIMI::Model::VolumeImage.all_uri(context)
31
+ :count => volume_images.count,
32
+ :volume_images => volume_images
31
33
  )
32
34
  end
33
35
 
@@ -17,17 +17,19 @@ class CIMI::Model::VolumeTemplateCollection < CIMI::Model::Base
17
17
 
18
18
  act_as_root_entity :volume_template
19
19
 
20
- array :volume_templates do
21
- scalar :href
22
- end
20
+ text :count
21
+
22
+ self.schema.add_collection_member_array(CIMI::Model::VolumeTemplate)
23
23
 
24
24
  def self.default(context)
25
+ volume_templates = CIMI::Model::VolumeTemplate.all(context)
25
26
  self.new(
26
27
  :id => context.volume_template_url,
27
28
  :name => 'default',
28
29
  :created => Time.now,
29
30
  :description => "#{context.driver.name.capitalize} VolumeTemplateCollection",
30
- :volume_templates => CIMI::Model::VolumeTemplate.all_uri(context)
31
+ :count => volume_templates.size,
32
+ :volume_templates => volume_templates
31
33
  )
32
34
  end
33
35
 
@@ -22,6 +22,7 @@ require_relative 'core_ext'
22
22
  require_relative 'models'
23
23
  require_relative 'drivers'
24
24
  require_relative 'helpers/driver_helper'
25
+ require_relative 'version'
25
26
 
26
27
  module TestPoller
27
28
  # This method will pool the resource until condition is true
@@ -67,8 +68,6 @@ class StorageSnapshot; include TestPoller; end
67
68
 
68
69
  module Deltacloud
69
70
 
70
- API_VERSION = '1.0.2'
71
-
72
71
  def self.drivers
73
72
  Drivers.driver_config
74
73
  end
@@ -117,7 +116,8 @@ module Deltacloud
117
116
  begin
118
117
  params = ([@credentials] + args).flatten
119
118
  backend.send(name, *params)
120
- rescue ArgumentError
119
+ rescue ArgumentError => e
120
+ puts "[W] Wrong arguments for #{name}. Omitting credentials injection. (#{e.message})"
121
121
  backend.send(name, *args)
122
122
  end
123
123
  end
@@ -41,7 +41,7 @@ module Deltacloud::Collections
41
41
  respond_to do |format|
42
42
  format.xml { haml :"addresses/show", :ugly => true }
43
43
  format.html { haml :"addresses/_address", :layout => false }
44
- format.json { convert_to_json(:address, @address) }
44
+ format.json { xml_to_json("addresses/show") }
45
45
  end
46
46
  end
47
47
  end
@@ -16,6 +16,8 @@
16
16
  module Deltacloud::Collections
17
17
  class Firewalls < Base
18
18
 
19
+ include Deltacloud::Features
20
+
19
21
  set :capability, lambda { |m| driver.respond_to? m }
20
22
 
21
23
  check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
@@ -64,7 +66,7 @@ module Deltacloud::Collections
64
66
  respond_to do |format|
65
67
  format.xml { haml :"firewalls/show" }
66
68
  format.html { haml :"firewalls/show" }
67
- format.json { convert_to_json(:firewall, @firewall) }
69
+ format.json { xml_to_json("firewalls/show") }
68
70
  end
69
71
  end
70
72
  end
@@ -107,7 +109,7 @@ module Deltacloud::Collections
107
109
  respond_to do |format|
108
110
  format.xml { haml :"firewalls/show" }
109
111
  format.html { haml :"firewalls/show" }
110
- format.json { convert_to_json(:firewall, @firewall) }
112
+ format.json { xml_to_json("firewalls/show") }
111
113
  end
112
114
  end
113
115
  end
@@ -42,7 +42,7 @@ module Deltacloud::Collections
42
42
  respond_to do |format|
43
43
  format.xml { haml :"keys/show", :ugly => true }
44
44
  format.html { haml :"keys/show" }
45
- format.json { convert_to_json(:key, @key)}
45
+ format.json { xml_to_json("keys/show")}
46
46
  end
47
47
  end
48
48
  end
@@ -53,7 +53,7 @@ module Deltacloud::Collections
53
53
  response['Location'] = load_balancer_url(@load_balancer.id)
54
54
  respond_to do |format|
55
55
  format.xml { haml :"load_balancers/show" }
56
- format.json { convert_to_json(:load_balancer, @load_balancer) }
56
+ format.json { xml_to_json("load_balancers/show")}
57
57
  format.html { redirect load_balancer_url(@load_balancer.id)}
58
58
  end
59
59
  end
@@ -48,7 +48,7 @@ module Deltacloud::Collections
48
48
  respond_to do |format|
49
49
  format.xml { haml :"storage_volumes/show" }
50
50
  format.html { haml :"storage_volumes/show" }
51
- format.json { convert_to_json(:storage_volume, @storage_volume) }
51
+ format.json { xml_to_json("storage_volumes/show") }
52
52
  end
53
53
  end
54
54
  end
@@ -62,7 +62,7 @@ module Deltacloud::Collections
62
62
  respond_to do |format|
63
63
  format.html { redirect(storage_volume_url(params[:id]))}
64
64
  format.xml { haml :"storage_volumes/show" }
65
- format.json { convert_to_json(:storage_volume, @storage_volume) }
65
+ format.json { xml_to_json("storage_volumes/show")}
66
66
  end
67
67
  end
68
68
  end
@@ -70,14 +70,14 @@ module Deltacloud::Collections
70
70
  action :detach, :with_capability => :detach_storage_volume do
71
71
  control do
72
72
  volume = driver.storage_volume(credentials, :id => params[:id])
73
- @storage_volume = driver.detach_storage_volume(credentials, :id => volume.id,
73
+ @storage_volume = driver.detach_storage_volume(credentials, :id => volume.id,
74
74
  :instance_id => volume.instance_id,
75
75
  :device => volume.device)
76
76
  status 202
77
77
  respond_to do |format|
78
78
  format.html { redirect(storage_volume_url(params[:id]))}
79
79
  format.xml { haml :"storage_volumes/show" }
80
- format.json { convert_to_json(:storage_volume, @storage_volume) }
80
+ format.json { xml_to_json("storage_volumes/show") }
81
81
  end
82
82
  end
83
83
  end
@@ -19,7 +19,6 @@ module Deltacloud
19
19
  require_relative '../core_ext.rb'
20
20
  require_relative './exceptions.rb'
21
21
  require_relative './features.rb'
22
- require_relative '../models/hardware_profile.rb'
23
22
  require_relative '../models/state_machine.rb'
24
23
 
25
24
  class BaseDriver
@@ -69,19 +68,13 @@ module Deltacloud
69
68
  ExceptionHandler::exceptions(&block)
70
69
  end
71
70
 
72
- def self.define_hardware_profile(name,&block)
71
+ def self.define_hardware_profile(profile_id, &block)
73
72
  @hardware_profiles ||= []
74
- hw_profile = @hardware_profiles.find{|e| e.name == name}
73
+ hw_profile = @hardware_profiles.find{|e| e.id == profile_id }
75
74
  return if hw_profile
76
- hw_profile = ::Deltacloud::HardwareProfile.new( name, &block )
75
+ hw_profile = ::Deltacloud::HardwareProfile.new(profile_id, &block )
77
76
  @hardware_profiles << hw_profile
78
77
  hw_profile.params
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
85
78
  end
86
79
 
87
80
  def self.hardware_profiles
@@ -89,14 +82,14 @@ module Deltacloud
89
82
  @hardware_profiles
90
83
  end
91
84
 
92
- def hardware_profiles(credentials, opts = nil)
85
+ def hardware_profiles(credentials, opts = {})
93
86
  results = self.class.hardware_profiles
94
87
  filter_hardware_profiles(results, opts)
95
88
  end
96
89
 
97
- def hardware_profile(credentials, name)
98
- name = name[:id] if name.kind_of? Hash
99
- hardware_profiles(credentials, :id => name).first
90
+ def hardware_profile(credentials, profile_id)
91
+ profile_id = profile_id[:id] if profile_id.kind_of? Hash
92
+ hardware_profiles(credentials, :id => profile_id).first
100
93
  end
101
94
 
102
95
  def filter_hardware_profiles(profiles, opts)
@@ -104,25 +97,24 @@ module Deltacloud
104
97
  if v = opts[:architecture]
105
98
  profiles = profiles.select { |hwp| hwp.include?(:architecture, v) }
106
99
  end
107
- # As a request param, we call 'name' 'id'
108
100
  if v = opts[:id]
109
- profiles = profiles.select { |hwp| hwp.name == v }
101
+ profiles = profiles.select { |hwp| hwp.id == v }
110
102
  end
111
103
  end
112
104
  profiles
113
105
  end
114
106
 
115
- def find_hardware_profile(credentials, name, image_id)
107
+ def find_hardware_profile(credentials, profile_id, image_id)
116
108
  hwp = nil
117
109
  if name
118
- unless hwp = hardware_profiles(credentials, :id => name).first
110
+ unless hwp = hardware_profile(credentials, profile_id)
119
111
  raise BackendError.new(400, "bad-hardware-profile-name",
120
- "Hardware profile '#{name}' does not exist", nil)
112
+ "Hardware profile '#{name}' does not exist", nil)
121
113
  end
122
114
  else
123
115
  unless image = image(credentials, :id=>image_id)
124
116
  raise BackendError.new(400, "bad-image-id",
125
- "Image with ID '#{image_id}' does not exist", nil)
117
+ "Image with ID '#{image_id}' does not exist", nil)
126
118
  end
127
119
  hwp = hardware_profiles(credentials,
128
120
  :architecture=>image.architecture).first
@@ -0,0 +1,294 @@
1
+ # This is a copy of code that has been submitted upstream
2
+ # https://github.com/appoxy/aws/pull/116
3
+ #
4
+ # If you make changes here, make sure they go upstream, too
5
+
6
+ unless Aws::Ec2::method_defined?(:create_vpc)
7
+ class Aws::Ec2
8
+ #-----------------------------------------------------------------
9
+ # VPC related
10
+ #-----------------------------------------------------------------
11
+
12
+ # Create VPC
13
+ # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVpc.html
14
+ #
15
+ # ec2.create_vpc("10.0.0.0/16")
16
+ # FIXME: EVen though the EC2 docs describe the parameter instanceTenancy,
17
+ # I could not get it to recognize that
18
+ def create_vpc(cidr_block = "10.0.0.0/16")
19
+ params = { "CidrBlock" => cidr_block }
20
+ link = generate_request("CreateVpc", params)
21
+ request_info(link, QEc2VpcsParser.new("vpc", :logger => @logger))
22
+ rescue Exception
23
+ on_exception
24
+ end
25
+
26
+
27
+ # Describe VPC's
28
+ # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeVpcs.html
29
+ #
30
+ # ec2.describe_vpcs
31
+ # ec2.describe_vpcs(vpcId1, vpcId2, 'Filter.1.Name' => 'state', 'Filter.1.Value' = > 'pending', ...)
32
+ def describe_vpcs(*args)
33
+ if args.last.is_a?(Hash)
34
+ params = args.pop.dup
35
+ else
36
+ params = {}
37
+ end
38
+ 1.upto(args.size) { |i| params["VpcId.#{i}"] = args[i-1] }
39
+ link = generate_request("DescribeVpcs", params)
40
+ request_info(link, QEc2VpcsParser.new("item", :logger => @logger))
41
+ rescue Exception
42
+ on_exception
43
+ end
44
+
45
+ # Delete VPC
46
+ # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteVpc.html
47
+ #
48
+ # ec2.delete_vpc(vpc_id)
49
+ def delete_vpc(vpc_id)
50
+ params = { "VpcId" => vpc_id }
51
+ link = generate_request("DeleteVpc", params)
52
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
53
+ rescue Exception
54
+ on_exception
55
+ end
56
+
57
+ # Create subnet in a VPC
58
+ # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSubnet.html
59
+ #
60
+ # ec2.create_subnet(vpc_id, cidr_block)
61
+ # ec2.create_subnet(vpc_id, cidr_block, availability_zone))
62
+ def create_subnet(vpc_id, cidr_block, availability_zone = nil)
63
+ params = { "VpcId" => vpc_id, "CidrBlock" => cidr_block }
64
+ params["AvailabilityZone"] = availability_zone if availability_zone
65
+ link = generate_request("CreateSubnet", params)
66
+ request_info(link, QEc2SubnetsParser.new("subnet", :logger => @logger))
67
+ rescue Exception
68
+ on_exception
69
+ end
70
+
71
+ # Describe subnets
72
+ # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html
73
+ #
74
+ # ec2.describe_subnets
75
+ # ecs.describe_subnets(subnetId1, SubnetId2, ...,
76
+ # 'Filter.1.Name' => 'state',
77
+ # 'Filter.1.Value.1' => 'pending',
78
+ # 'Filter.2.Name' => ...)
79
+ def describe_subnets(*args)
80
+ if args.last.is_a?(Hash)
81
+ params = args.pop.dup
82
+ else
83
+ params = {}
84
+ end
85
+ 1.upto(args.size) { |i| params["SubnetId.#{i}"] = args[i-1] }
86
+ link = generate_request("DescribeSubnets", params)
87
+ request_info(link, QEc2SubnetsParser.new("item", :logger => @logger))
88
+ rescue Exception
89
+ on_exception
90
+ end
91
+
92
+ # Delete Subnet
93
+ # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteSubnet.html
94
+ #
95
+ # ec2.delete_subnet(subnet_id)
96
+ def delete_subnet(subnet_id)
97
+ params = { "SubnetId" => subnet_id }
98
+ link = generate_request("DeleteSubnet", params)
99
+ request_info(link, RightBoolResponseParser.new(:logger => @logger))
100
+ rescue Exception
101
+ on_exception
102
+ end
103
+
104
+ # The only change in this class compared to upstream is
105
+ # that we parse out subnetId and vpcId
106
+ class QEc2DescribeInstancesParser < Aws::AwsParser #:nodoc:
107
+ def tagstart(name, attributes)
108
+ # DescribeInstances property
109
+ if (name == 'item' && @xmlpath == 'DescribeInstancesResponse/reservationSet') ||
110
+ # RunInstances property
111
+ (name == 'RunInstancesResponse')
112
+ @reservation = {:aws_groups => [],
113
+ :instances_set => []}
114
+
115
+ elsif (name == 'item') &&
116
+ # DescribeInstances property
117
+ (@xmlpath=='DescribeInstancesResponse/reservationSet/item/instancesSet' ||
118
+ # RunInstances property
119
+ @xmlpath=='RunInstancesResponse/instancesSet')
120
+ # the optional params (sometimes are missing and we dont want them to be nil)
121
+ @instance = {:aws_reason => '',
122
+ :dns_name => '',
123
+ :private_dns_name => '',
124
+ :ami_launch_index => '',
125
+ :ssh_key_name => '',
126
+ :aws_state => '',
127
+ :root_device_type => '',
128
+ :root_device_name => '',
129
+ :architecture => '',
130
+ :subnet_id => '',
131
+ :vpc_id => '',
132
+ :block_device_mappings => [],
133
+ :aws_product_codes => [],
134
+ :tags => {}}
135
+ end
136
+ end
137
+
138
+ def tagend(name)
139
+ case name
140
+ when 'rootDeviceType' then
141
+ @instance[:root_device_type] = @text
142
+ when 'architecture' then
143
+ @instance[:architecture] = @text
144
+ when 'rootDeviceName' then
145
+ @instance[:root_device_name] = @text
146
+ # reservation
147
+ when 'reservationId' then
148
+ @reservation[:aws_reservation_id] = @text
149
+ when 'ownerId' then
150
+ @reservation[:aws_owner] = @text
151
+ when 'groupId' then
152
+ @reservation[:aws_groups] << @text
153
+ # instance
154
+ when 'instanceId' then
155
+ @instance[:aws_instance_id] = @text
156
+ when 'imageId' then
157
+ @instance[:aws_image_id] = @text
158
+ when 'dnsName' then
159
+ @instance[:dns_name] = @text
160
+ when 'privateDnsName' then
161
+ @instance[:private_dns_name] = @text
162
+ when 'reason' then
163
+ @instance[:aws_reason] = @text
164
+ when 'keyName' then
165
+ @instance[:ssh_key_name] = @text
166
+ when 'amiLaunchIndex' then
167
+ @instance[:ami_launch_index] = @text
168
+ when 'code' then
169
+ @instance[:aws_state_code] = @text
170
+ when 'name' then
171
+ @instance[:aws_state] = @text
172
+ when 'productCode' then
173
+ @instance[:aws_product_codes] << @text
174
+ when 'instanceType' then
175
+ @instance[:aws_instance_type] = @text
176
+ when 'launchTime' then
177
+ @instance[:aws_launch_time] = @text
178
+ when 'kernelId' then
179
+ @instance[:aws_kernel_id] = @text
180
+ when 'ramdiskId' then
181
+ @instance[:aws_ramdisk_id] = @text
182
+ when 'platform' then
183
+ @instance[:aws_platform] = @text
184
+ when 'availabilityZone' then
185
+ @instance[:aws_availability_zone] = @text
186
+ when 'privateIpAddress' then
187
+ @instance[:aws_private_ip_address] = @text
188
+ when 'subnetId' then
189
+ @instance[:subnet_id] = @text
190
+ when 'vpcId' then
191
+ @instance[:vpc_id] = @text
192
+ when 'key' then
193
+ @tag_key = @text
194
+ when 'value' then
195
+ @tag_value = @text
196
+ when 'deviceName' then
197
+ @device_name = @text
198
+ when 'volumeId' then
199
+ @volume_id = @text
200
+ when 'state'
201
+ if @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet/item/monitoring' || # DescribeInstances property
202
+ @xmlpath == 'RunInstancesResponse/instancesSet/item/monitoring' # RunInstances property
203
+ @instance[:monitoring_state] = @text
204
+ end
205
+ when 'item'
206
+ if @xmlpath=='DescribeInstancesResponse/reservationSet/item/instancesSet/item/tagSet' # Tags
207
+ @instance[:tags][@tag_key] = @tag_value
208
+ elsif @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet/item/blockDeviceMapping' # Block device mappings
209
+ @instance[:block_device_mappings] << { @device_name => @volume_id }
210
+ elsif @xmlpath == 'DescribeInstancesResponse/reservationSet/item/instancesSet' || # DescribeInstances property
211
+ @xmlpath == 'RunInstancesResponse/instancesSet' # RunInstances property
212
+ @reservation[:instances_set] << @instance
213
+ elsif @xmlpath=='DescribeInstancesResponse/reservationSet' # DescribeInstances property
214
+ @result << @reservation
215
+ end
216
+ when 'RunInstancesResponse' then
217
+ @result << @reservation # RunInstances property
218
+ end
219
+ end
220
+
221
+ def reset
222
+ @result = []
223
+ end
224
+ end
225
+
226
+ #-----------------------------------------------------------------
227
+ # PARSERS: Vpc
228
+ #-----------------------------------------------------------------
229
+
230
+ class QEc2VpcsParser < Aws::AwsParser #:nodoc:
231
+ def initialize(wrapper, opts = {})
232
+ super(opts)
233
+ @wrapper = wrapper
234
+ end
235
+
236
+ def tagstart(name, attribute)
237
+ @vpc = {} if name == @wrapper
238
+ end
239
+
240
+ def tagend(name)
241
+ case name
242
+ when 'vpcId' then
243
+ @vpc[:vpc_id] = @text
244
+ when 'state' then
245
+ @vpc[:state] = @text
246
+ when 'cidrBlock' then
247
+ @vpc[:cidr_block] = @text
248
+ when 'dhcpOptionsId' then
249
+ @vpc[:dhcp_options_id] = @text
250
+ when @wrapper
251
+ @result << @vpc
252
+ end
253
+ end
254
+
255
+ def reset
256
+ @result = []
257
+ end
258
+ end
259
+
260
+ class QEc2SubnetsParser < Aws::AwsParser #:nodoc
261
+ def initialize(wrapper, opts = {})
262
+ super(opts)
263
+ @wrapper = wrapper
264
+ end
265
+
266
+ def tagstart(name, attribute)
267
+ @subnet = {} if name == @wrapper
268
+ end
269
+
270
+ def tagend(name)
271
+ case name
272
+ when 'subnetId' then
273
+ @subnet[:subnet_id] = @text
274
+ when 'state' then
275
+ @subnet[:state] = @text
276
+ when 'vpcId' then
277
+ @subnet[:vpc_id] = @text
278
+ when 'cidrBlock' then
279
+ @subnet[:cidr_block] = @text
280
+ when 'availableIpAddressCount' then
281
+ @subnet[:available_ip_address_count] = @text
282
+ when 'availabilityZone' then
283
+ @subnet[:availability_zone] = @text
284
+ when @wrapper
285
+ @result << @subnet
286
+ end
287
+ end
288
+
289
+ def reset
290
+ @result = []
291
+ end
292
+ end
293
+ end
294
+ end