deltacloud-core 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/Rakefile +63 -7
  2. data/bin/deltacloudd +29 -17
  3. data/config.ru +5 -3
  4. data/config/drivers/ec2.yaml +9 -0
  5. data/config/drivers/google.yaml +3 -0
  6. data/config/drivers/openstack.yaml +3 -0
  7. data/deltacloud-core.gemspec +1 -1
  8. data/lib/cimi/dependencies.rb +62 -0
  9. data/lib/cimi/helpers/cimi_helper.rb +50 -0
  10. data/lib/cimi/model.rb +52 -0
  11. data/lib/cimi/model/action.rb +24 -0
  12. data/lib/cimi/model/base.rb +249 -0
  13. data/lib/cimi/model/cloud_entry_point.rb +48 -0
  14. data/lib/cimi/model/entity_metadata.rb +83 -0
  15. data/lib/cimi/model/entity_metadata_collection.rb +31 -0
  16. data/lib/cimi/model/errors.rb +40 -0
  17. data/lib/cimi/model/machine.rb +227 -0
  18. data/lib/cimi/model/machine_admin.rb +59 -0
  19. data/lib/cimi/model/machine_admin_collection.rb +34 -0
  20. data/lib/cimi/model/machine_collection.rb +34 -0
  21. data/lib/cimi/model/machine_configuration.rb +67 -0
  22. data/lib/cimi/model/machine_configuration_collection.rb +34 -0
  23. data/lib/cimi/model/machine_image.rb +46 -0
  24. data/lib/cimi/model/machine_image_collection.rb +34 -0
  25. data/lib/cimi/model/machine_template.rb +41 -0
  26. data/lib/cimi/model/machine_template_collection.rb +34 -0
  27. data/lib/cimi/model/network.rb +69 -0
  28. data/lib/cimi/model/network_collection.rb +34 -0
  29. data/lib/cimi/model/network_configuration.rb +50 -0
  30. data/lib/cimi/model/network_configuration_collection.rb +34 -0
  31. data/lib/cimi/model/network_template.rb +26 -0
  32. data/lib/cimi/model/schema.rb +277 -0
  33. data/lib/cimi/model/volume.rb +103 -0
  34. data/lib/cimi/model/volume_collection.rb +34 -0
  35. data/lib/cimi/model/volume_configuration.rb +60 -0
  36. data/lib/cimi/model/volume_configuration_collection.rb +34 -0
  37. data/lib/cimi/model/volume_image.rb +49 -0
  38. data/lib/cimi/model/volume_image_collection.rb +34 -0
  39. data/lib/cimi/model/volume_template.rb +23 -0
  40. data/lib/cimi/model/volume_template_collection.rb +34 -0
  41. data/lib/cimi/server.rb +575 -0
  42. data/lib/deltacloud/base_driver/base_driver.rb +11 -1
  43. data/lib/deltacloud/core_ext.rb +2 -0
  44. data/lib/deltacloud/core_ext/array.rb +25 -0
  45. data/lib/deltacloud/core_ext/hash.rb +7 -0
  46. data/lib/deltacloud/core_ext/proc.rb +31 -0
  47. data/lib/deltacloud/core_ext/string.rb +15 -0
  48. data/lib/deltacloud/drivers/condor/condor_driver.rb +2 -1
  49. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +32 -10
  50. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +1 -1
  51. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +1 -1
  52. data/lib/deltacloud/drivers/google/google_driver.rb +233 -0
  53. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +7 -2
  54. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +7 -2
  55. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +7 -2
  56. data/lib/deltacloud/drivers/mock/mock_client.rb +17 -0
  57. data/lib/deltacloud/drivers/mock/mock_driver.rb +82 -8
  58. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +1 -1
  59. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +47 -0
  60. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +8 -8
  61. data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +122 -49
  62. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +42 -22
  63. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +1 -1
  64. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +3 -2
  65. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +2 -2
  66. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +25 -4
  67. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +35 -12
  68. data/lib/deltacloud/hardware_profile.rb +34 -10
  69. data/lib/deltacloud/helpers/application_helper.rb +3 -28
  70. data/lib/deltacloud/helpers/blob_stream.rb +2 -1
  71. data/lib/deltacloud/models.rb +2 -0
  72. data/lib/deltacloud/models/bucket.rb +1 -1
  73. data/lib/deltacloud/models/image.rb +1 -1
  74. data/lib/deltacloud/models/instance.rb +2 -1
  75. data/lib/deltacloud/models/instance_address.rb +56 -0
  76. data/lib/deltacloud/models/provider.rb +27 -0
  77. data/{server.rb → lib/deltacloud/server.rb} +72 -14
  78. data/lib/deltacloud/validation.rb +31 -10
  79. data/lib/sinatra/rabbit.rb +34 -26
  80. data/lib/sinatra/rack_accept.rb +5 -5
  81. data/lib/sinatra/rack_matrix_params.rb +6 -2
  82. data/lib/sinatra/rack_syslog.rb +3 -3
  83. data/lib/sinatra/static_assets.rb +1 -1
  84. data/lib/sinatra/url_for.rb +1 -7
  85. data/public/images/bread-bg.png +0 -0
  86. data/public/images/logo-wide.png +0 -0
  87. data/public/images/topbar-bg.png +0 -0
  88. data/public/javascripts/application.js +5 -0
  89. data/public/javascripts/cmwgapp.js +249 -0
  90. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  91. data/public/javascripts/jquery.mobile-1.0rc1.min.js +170 -0
  92. data/public/stylesheets/images/icons-18-black.png +0 -0
  93. data/public/stylesheets/images/icons-18-white.png +0 -0
  94. data/public/stylesheets/images/icons-36-black.png +0 -0
  95. data/public/stylesheets/images/icons-36-white.png +0 -0
  96. data/public/stylesheets/jquery.mobile-1.0rc1.min.css +12 -0
  97. data/public/stylesheets/new.css +4 -0
  98. data/support/fedora/deltacloud-core.init +20 -13
  99. data/tests/cimi/features/step_definitions/common_steps.rb +59 -0
  100. data/tests/cimi/features/step_definitions/machine_images_steps.rb +0 -0
  101. data/tests/cimi/features/step_definitions/machines_steps.rb +99 -0
  102. data/tests/cimi/features/step_definitions/volumes_steps.rb +115 -0
  103. data/tests/cimi/features/support/env.rb +53 -0
  104. data/tests/common.rb +89 -11
  105. data/tests/core_ext/string.rb +31 -0
  106. data/tests/drivers/google/api_test.rb +35 -0
  107. data/tests/drivers/google/buckets_test.rb +116 -0
  108. data/tests/drivers/google/setup.rb +38 -0
  109. data/tests/drivers/mock/instances_test.rb +20 -5
  110. data/tests/drivers/openstack/api_test.rb +41 -0
  111. data/tests/drivers/openstack/hardware_profiles_test.rb +53 -0
  112. data/tests/drivers/openstack/images_test.rb +40 -0
  113. data/tests/drivers/openstack/instances_test.rb +163 -0
  114. data/tests/drivers/openstack/realms_test.rb +36 -0
  115. data/tests/drivers/openstack/setup.rb +20 -0
  116. data/tests/drivers/rackspace/buckets_test.rb +145 -0
  117. data/tests/drivers/rackspace/setup.rb +3 -3
  118. data/tests/drivers/rhevm/api_test.rb +1 -1
  119. data/tests/drivers/rhevm/images_test.rb +2 -2
  120. data/tests/drivers/rhevm/instances_test.rb +10 -12
  121. data/tests/drivers/rhevm/realms_test.rb +4 -4
  122. data/tests/drivers/rhevm/setup.rb +3 -3
  123. data/tests/rabbit_test.rb +1 -1
  124. data/views/api/show.html.haml +13 -0
  125. data/views/cimi/cloudEntryPoint/index.html.haml +5 -0
  126. data/views/cimi/cloudEntryPoint/index.xml.haml +9 -0
  127. data/views/cimi/collection/index.html.haml +45 -0
  128. data/views/cimi/collection/response.xml.haml +3 -0
  129. data/views/cimi/error.html.haml +31 -0
  130. data/views/cimi/errors/400.html.haml +41 -0
  131. data/views/cimi/errors/400.xml.haml +3 -0
  132. data/views/cimi/errors/401.html.haml +41 -0
  133. data/views/cimi/errors/401.xml.haml +2 -0
  134. data/views/cimi/errors/403.html.haml +42 -0
  135. data/views/cimi/errors/403.xml.haml +2 -0
  136. data/views/cimi/errors/404.html.haml +29 -0
  137. data/views/cimi/errors/404.xml.haml +2 -0
  138. data/views/cimi/errors/405.html.haml +29 -0
  139. data/views/cimi/errors/405.xml.haml +5 -0
  140. data/views/cimi/errors/500.html.haml +43 -0
  141. data/views/cimi/errors/500.xml.haml +6 -0
  142. data/views/cimi/errors/502.html.haml +43 -0
  143. data/views/cimi/errors/502.xml.haml +7 -0
  144. data/views/cimi/errors/backend_capability_failure.html.haml +29 -0
  145. data/views/cimi/layout.html.haml +32 -0
  146. data/views/cimi/machine_configurations/show.html.haml +159 -0
  147. data/views/cimi/machine_configurations/show.xml.haml +27 -0
  148. data/views/cimi/machine_images/show.html.haml +79 -0
  149. data/views/cimi/machine_images/show.xml.haml +17 -0
  150. data/views/cimi/machines/show.html.haml +177 -0
  151. data/views/cimi/machines/show.xml.haml +28 -0
  152. data/views/cimi/volumes/show.html.haml +68 -0
  153. data/views/cimi/volumes/show.xml.haml +17 -0
  154. data/views/drivers/show.html.haml +10 -5
  155. data/views/drivers/show.xml.haml +9 -4
  156. data/views/error.html.haml +2 -2
  157. data/views/errors/500.xml.haml +7 -1
  158. data/views/instances/index.html.haml +1 -1
  159. data/views/instances/new.html.haml +19 -16
  160. data/views/instances/show.html.haml +7 -2
  161. data/views/instances/show.xml.haml +8 -7
  162. data/views/layout.html.haml +2 -2
  163. data/views/storage_volumes/show.html.haml +1 -1
  164. metadata +296 -204
  165. data/public/javascripts/jquery.mobile-1.0b1.min.js +0 -146
  166. data/public/stylesheets/jquery.mobile-1.0b1.min.css +0 -8
