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
@@ -14,6 +14,7 @@
14
14
  # under the License.
15
15
 
16
16
  require 'fog'
17
+ require_relative '../../helpers/blob_stream_helper.rb'
17
18
 
18
19
  module Deltacloud
19
20
  module Drivers
@@ -195,7 +196,7 @@ class GoogleDriver < Deltacloud::BaseDriver
195
196
  def valid_credentials?(credentials)
196
197
  begin
197
198
  new_client(credentials).get_service && true
198
- rescue => e
199
+ rescue
199
200
  return false
200
201
  end
201
202
  return true
@@ -45,8 +45,13 @@ module Deltacloud
45
45
  results = []
46
46
  safely do
47
47
  if opts[:id]
48
- flavor = os.flavor(opts[:id])
49
- results << convert_from_flavor(flavor)
48
+ begin
49
+ flavor = os.flavor(opts[:id])
50
+ results << convert_from_flavor(flavor)
51
+ rescue => e
52
+ raise e unless e.message =~ /The resource could not be found/
53
+ results = []
54
+ end
50
55
  else
51
56
  results = os.flavors.collect do |f|
52
57
  convert_from_flavor(f)
@@ -62,17 +67,20 @@ module Deltacloud
62
67
  profiles = hardware_profiles(credentials)
63
68
  safely do
64
69
  if(opts[:id])
65
- img = os.get_image(opts[:id])
66
- results << convert_from_image(img, os.connection.authuser)
70
+ begin
71
+ img = os.get_image(opts[:id])
72
+ results << convert_from_image(img, os.connection.authuser)
73
+ rescue => e
74
+ raise e unless e.message =~ /Image not found/
75
+ results = []
76
+ end
67
77
  else
68
- results = os.list_images.collect do |img|
69
- convert_from_image(img, os.connection.authuser)
78
+ results = os.list_images.collect do |i|
79
+ convert_from_image(i, os.connection.authuser)
70
80
  end
71
81
  end
72
82
  end
73
- results.each do |img|
74
- img.hardware_profiles = profiles
75
- end
83
+ results.each { |img| img.hardware_profiles = profiles }
76
84
  filter_on(results, :owner_id, opts)
77
85
  end
78
86
 
@@ -108,6 +116,7 @@ module Deltacloud
108
116
  end
109
117
  end
110
118
  end