@@ -33,6 +33,10 @@ module Deltacloud
33
33
 
34
34
  class RHEVMDriver < Deltacloud::BaseDriver
35
35
 
36
+ def supported_collections
37
+ DEFAULT_COLLECTIONS - [:storage_snapshots]
38
+ end
39
+
36
40
  feature :instances, :user_name do
37
41
  constraint :max_length, 50
38
42
  end
@@ -64,25 +68,29 @@ class RHEVMDriver < Deltacloud::BaseDriver
64
68
 
65
69
  define_instance_states do
66
70
  start.to( :pending ) .automatically
67
- pending.to( :running ) .on( :start )
68
71
  pending.to( :stopped ) .automatically
69
72
  stopped.to( :running ) .on( :start )
70
73
  running.to( :stopping ) .on( :stop )
71
74
  stopped.to( :finish ) .on( :destroy )
72
75
  end
73
76
 
77
+ def providers(credentials)
78
+ client = new_client(credentials)
79
+ safely do
80
+ client.datacenters.collect { |dc| convert_provider(dc) }
81
+ end
82
+ end
83
+
74
84
  #
75
85
  # Realms
76
86
  #
77
87
 
78
- def realms(credentials, opts=nil)
88
+ def realms(credentials, opts={})
79
89
  client = new_client(credentials)
80
90
  realm_arr = []
81
91
  safely do
82
- clusters = client.clusters
83
- clusters.each do |r|
84
- d = client.datacenters(:id => r.datacenter.id).first
85
- realm_arr << convert_realm(r, d)
92
+ realm_arr = client.clusters.collect do |r|
93
+ convert_realm(r, client.datacenter(r.datacenter.id))
86
94
  end
87
95
  end
88
96
  realm_arr = filter_on( realm_arr, :id, opts )
@@ -93,12 +101,10 @@ class RHEVMDriver < Deltacloud::BaseDriver
93
101
  client = new_client(credentials)
94
102
  img_arr = []
95
103
  safely do
96
- templates = client.templates
97
104
  if (!opts.nil? && opts[:id])
98
- templates = templates.select{|t| opts[:id] == t.id}
99
- end
100
- templates.each do |t|
101
- img_arr << convert_image(client, t)
105
+ img_arr << convert_image(client, client.template(opts[:id]))
106
+ else
107
+ img_arr = client.templates.collect { |t| convert_image(client, t) }
102
108
  end
103
109
  end
104
110
  img_arr = filter_on( img_arr, :architecture, opts )
@@ -214,12 +220,20 @@ class RHEVMDriver < Deltacloud::BaseDriver
214
220
  private