119
+ return [] if opts[:id] and opts[:id] != 'default'
111
120
  [ Realm.new( { :id=>'default',
112
121
  :name=>'default',
113
122
  :limit => limits,
@@ -119,11 +128,16 @@ module Deltacloud
119
128
  insts = []
120
129
  safely do
121
130
  if opts[:id]
122
- server = os.get_server(opts[:id].to_i)
123
- insts << convert_from_server(server, os.connection.authuser)
131
+ begin
132
+ server = os.get_server(opts[:id])
133
+ insts << convert_from_server(server, os.connection.authuser)
134
+ rescue => e
135
+ raise e unless e.message =~ /The resource could not be found/
136
+ insts = []
137
+ end
124
138
  else
125
- insts = os.list_servers_detail.collect do |server|
126
- convert_from_server(server, os.connection.authuser)
139
+ insts = os.list_servers_detail.collect do |s|
140
+ convert_from_server(s, os.connection.authuser)
127
141
  end
128
142
  end
129
143
  end
@@ -137,7 +151,7 @@ module Deltacloud
137
151
  #opts[:personality]: path1='server_path1'. content1='contents1', path2='server_path2', content2='contents2' etc
138
152
  params = {}
139
153
  params[:personality] = extract_personality(opts)
140
- params[:name] = (opts[:name] && opts[:name].length>0)? opts[:name] : Time.now.to_s
154
+ params[:name] = (opts[:name] && opts[:name].length>0)? opts[:name] : "server#{Time.now.to_s}"
141
155
  params[:imageRef] = image_id
142
156
  params[:flavorRef] = (opts[:hwp_id] && opts[:hwp_id].length>0) ?
143
157
  opts[:hwp_id] : hardware_profiles(credentials).first.name
@@ -157,7 +171,7 @@ module Deltacloud
157
171
  def reboot_instance(credentials, instance_id)
158
172
  os = new_client(credentials)
159
173
  safely do
160
- server = os.get_server(instance_id.to_i)
174
+ server = os.get_server(instance_id)
161
175
  server.reboot! # sends a hard reboot (power cycle) - could instead server.reboot("SOFT")
162
176
  convert_from_server(server, os.connection.authuser)
163
177
  end
@@ -166,7 +180,7 @@ module Deltacloud
166
180
  def destroy_instance(credentials, instance_id)
167
181
  os = new_client(credentials)
168
182
  safely do
169
- server = os.get_server(instance_id.to_i)
183
+ server = os.get_server(instance_id)
170
184
  server.delete!
171
185
  convert_from_server(server, os.connection.authuser)
172
186
  end
@@ -55,6 +55,7 @@ class RhevmDriver < Deltacloud::BaseDriver
55
55
  pending.to( :stopped ) .automatically
56
56
  stopped.to( :running ) .on( :start )
57
57
  running.to( :stopping ) .on( :stop )
58
+ stopping.to( :stopped ) .on( :stop )
58
59
  stopped.to( :finish ) .on( :destroy )
59
60
  end
60
61
 
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
  require 'rbvmomi'
18
- require 'deltacloud/drivers/vsphere/vsphere_client'
18
+ require_relative './vsphere_client.rb'
19
19
 
20
20
  module Deltacloud::Drivers::Vsphere
21
21
 
@@ -74,7 +74,6 @@ module Deltacloud::Drivers::Vsphere
74
74
  # Images are virtual machines with 'template' flag set to be true.
75
75
  # Thus we're getting them using find_vm and list_virtual_machines
76
76
  def images(credentials, opts={})
77
- cloud = new_client(credentials)
78
77
  img_arr = []
79
78
  profiles = hardware_profiles(credentials)
80
79
  # Skip traversing through all instances in all datacenters when ID
@@ -86,9 +85,8 @@ module Deltacloud::Drivers::Vsphere
86
85
  template_vms = list_virtual_machines(credentials).select { |vm| vm[:instance] && vm[:instance].summary.config[:template] }
87
86
  end
88
87
  img_arr = template_vms.collect do |image_hash|
89
- image, realm = image_hash[:instance], image_hash[:datastore]
88
+ image = image_hash[:instance]
90
89
  config = image.summary.config
91
- instance_state = convert_state(:instance, image.summary.runtime[:powerState])
92
90
  # Preload all properties to save multiple SOAP calls to vSphere
93
91
  properties = {
94
92
  :name => config[:name],
@@ -115,7 +113,6 @@ module Deltacloud::Drivers::Vsphere
115
113
  end
116
114
 
117
115
  def create_image(credentials, opts={})
118
- vsphere = new_client(credentials)
119
116
  safely do
120
117
  find_vm(credentials, opts[:id])[:instance].MarkAsTemplate
121
118
  end
@@ -132,7 +129,7 @@ module Deltacloud::Drivers::Vsphere
132
129
  else
133
130
  rootFolder = vsphere.serviceInstance.content.rootFolder
134
131
  rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).collect do |dc|
135
- dc.datastoreFolder.childEntity.collect { |datastore| convert_realm(datastore) }
132
+ dc.datastoreFolder.childEntity.collect { |ds| convert_realm(ds) }
136
133
  end.flatten
137
134
  end
138
135
  end
@@ -141,7 +138,6 @@ module Deltacloud::Drivers::Vsphere
141
138
  # List all running instances, across all datacenters. DeltaCloud API does
142
139
  # not yet support filtering instances by realm.
143
140
  def instances(credentials, opts={})
144
- cloud = new_client(credentials)
145
141
  inst_arr, machine_vms, pending_vms = [], [], []
146
142
  safely do
147
143
  # Using find_vm is a way faster than listing all virtual machines
@@ -213,12 +209,10 @@ module Deltacloud::Drivers::Vsphere
213
209
 
214
210
 
215
211
  def create_instance(credentials, image_id, opts={})
216
- vsphere = new_client(credentials)
217
212
  safely do
218
213
  if opts[:hwp_cpu]
219
214
  raise "Invalid CPU value. Must be in integer format" unless valid_cpu_value?(opts[:hwp_cpu])
220
215
  end
221
- rootFolder = vsphere.serviceInstance.content.rootFolder
222
216
  vm = find_vm(credentials, opts[:image_id])
223
217
  raise "ERROR: Could not find the image in given datacenter" unless vm[:instance]
224
218
  # New instance need valid resource pool and datastore to be placed.
@@ -55,7 +55,6 @@ module Deltacloud::Helpers
55
55
  filter.merge!(:owner_id => params[:owner_id]) if params[:owner_id]
56
56
  filter.merge!(:state => params[:state]) if params[:state]
57
57
  filter = {} if filter.keys.size.eql?(0)
58
- singular = model.to_s.singularize.to_sym
59
58
  begin
60
59
  @benchmark = Benchmark.measure do
61
60
  @elements = driver.send(model.to_sym, credentials, filter)
@@ -179,7 +178,6 @@ module Deltacloud::Helpers
179
178
  end
180
179
 
181
180
  def image_for_state(state)
182
- state_img = "stopped" if (state!='RUNNING' or state!='PENDING')
183
181
  capture_haml do
184
182
  haml_tag :img, :src => "/images/#{state}" % state.downcase, :title => state
185
183
  end
@@ -20,4 +20,6 @@ class FirewallRule < BaseModel
20
20
  attr_accessor :port_to
21
21
  attr_accessor :sources
22
22
  attr_accessor :direction #ingress egress
23
+ attr_accessor :rule_action #Accept/Deny - initially added for FGCP
24
+ attr_accessor :log_rule #log when rule triggered true/false - added for FGCP
23
25
  end
@@ -15,7 +15,7 @@
15
15
  # under the License.
16
16
 
17
17
  module Deltacloud
18
- class HardwareProfile
18
+ class HardwareProfile < BaseModel
19
19
 
20
20
  UNITS = {
21
21
  :memory => "MB",
@@ -28,6 +28,62 @@ module Deltacloud
28
28
  UNITS[name]
29
29
  end
30
30
 
31
+ class << self
32
+ def property(prop)
33
+ define_method(prop) do |*args|
34
+ values, opts, *ignored = *args
35
+ unless values.nil?
36
+ @properties[prop] = Property.new(prop, values, opts || {})
37
+ end
38
+ @properties[prop]
39
+ end
40
+ end
41
+ end
42
+
43
+ attr_accessor :name
44
+
45
+ property :cpu
46
+ property :architecture
47
+ property :memory
48
+ property :storage
49
+
50
+ def initialize(profile_id, &block)
51
+ @properties = {}
52
+ super(:id => profile_id)
53
+ result = instance_eval(&block) if block_given?
54
+ @name ||= profile_id
55
+ result
56
+ end
57
+
58
+ def each_property(&block)
59
+ @properties.each_value { |prop| yield prop }
60
+ end
61
+
62
+ def properties
63
+ @properties.values
64
+ end
65
+
66
+ def property(name)
67
+ @properties[name.to_sym]
68
+ end
69
+
70
+ def default?(prop, v)
71
+ property(prop) && property(prop).default.to_s == v
72
+ end
73
+
74
+ def include?(prop, v)
75
+ return false unless p = property(prop)
76
+ return true if p.kind == :range and (p.first..p.last).include?(v)
77
+ return true if p.kind == :enum and p.values.include?(v)
78
+ false
79
+ end
80
+
81
+ def params
82
+ @properties.values.inject([]) { |m, prop|
83
+ m << prop.to_param
84
+ }.compact
85
+ end
86
+
31
87
  class Property
32
88
  attr_reader :name, :kind, :default
33
89
  # kind == :range
@@ -82,10 +138,10 @@ module Deltacloud
82
138
  # overide fixed values.
83
139
  #
84
140
  # when :fixed then (v == @default.to_s)
85
- when :fixed then true
86
- when :range then match_type?(first, v) and (first..last).include?(v)
87
- when :enum then match_type?(values.first, v) and values.include?(v)
88
- else false
141
+ when :fixed then true
142
+ when :range then match_type?(first, v) and (first..last).include?(v)
143
+ when :enum then match_type?(values.first, v) and values.include?(v)
144
+ else false
89
145
  end
90
146
  end
91
147
 
@@ -115,59 +171,5 @@ module Deltacloud
115
171
  v.to_s
116
172
  end
117
173
  end
118
-
119
- class << self
120
- def property(prop)
121
- define_method(prop) do |*args|
122
- values, opts, *ignored = *args
123
- instvar = :"@#{prop}"
124
- unless values.nil?
125
- @properties[prop] = Property.new(prop, values, opts || {})
126
- end
127
- @properties[prop]
128
- end
129
- end
130
- end
131
-
132
- attr_reader :name
133
- property :cpu
134
- property :architecture
135
- property :memory
136
- property :storage
137
-
138
- def initialize(name,&block)
139
- @properties = {}
140
- @name = name
141
- instance_eval &block if block_given?
142
- end
143
-
144
- def each_property(&block)
145
- @properties.each_value { |prop| yield prop }
146
- end
147
-
148
- def properties
149
- @properties.values
150
- end
151
-
152
- def property(name)
153
- @properties[name.to_sym]
154
- end
155
-
156
- def default?(prop, v)
157
- property(prop) && property(prop).default.to_s == v
158
- end
159
-
160
- def include?(prop, v)
161
- return false unless p = property(prop)
162
- return true if p.kind == :range and (p.first..p.last).include?(v)
163
- return true if p.kind == :enum and p.values.include?(v)
164
- false
165
- end
166
-
167
- def params
168
- @properties.values.inject([]) { |m, prop|
169
- m << prop.to_param
170
- }.compact
171
- end
172
174
  end
173
175
  end
@@ -1,3 +1,4 @@
1
+ #
1
2
  # Licensed to the Apache Software Foundation (ASF) under one or more
2
3
  # contributor license agreements. See the NOTICE file distributed with
3
4
  # this work for additional information regarding copyright ownership. The
@@ -12,20 +13,7 @@
12
13
  # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
14
  # License for the specific language governing permissions and limitations
14
15
  # under the License.
15
- #
16
-
17
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', '..')
18
- require 'tests/common'
19
-
20
- require 'deltacloud/drivers'
21
- require 'deltacloud/drivers/mock/mock_driver'
22
-
23
- module DeltacloudUnitTest
24
16
 
25
- class StringTest < Test::Unit::TestCase
26
- def test_camelize
27
- "hello_camel".camelize.should == "helloCamel"
28
- "hello_camel_lots_of_humps".camelize.should == "helloCamelLotsOfHumps"
29
- end
30
- end
17
+ module Deltacloud
18
+ API_VERSION = '1.0.3' unless defined?(API_VERSION)
31
19
  end
@@ -17,6 +17,7 @@ require 'require_relative' if RUBY_VERSION < '1.9'
17
17
 
18
18
  require_relative './deltacloud/core_ext'
19
19
  require_relative './sinatra/rack_logger'
20
+ require_relative './deltacloud/version'
20
21
 
21
22
  module Deltacloud
22
23
 
@@ -38,12 +38,14 @@ module Deltacloud::EC2
38
38
  enable :xhtml
39
39
  enable :dump_errors
40
40
  enable :show_errors
41
- enable :method_override
42
41
  disable :show_exceptions
43
42
 
44
- set :version, Deltacloud[:ec2].version
45
- set :root_url, Deltacloud[:ec2].root_url
43
+ set :config, Deltacloud[:ec2]
44
+ set :root_url, config.root_url
45
+ set :root_path, config.root_url
46
+ set :version, config.version
46
47
  set :root, File.join(File.dirname(__FILE__), '..', '..')
48
+ set :public_folder, root + '/public'
47
49
  set :views, File.join(File.dirname(__FILE__), 'views')
48
50
 
49
51
  error Deltacloud::EC2::QueryParser::InvalidAction do
@@ -29,7 +29,7 @@ module Rack
29
29
  begin
30
30
  assumed_layout = args[1] == :layout
31
31
  args[1] = "#{args[1]}.#{@media_type}".to_sym if args[1].is_a?(::Symbol)
32
- render_without_format *args, &block
32
+ render_without_format(*args, &block)
33
33
  rescue Errno::ENOENT => e
34
34
  raise "ERROR: Missing template: #{args[1]}.#{args[0]}" unless assumed_layout
35
35
  raise e
@@ -39,65 +39,65 @@ module Rack
39
39
  end
40
40
  end
41
41
 
42
- module Helpers
43
-
44
- # This code was inherited from respond_to plugin
45
- # http://github.com/cehoffman/sinatra-respond_to
46
- #
47
- # This method is used to overide the default content_type returned from
48
- # rack-accept middleware.
49
- def self.included(klass)
50
- klass.class_eval do
51
- alias :content_type_without_save :content_type
52
- def content_type(*args)
53
- content_type_without_save *args
54
- request.env['rack-accept.formats'] = { args.first.to_sym => 1 }
55
- response['Content-Type']
56
- end
42
+ module Helpers
43
+
44
+ # This code was inherited from respond_to plugin
45
+ # http://github.com/cehoffman/sinatra-respond_to
46
+ #
47
+ # This method is used to overide the default content_type returned from
48
+ # rack-accept middleware.
49
+ def self.included(klass)
50
+ klass.class_eval do
51
+ alias :content_type_without_save :content_type
52
+ def content_type(*args)
53
+ content_type_without_save(*args)
54
+ request.env['rack-accept.formats'] = { args.first.to_sym => 1 }
55
+ response['Content-Type']
57
56
  end
58
57
  end
58
+ end
59
59
 
60
- def accepting_formats
61
- request.env['rack-accept.formats']
62
- end
60
+ def accepting_formats
61
+ request.env['rack-accept.formats']
62
+ end
63
63
 
64
- def static_file?(path)
65
- public_dir = File.expand_path(settings.public)
66
- path = File.expand_path(File.join(public_dir, unescape(path)))
67
- path[0, public_dir.length] == public_dir && File.file?(path)
64
+ def static_file?(path)
65
+ public_dir = File.expand_path(settings.public)
66
+ path = File.expand_path(File.join(public_dir, unescape(path)))
67
+ path[0, public_dir.length] == public_dir && File.file?(path)
68
+ end
69
+
70
+ def respond_to(&block)
71
+ wants = {}
72
+ def wants.method_missing(type, *args, &handler)
73
+ self[type] = handler
68
74
  end
75
+ yield wants
69
76
 
70
- def respond_to(&block)
71
- wants = {}
72
- def wants.method_missing(type, *args, &handler)
73
- self[type] = handler
74
- end
75
- yield wants
76
- if Deltacloud.default_frontend.name == :cimi
77
- @media_type = (accepting_formats.has_key?(:xml) ? [:xml, accepting_formats[:xml]] : nil)
78
- end
79
- @media_type ||= accepting_formats.to_a.sort { |a,b| a[1]<=>b[1] }.reverse.select do |format, priority|
80
- wants.keys.include?(format) == true
81
- end.first
82
- if @media_type and @media_type.kind_of? Symbol
83
- @media_type = [ @media_type ]
84
- end
85
- if @media_type and @media_type[0]
86
- @media_type = @media_type[0]
87
- if Rack::MediaType::ACCEPTED_MEDIA_TYPES[@media_type]
88
- headers 'Content-Type' => Rack::MediaType::ACCEPTED_MEDIA_TYPES[@media_type][:return]
89
- else
90
- headers 'Content-Type' => 'application/xml'
91
- end
92
- wants[@media_type.to_sym].call if wants[@media_type.to_sym]
77
+ if Deltacloud.default_frontend.name == :cimi
78
+ @media_type = (accepting_formats.has_key?(:xml) ? [:xml, accepting_formats[:xml]] : nil)
79
+ end if Deltacloud.respond_to? :default_frontend
80
+
81
+ @media_type ||= accepting_formats.to_a.sort { |a,b| a[1]<=>b[1] }.reverse.select do |format, priority|
82
+ wants.keys.include?(format) == true
83
+ end.first
84
+ if @media_type and @media_type.kind_of? Symbol
85
+ @media_type = [ @media_type ]
86
+ end
87
+ if @media_type and @media_type[0]
88
+ @media_type = @media_type[0]
89
+ if Rack::MediaType::ACCEPTED_MEDIA_TYPES[@media_type]
90
+ headers 'Content-Type' => Rack::MediaType::ACCEPTED_MEDIA_TYPES[@media_type][:return]
93
91
  else
94
- headers 'Content-Type' => nil
95
- status 406
92
+ headers 'Content-Type' => 'application/xml'
96
93
  end
94
+ wants[@media_type.to_sym].call if wants[@media_type.to_sym]
95
+ else
96
+ headers 'Content-Type' => nil
97
+ status 406
97
98
  end
98
-
99
+ end
99
100
  end
100
-
101
101
  end
102
102
 
103
103
  class MediaType < Sinatra::Base
@@ -119,7 +119,7 @@ module Rack
119
119
  accept, index = env['rack-accept.request'], {}
120
120
 
121
121
  # Skip everything when 'format' parameter is set in URL
122
- if env['rack.request.query_hash']["format"]
122
+ if env['rack.request.query_hash'] and env['rack.request.query_hash']["format"]
123
123
  media_type = case env['rack.request.query_hash']["format"]
124
124
  when 'html' then :html
125
125
  when 'xml' then :xml
@@ -135,8 +135,8 @@ module Rack
135
135
  sorted_media_types << 'application/xml' if sorted_media_types.empty?
136
136
  # Choose the right format with the media type according to the priority
137
137
  ACCEPTED_MEDIA_TYPES.each do |format, definition|
138
- definition[:match].each do |media_type|
139
- break if index[format] = sorted_media_types.index(media_type)
138
+ definition[:match].each do |mt|
139
+ break if index[format] = sorted_media_types.index(mt)
140
140
  end
141
141
  end
142
142
  # Reject formats with no/nil priority