215
221
 
216
222
  def new_client(credentials)
217
- url = api_provider
223
+ url, datacenter = api_provider.split(';')
218
224
  safely do
219
- ::RHEVM::Client.new(credentials.user, credentials.password, url)
225
+ ::RHEVM::Client.new(credentials.user, credentials.password, url, datacenter)
220
226
  end
221
227
  end
222
228
 
229
+ def convert_provider(dc)
230
+ Provider.new(
231
+ :id => dc.id,
232
+ :name => dc.name,
233
+ :url => [api_provider.split(';').first, dc.id].join(';')
234
+ )
235
+ end
236
+
223
237
  def confserver_ip(uuid)
224
238
  client = RestClient::Resource::new(ENV['CONFIG_SERVER_ADDRESS'])
225
239
  client["/ip/%s/%s" % [ (ENV['CONFIG_SERVER_VERSION'] || '0.0.1'), uuid]].get(:accept => 'text/plain').body.strip rescue nil
@@ -234,15 +248,21 @@ class RHEVMDriver < Deltacloud::BaseDriver
234
248
  :hwp_storage => "#{storage_size}"
235
249
  )
236
250
  public_addresses = []
237
- # First check if RHEV-M guest tools are installed and IP address is offered by them
238
- public_addresses << inst.ip if inst.ip
239
- # Second check if ConfServer broker is running, then ask for an IP there
240
- public_addresses << confserver_ip(inst.id) if ENV['CONFIG_SERVER_ADDRESS'] and public_addresses.empty?
241
- public_addresses.compact!
242
- # If everything fails fallback to report MAC address
243
- public_addresses = inst.macs if public_addresses.empty?
244
- public_addresses.flatten!
245
- public_addresses << inst.vnc if inst.vnc
251
+ # First try to get IP address from RHEV-M. This require rhev-agent package
252
+ # installed on guest
253
+ public_addresses << InstanceAddress.new(inst.ip) if inst.ip
254
+ # ConfServer will overide the IP address returned by RHEV-M guest agent
255
+ if ENV['CONFIG_SERVER_ADDRESS']
256
+ ip = confserver_ip(inst.id)
257
+ public_addresses = [ InstanceAddress.new(ip) ]
258
+ end
259
+ # If IP retrieval failed, fallback to VNC and MAC address
260
+ if public_addresses.empty?
261
+ public_addresses = inst.macs.collect { |mac_address| InstanceAddress.new(mac_address, :type => :mac) }
262
+ end
263
+ if inst.vnc
264
+ public_addresses << InstanceAddress.new(inst.vnc[:address], :port => inst.vnc[:port], :type => :vnc)
265
+ end
246
266
  Instance.new(
247
267
  :id => inst.id,
248
268
  :name => inst.name,
@@ -131,7 +131,7 @@ class RimuHostingDriver < Deltacloud::BaseDriver
131
131
  :owner_id => "root",
132
132
  :instance_profile => InstanceProfile.new("none"),
133
133
  :actions => instance_actions_for("RUNNING"),
134
- :public_addresses => inst["allocated_ips"]["primary_ip"],
134
+ :public_addresses => [ InstanceAddress.new(inst["allocated_ips"]["primary_ip"] ),
135
135
  :launch_time => inst["billing_info"]["order_date"]["iso_format"]
136
136
  })
137
137
  end
@@ -51,7 +51,8 @@ class SBCDriver < Deltacloud::BaseDriver
51
51
  def realms(credentials, opts={})
52
52
  sbc_client = new_client(credentials)
53
53
  doc = sbc_client.list_locations
54
- doc.xpath('ns2:DescribeLocationsResponse/Location').map { |loc| convert_location(loc) }
54
+ realms = doc.xpath('ns2:DescribeLocationsResponse/Location').map { |loc| convert_location(loc) }
55
+ realms = filter_on(realms, :id, opts)
55
56
  end
56
57
 
57
58
  #
@@ -206,7 +207,7 @@ class SBCDriver < Deltacloud::BaseDriver
206
207
  :realm_id => instance["location"],
207
208
  :state => state,
208
209
  :actions => instance_actions_for(state),
209
- :public_addresses => [instance["primaryIP"]["ip"]],
210
+ :public_addresses => [ InstanceAddress.new(instance["primaryIP"]["ip"]) ],
210
211
  :private_addresses => [],
211
212
  :instance_profile => InstanceProfile.new(instance["instanceType"].gsub('/', '-')),
212
213
  :launch_time => instance["launchTime"],
@@ -262,8 +262,8 @@ end
262
262
  :realm_id => "US-Miami",
263
263
  :state => current_state,
264
264
  :actions => instance_actions_for(current_state),
265
- :public_addresses => vapp_public_ip,
266
- :private_addresses => vapp_private_ip,
265
+ :public_addresses => [ InstanceAddress.new(vapp_public_ip) ],
266
+ :private_addresses => [ InstanceAddress.new(vapp_private_ip) ],
267
267
  :instance_profile => profile
268
268
  } )
269
269
  end
@@ -32,7 +32,8 @@ module Deltacloud::Drivers::VSphere
32
32
  rootFolder = vsphere.serviceInstance.content.rootFolder
33
33
  vm = {}
34
34
  rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).each do |dc|
35
- dc.datastoreFolder.childEntity.collect do |datastore|
35
+ dslist = list_datastores(dc.datastoreFolder)
36
+ dslist.each do |datastore|
36
37
  vm[:instance] = datastore.vm.find { |x| x.name == name }
37
38
  if vm[:instance]
38
39
  vm[:datastore] = datastore.name
@@ -63,6 +64,7 @@ module Deltacloud::Drivers::VSphere
63
64
  dc = rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).select do |dc|
64
65
  dc.datastoreFolder.childEntity.find { |d| d.name == name }.nil? == false
65
66
  end.flatten.compact.first
67
+ dc = rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).first
66
68
  dc.hostFolder.childEntity.collect.first.resourcePool
67
69
  end
68
70
  end
@@ -77,8 +79,12 @@ module Deltacloud::Drivers::VSphere
77
79
  safely do
78
80
  rootFolder = vsphere.serviceInstance.content.rootFolder
79
81
  rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).collect do |dc|
80
- dc.datastoreFolder.childEntity.find { |d| d.name == name }
81
- end.flatten.compact.first
82
+ list_datastores(dc.datastoreFolder).each do |d|
83
+ if d.name == name
84
+ return d
85
+ end
86
+ end
87
+ end
82
88
  end
83
89
  end
84
90
 
@@ -90,7 +96,7 @@ module Deltacloud::Drivers::VSphere
90
96
  vms = []
91
97
  rootFolder = vsphere.serviceInstance.content.rootFolder
92
98
  rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).each do |dc|
93
- dc.datastoreFolder.childEntity.each do |datastore|
99
+ list_datastores(dc.datastoreFolder).each do |datastore|
94
100
  vms += datastore.vm.collect { |vm| { :instance => vm, :datastore => datastore.name } unless vm.nil? }
95
101
  stored_tasks(datastore, vsphere) do |task|
96
102
  if task.info.entity.class == RbVmomi::VIM::VirtualMachine
@@ -102,6 +108,21 @@ module Deltacloud::Drivers::VSphere
102
108
  vms.flatten.compact
103
109
  end
104
110
 
111
+ # This helper will traverse across all datacenters and folders and gather
112
+ # all datastores available on vSphere
113
+ #
114
+ def list_datastores(df)
115
+ datastores = []
116
+ df.childEntity.each do |object|
117
+ if object.class.to_s == 'Folder'
118
+ datastores += list_datastores(object)
119
+ else
120
+ datastores << object
121
+ end
122
+ end
123
+ datastores
124
+ end
125
+
105
126
  # Map given instance to task. Task name is used as a filename.
106
127
  #
107
128
  def map_task_to_instance(datastore, task_key, new_instance)
@@ -42,13 +42,17 @@ module Deltacloud::Drivers::VSphere
42
42
  safely do
43
43
  service = vsphere.serviceInstance.content
44
44
  max_memory, max_cpu_cores = [], []
45
+ #
46
+ # Note: Memory is being hardcoded now to range 512MB to 2GB
47
+ # JIRA: DTACLOUD-123
48
+ #
45
49
  service.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).each do |dc|
46
- max_memory << dc.hostFolder.childEntity.first.summary.effectiveMemory
50
+ # max_memory << dc.hostFolder.childEntity.first.summary.effectiveMemory
47
51
  max_cpu_cores << dc.hostFolder.childEntity.first.summary.numCpuCores
48
52
  end
49
53
  [Deltacloud::HardwareProfile::new('default') do
50
54
  cpu (1..max_cpu_cores.min)
51
- memory (128..max_memory.min)
55
+ memory (512..2048)
52
56
  architecture ['x86_64', 'i386']
53
57
  end]
54
58
  end
@@ -171,11 +175,15 @@ module Deltacloud::Drivers::VSphere
171
175
  :hwp_cpu => properties[:cpus],
172
176
  :hwp_memory => properties[:memory],
173
177
  :hwp_storage => properties[:storage])
174
-
175
178
  # We're getting IP address from 'vmware guest tools'.
176
179
  # If guest tools are not installed, we return list of MAC addresses
177
180
  # assigned to this instance.
178
- instance_address = vm.guest[:net].empty? ? vm.macs.values.first : vm.guest[:net].first[:ipAddress].first
181
+ public_addresses = []
182
+ if vm.guest[:net].empty?
183
+ public_addresses = vm.macs.values.collect { |mac_address| InstanceAddress.new(mac_address, :type => :mac) }
184
+ else
185
+ public_addresses = [InstanceAddress.new(vm.guest[:net].first[:ipAddress].first)]
186
+ end
179
187
  Instance.new(
180
188
  :id => properties[:name],
181
189
  :name => properties[:name],
@@ -184,7 +192,7 @@ module Deltacloud::Drivers::VSphere
184
192
  :description => properties[:full_name],
185
193
  :realm_id => realm_id,
186
194
  :state => instance_state,
187
- :public_addresses => instance_address,
195
+ :public_addresses => public_addresses,
188
196
  :private_addresses => [],
189
197
  :instance_profile => instance_profile,
190
198
  :actions => instance_actions_for( instance_state ),
@@ -205,6 +213,9 @@ module Deltacloud::Drivers::VSphere
205
213
  def create_instance(credentials, image_id, opts)
206
214
  vsphere = new_client(credentials)
207
215
  safely do
216
+ if opts[:hwp_cpu]
217
+ raise "Invalid CPU value. Must be in integer format" unless valid_cpu_value?(opts[:hwp_cpu])
218
+ end
208
219
  rootFolder = vsphere.serviceInstance.content.rootFolder
209
220
  vm = find_vm(credentials, opts[:image_id])
210
221
  raise "ERROR: Could not find the image in given datacenter" unless vm[:instance]
@@ -306,7 +317,7 @@ module Deltacloud::Drivers::VSphere
306
317
 
307
318
  # Reboot an instance, given its id.
308
319
  def reboot_instance(credentials, id)
309
- find_vm(credentials, id)[:instance].ResetVM_Task
320
+ find_vm(credentials, id)[:instance].RebootGuest
310
321
  end
311
322
 
312
323
  # Start an instance, given its id.
@@ -351,6 +362,10 @@ module Deltacloud::Drivers::VSphere
351
362
  status 502
352
363
  end
353
364
 
365
+ on /Invalid/ do
366
+ status 400
367
+ end
368
+
354
369
  end
355
370
 
356
371
  def valid_credentials?(credentials)
@@ -378,12 +393,16 @@ module Deltacloud::Drivers::VSphere
378
393
  end
379
394
 
380
395
  def convert_realm(datastore)
381
- Realm::new(
382
- :id => datastore.name,
383
- :name => datastore.name,
384
- :limit => datastore.summary.freeSpace,
385
- :state => datastore.summary.accessible ? 'AVAILABLE' : 'UNAVAILABLE'
386
- )
396
+ if datastore.class.to_s == 'Folder'
397
+ datastore.childEntity.collect { |datastorenew| convert_realm(datastorenew) }
398
+ else
399
+ Realm::new(
400
+ :id => datastore.name,
401
+ :name => datastore.name,
402
+ :limit => datastore.summary.freeSpace,
403
+ :state => datastore.summary.accessible ? 'AVAILABLE' : 'UNAVAILABLE'
404
+ )
405
+ end
387
406
  end
388
407
 
389
408
  def convert_state(object, state)
@@ -404,6 +423,10 @@ module Deltacloud::Drivers::VSphere
404
423
  new_state
405
424
  end
406
425
 
426
+ def valid_cpu_value?(val)
427
+ true if val =~ /^(\d+)$/
428
+ end
429
+
407
430
  def valid_memory_value?(val)
408
431
  true if (val.to_i%4) == 0
409
432
  end
@@ -68,26 +68,50 @@ module Deltacloud
68
68
  kind == :fixed
69
69
  end
70
70
 
71
- def to_param
72
- return nil if kind == :fixed
73
- if kind == :range
74
- # FIXME: We can't validate ranges currently
75
- args = [param, :string, :optional]
76
- else
77
- args = [param, :string, :optional, values.collect { |v| v.to_s} ]
71
+ def valid?(v)
72
+ v = convert_property_value_type(v)
73
+ case kind
74
+ # NOTE:
75
+ # Currently we cannot validate fixed values because of UI
76
+ # limitation. In UI we have multiple hwp_* properties which overide
77
+ # each other.
78
+ # Then provider have one 'static' hardware profile and one
79
+ # 'customizable' when user select the static one the UI also send
80
+ # values from the customizable one (which will lead to a validation
81
+ # error because validation algorith will think that client want to
82
+ # overide fixed values.
83
+ #
84
+ # 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
78
89
  end
79
- Validation::Param.new(args)
90
+ end
91
+
92
+ def to_param
93
+ Validation::Param.new([param, :string, :optional, []])
80
94
  end
81
95
 
82
96
  def include?(v)
83
97
  if kind == :fixed
84
98
  return v == value
85
- elsif kind == :range
86
- return v >= first && v <= last
87
99
  else
88
100
  return values.include?(v)
89
101
  end
90
102
  end
103
+
104
+ private
105
+
106
+ def match_type?(reference, value)
107
+ true if reference.class == value.class
108
+ end
109
+
110
+ def convert_property_value_type(v)
111
+ return v.to_f if v =~ /(\d+)\.(\d+)/
112
+ return v.to_i if v =~ /(\d+)/
113
+ v.to_s
114
+ end
91
115
  end
92
116
 
93
117
  class << self
@@ -22,12 +22,12 @@ module ApplicationHelper
22
22
  include Deltacloud
23
23
 
24
24
  def bread_crumb
25
- s = "<ul class='breadcrumb'><li class='first'><a href='#{root_url}'>&#948</a></li>"
25
+ s = "<ul class='breadcrumb'><li class='first'><a href='#{settings.root_url}'>&#948</a></li>"
26
26
  url = request.path_info.split('?') #remove extra query string parameters
27
27
  levels = url[0].split('/') #break up url into different levels
28
28
  levels.each_with_index do |level, index|
29
29
  unless level.blank?
30
- next if "/#{level}" == Sinatra::UrlForHelper::DEFAULT_URI_PREFIX
30
+ next if "/#{level}" == settings.root_url
31
31
  if index == levels.size-1 || (level == levels[levels.size-2] && levels[levels.size-1].to_i > 0)
32
32
  s += "<li class='subsequent'>#{level.gsub(/_/, ' ')}</li>\n" unless level.to_i > 0
33
33
  else
@@ -177,7 +177,7 @@ module ApplicationHelper
177
177
  def link_to_documentation
178
178
  return '' unless request.env['REQUEST_URI']
179
179
  uri = request.env['REQUEST_URI'].dup
180
- uri.gsub!(Sinatra::UrlForHelper::DEFAULT_URI_PREFIX,
180
+ uri.gsub!(settings.root_url,
181
181
  api_url_for(:docs)) unless uri.include?("docs") #i.e. if already serving under /api/docs, leave it be
182
182
  '<a href="%s">[ Documentation ]</a>' % uri
183
183
  end
@@ -248,31 +248,6 @@ module ApplicationHelper
248
248
  end
249
249
  end
250
250
 
251
- # FIXME: It would be cleaner if we stored the type of address explicitly in
252
- # public_addresses instead of guessing it; especially since now a RHEV-M
253
- # vnc address in theory could look like type ipv4.
254
- #
255
- # Instead of pushing just the address onto public_addresses, we should
256
- # just push a pair [type, address], i.e. [:vnc, "172.16.0.1"] or a hash
257
- # { :vnc => "172.16.0.1" }
258
- #
259
- def address_type(address)
260
- case address
261
- when /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/; :ipv4
262
- when /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:[\-\d]+)$/; :vnc
263
- when /^(\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2})?$/; :mac
264
- else :hostname
265
- end
266
- end
267
-
268
- def format_address(address, opts={})
269
- capture_haml do
270
- haml_tag :address, { :type => address_type(address) }.merge(opts) do
271
- haml_concat address
272
- end
273
- end
274
- end
275
-
276
251
  def translate_error_code(code)
277
252
  case code
278
253
  when 400; { :message => "Bad Request" }
@@ -104,6 +104,7 @@ module Thin
104
104
  end
105
105
 
106
106
  require 'net/http'
107
+ require 'net/https'
107
108
  #monkey patch for Net:HTTP
108
109
  module Net
109
110
  class HTTP
@@ -186,7 +187,7 @@ class BlobStreamIO
186
187
  def self.is_put_blob(request = nil)
187
188
  path = request.env['PATH_INFO']
188
189
  method = request.env['REQUEST_METHOD']
189
- if ( path =~ /^#{Regexp.escape(Sinatra::UrlForHelper::DEFAULT_URI_PREFIX)}\/buckets/ && method == 'PUT' )
190
+ if ( path =~ /^#{Regexp.escape(settings.root_url)}\/buckets/ && method == 'PUT' )
190
191
  return true
191
192
  else
192
193
  return false