deltacloud-core 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. data/deltacloud-core.gemspec +4 -7
  2. data/lib/cimi/collections/address_templates.rb +4 -42
  3. data/lib/cimi/collections/addresses.rb +5 -43
  4. data/lib/cimi/collections/base.rb +11 -3
  5. data/lib/cimi/collections/cloud_entry_point.rb +1 -1
  6. data/lib/cimi/collections/credentials.rb +4 -43
  7. data/lib/cimi/collections/forwarding_group_templates.rb +2 -20
  8. data/lib/cimi/collections/forwarding_groups.rb +2 -21
  9. data/lib/cimi/collections/machine_configurations.rb +2 -20
  10. data/lib/cimi/collections/machine_images.rb +4 -42
  11. data/lib/cimi/collections/machine_templates.rb +4 -42
  12. data/lib/cimi/collections/machines.rb +14 -64
  13. data/lib/cimi/collections/network_configurations.rb +2 -20
  14. data/lib/cimi/collections/network_port_configurations.rb +2 -21
  15. data/lib/cimi/collections/network_port_templates.rb +2 -23
  16. data/lib/cimi/collections/network_ports.rb +6 -46
  17. data/lib/cimi/collections/network_templates.rb +2 -21
  18. data/lib/cimi/collections/networks.rb +4 -40
  19. data/lib/cimi/collections/resource_metadata.rb +2 -21
  20. data/lib/cimi/collections/system_templates.rb +4 -45
  21. data/lib/cimi/collections/systems.rb +65 -82
  22. data/lib/cimi/collections/volume_configurations.rb +4 -45
  23. data/lib/cimi/collections/volume_images.rb +4 -42
  24. data/lib/cimi/collections/volume_templates.rb +5 -44
  25. data/lib/cimi/collections/volumes.rb +4 -48
  26. data/lib/cimi/helpers.rb +1 -0
  27. data/lib/cimi/helpers/cimi_helper.rb +1 -1
  28. data/lib/cimi/helpers/cimi_rabbit_helper.rb +113 -0
  29. data/lib/cimi/helpers/database_helper.rb +1 -2
  30. data/lib/cimi/models.rb +12 -11
  31. data/lib/cimi/models/action.rb +0 -4
  32. data/lib/cimi/models/address.rb +0 -38
  33. data/lib/cimi/models/address_create.rb +0 -31
  34. data/lib/cimi/models/address_template.rb +0 -47
  35. data/lib/cimi/models/address_template_create.rb +0 -16
  36. data/lib/cimi/models/base.rb +2 -74
  37. data/lib/cimi/models/cloud_entry_point.rb +2 -30
  38. data/lib/cimi/models/collection.rb +8 -25
  39. data/lib/cimi/models/credential.rb +0 -34
  40. data/lib/cimi/models/credential_create.rb +0 -26
  41. data/lib/cimi/models/credential_template.rb +0 -2
  42. data/lib/cimi/models/disk.rb +0 -56
  43. data/lib/cimi/models/forwarding_group.rb +0 -8
  44. data/lib/cimi/models/forwarding_group_template.rb +0 -8
  45. data/lib/cimi/models/machine.rb +4 -129
  46. data/lib/cimi/models/machine_configuration.rb +0 -31
  47. data/lib/cimi/models/machine_create.rb +1 -29
  48. data/lib/cimi/models/machine_image.rb +0 -28
  49. data/lib/cimi/models/machine_image_create.rb +0 -19
  50. data/lib/cimi/models/machine_template.rb +5 -39
  51. data/lib/cimi/models/machine_template_create.rb +0 -12
  52. data/lib/cimi/models/machine_volume.rb +0 -65
  53. data/lib/cimi/models/network.rb +0 -32
  54. data/lib/cimi/models/network_configuration.rb +0 -15
  55. data/lib/cimi/models/network_create.rb +0 -23
  56. data/lib/cimi/models/network_port.rb +0 -73
  57. data/lib/cimi/models/network_port_configuration.rb +0 -8
  58. data/lib/cimi/models/network_port_template.rb +0 -8
  59. data/lib/cimi/models/network_template.rb +2 -12
  60. data/lib/cimi/models/resource.rb +0 -6
  61. data/lib/cimi/models/resource_metadata.rb +1 -95
  62. data/lib/cimi/models/schema.rb +28 -32
  63. data/lib/cimi/models/system.rb +15 -39
  64. data/lib/cimi/models/system_address.rb +26 -0
  65. data/lib/cimi/models/system_create.rb +20 -0
  66. data/lib/cimi/models/system_credential.rb +26 -0
  67. data/lib/cimi/models/system_forwarding_group.rb +26 -0
  68. data/lib/cimi/models/system_machine.rb +26 -0
  69. data/lib/cimi/models/system_network.rb +26 -0
  70. data/lib/cimi/models/system_network_port.rb +26 -0
  71. data/lib/cimi/models/system_system.rb +26 -0
  72. data/lib/cimi/models/system_template.rb +15 -31
  73. data/lib/cimi/models/system_volume.rb +26 -0
  74. data/lib/cimi/models/volume.rb +0 -59
  75. data/lib/cimi/models/volume_configuration.rb +1 -64
  76. data/lib/cimi/models/volume_configuration_create.rb +22 -0
  77. data/lib/cimi/models/volume_create.rb +0 -38
  78. data/lib/cimi/models/volume_image.rb +0 -30
  79. data/lib/cimi/models/volume_image_create.rb +0 -25
  80. data/lib/cimi/models/volume_template.rb +2 -43
  81. data/lib/cimi/models/volume_template_create.rb +0 -12
  82. data/lib/cimi/service.rb +82 -0
  83. data/lib/cimi/service/action.rb +21 -0
  84. data/lib/cimi/service/address.rb +56 -0
  85. data/lib/cimi/service/address_create.rb +45 -0
  86. data/lib/cimi/service/address_template.rb +71 -0
  87. data/lib/cimi/service/address_template_create.rb +34 -0
  88. data/lib/cimi/service/base.rb +266 -0
  89. data/lib/cimi/service/cloud_entry_point.rb +53 -0
  90. data/lib/cimi/service/credential.rb +52 -0
  91. data/lib/cimi/service/credential_create.rb +38 -0
  92. data/lib/cimi/service/credential_template.rb +20 -0
  93. data/lib/cimi/service/disk.rb +75 -0
  94. data/lib/cimi/service/forwarding_group.rb +26 -0
  95. data/lib/cimi/service/forwarding_group_template.rb +26 -0
  96. data/lib/cimi/service/machine.rb +154 -0
  97. data/lib/cimi/service/machine_configuration.rb +54 -0
  98. data/lib/cimi/service/machine_create.rb +49 -0
  99. data/lib/cimi/service/machine_image.rb +47 -0
  100. data/lib/cimi/service/machine_image_create.rb +35 -0
  101. data/lib/cimi/service/machine_template.rb +61 -0
  102. data/lib/cimi/service/machine_template_create.rb +29 -0
  103. data/lib/cimi/service/machine_volume.rb +74 -0
  104. data/lib/cimi/service/network.rb +51 -0
  105. data/lib/cimi/service/network_configuration.rb +36 -0
  106. data/lib/cimi/service/network_create.rb +39 -0
  107. data/lib/cimi/service/network_port.rb +97 -0
  108. data/lib/cimi/service/network_port_configuration.rb +26 -0
  109. data/lib/cimi/service/network_port_template.rb +26 -0
  110. data/lib/cimi/service/network_template.rb +28 -0
  111. data/lib/cimi/service/resource_metadata.rb +44 -0
  112. data/lib/cimi/service/system.rb +45 -0
  113. data/lib/cimi/service/system_address.rb +34 -0
  114. data/lib/cimi/service/system_create.rb +39 -0
  115. data/lib/cimi/service/system_credential.rb +34 -0
  116. data/lib/cimi/service/system_forwarding_group.rb +34 -0
  117. data/lib/cimi/service/system_machine.rb +34 -0
  118. data/lib/cimi/service/system_network.rb +34 -0
  119. data/lib/cimi/service/system_network_port.rb +34 -0
  120. data/lib/cimi/service/system_system.rb +34 -0
  121. data/lib/cimi/service/system_template.rb +32 -0
  122. data/lib/cimi/service/system_volume.rb +34 -0
  123. data/lib/cimi/service/volume.rb +81 -0
  124. data/lib/cimi/service/volume_configuration.rb +92 -0
  125. data/lib/cimi/service/volume_configuration_create.rb +29 -0
  126. data/lib/cimi/service/volume_create.rb +47 -0
  127. data/lib/cimi/service/volume_image.rb +44 -0
  128. data/lib/cimi/service/volume_image_create.rb +42 -0
  129. data/lib/cimi/service/volume_template.rb +61 -0
  130. data/lib/cimi/service/volume_template_create.rb +29 -0
  131. data/lib/db/entity.rb +16 -1
  132. data/lib/deltacloud/collections/addresses.rb +2 -2
  133. data/lib/deltacloud/collections/buckets.rb +16 -18
  134. data/lib/deltacloud/collections/drivers.rb +4 -4
  135. data/lib/deltacloud/collections/firewalls.rb +5 -5
  136. data/lib/deltacloud/collections/images.rb +3 -3
  137. data/lib/deltacloud/collections/instance_states.rb +4 -4
  138. data/lib/deltacloud/collections/instances.rb +22 -13
  139. data/lib/deltacloud/collections/keys.rb +2 -2
  140. data/lib/deltacloud/collections/load_balancers.rb +16 -13
  141. data/lib/deltacloud/collections/storage_snapshots.rb +3 -3
  142. data/lib/deltacloud/collections/storage_volumes.rb +5 -5
  143. data/lib/deltacloud/core_ext/ordered_hash.rb +0 -4
  144. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +8 -0
  145. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +4 -3
  146. data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +266 -19
  147. data/lib/deltacloud/drivers/google/google_driver.rb +6 -0
  148. data/lib/deltacloud/drivers/mock/mock_driver.rb +2 -2
  149. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +166 -54
  150. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +2 -0
  151. data/lib/deltacloud/helpers/blob_stream_helper.rb +0 -2
  152. data/lib/deltacloud/helpers/deltacloud_helper.rb +22 -22
  153. data/lib/deltacloud/helpers/driver_helper.rb +4 -7
  154. data/lib/deltacloud/helpers/rabbit_helper.rb +5 -0
  155. data/lib/deltacloud/server.rb +4 -4
  156. data/lib/deltacloud/version.rb +1 -1
  157. data/lib/deltacloud_rack.rb +6 -1
  158. data/lib/ec2/server.rb +6 -1
  159. data/tests/cimi/collections/common.rb +33 -0
  160. data/tests/cimi/collections/machines_test.rb +19 -0
  161. data/tests/cimi/collections/system_templates_test.rb +47 -0
  162. data/tests/cimi/collections/volumes_test.rb +42 -0
  163. data/tests/cimi/db/database_helper_test.rb +7 -4
  164. data/tests/deltacloud/drivers_test.rb +1 -1
  165. data/tests/drivers/ec2/common.rb +4 -1
  166. data/tests/drivers/fgcp/common.rb +1 -2
  167. data/tests/drivers/gogrid/common.rb +1 -2
  168. data/tests/drivers/google/common.rb +1 -1
  169. data/tests/drivers/models/address_test.rb +2 -2
  170. data/tests/drivers/models/base_test.rb +2 -2
  171. data/tests/drivers/models/blob_test.rb +2 -2
  172. data/tests/drivers/models/instance_address_test.rb +8 -8
  173. data/tests/drivers/models/instance_profile_test.rb +2 -2
  174. data/tests/drivers/models/keys_test.rb +4 -4
  175. data/tests/drivers/models/metrics_test.rb +3 -3
  176. data/tests/drivers/openstack/common.rb +1 -2
  177. data/views/addresses/_address.html.haml +3 -3
  178. data/views/addresses/associate.html.haml +3 -3
  179. data/views/addresses/index.html.haml +2 -2
  180. data/views/addresses/index.xml.haml +2 -2
  181. data/views/addresses/show.html.haml +7 -7
  182. data/views/addresses/show.xml.haml +9 -9
  183. data/views/api/show.html.haml +2 -2
  184. data/views/api/show.xml.haml +1 -1
  185. data/views/blobs/new.html.haml +1 -1
  186. data/views/blobs/show.html.haml +8 -8
  187. data/views/blobs/show.xml.haml +7 -7
  188. data/views/buckets/index.html.haml +1 -1
  189. data/views/buckets/index.xml.haml +2 -2
  190. data/views/buckets/show.html.haml +7 -7
  191. data/views/buckets/show.xml.haml +6 -6
  192. data/views/drivers/index.html.haml +1 -1
  193. data/views/drivers/index.xml.haml +1 -1
  194. data/views/drivers/show.html.haml +6 -6
  195. data/views/drivers/show.xml.haml +5 -5
  196. data/views/error.html.haml +2 -2
  197. data/views/errors/backend_capability_failure.xml.haml +3 -3
  198. data/views/errors/common.html.haml +7 -7
  199. data/views/errors/common.xml.haml +5 -5
  200. data/views/firewalls/index.html.haml +1 -1
  201. data/views/firewalls/index.xml.haml +1 -1
  202. data/views/firewalls/new_rule.html.haml +1 -1
  203. data/views/firewalls/show.html.haml +8 -8
  204. data/views/firewalls/show.xml.haml +9 -9
  205. data/views/hardware_profiles/index.html.haml +1 -1
  206. data/views/hardware_profiles/index.xml.haml +2 -2
  207. data/views/hardware_profiles/show.html.haml +3 -3
  208. data/views/hardware_profiles/show.xml.haml +4 -4
  209. data/views/images/index.html.haml +1 -1
  210. data/views/images/index.xml.haml +2 -2
  211. data/views/images/new.html.haml +2 -2
  212. data/views/images/show.html.haml +14 -14
  213. data/views/images/show.xml.haml +14 -14
  214. data/views/instance_states/show.html.haml +1 -1
  215. data/views/instance_states/show.png.erb +2 -2
  216. data/views/instance_states/show.xml.haml +1 -1
  217. data/views/instances/index.html.haml +1 -1
  218. data/views/instances/index.xml.haml +2 -2
  219. data/views/instances/new.html.haml +22 -14
  220. data/views/instances/run.html.haml +2 -2
  221. data/views/instances/run.xml.haml +3 -3
  222. data/views/instances/run_command.html.haml +4 -4
  223. data/views/instances/show.html.haml +27 -27
  224. data/views/instances/show.xml.haml +37 -37
  225. data/views/keys/index.html.haml +1 -1
  226. data/views/keys/index.xml.haml +2 -2
  227. data/views/keys/show.html.haml +10 -10
  228. data/views/keys/show.xml.haml +12 -12
  229. data/views/load_balancers/index.html.haml +1 -1
  230. data/views/load_balancers/index.xml.haml +2 -2
  231. data/views/load_balancers/new.html.haml +1 -8
  232. data/views/load_balancers/show.html.haml +10 -10
  233. data/views/load_balancers/show.xml.haml +9 -9
  234. data/views/metrics/index.html.haml +1 -1
  235. data/views/metrics/index.xml.haml +2 -2
  236. data/views/metrics/show.html.haml +2 -2
  237. data/views/metrics/show.xml.haml +3 -3
  238. data/views/realms/index.html.haml +1 -1
  239. data/views/realms/index.xml.haml +2 -2
  240. data/views/realms/show.html.haml +6 -6
  241. data/views/realms/show.xml.haml +5 -5
  242. data/views/storage_snapshots/index.html.haml +1 -1
  243. data/views/storage_snapshots/index.xml.haml +2 -2
  244. data/views/storage_snapshots/show.html.haml +6 -6
  245. data/views/storage_snapshots/show.xml.haml +4 -4
  246. data/views/storage_volumes/attach.html.haml +2 -2
  247. data/views/storage_volumes/index.html.haml +1 -1
  248. data/views/storage_volumes/index.xml.haml +2 -2
  249. data/views/storage_volumes/show.html.haml +19 -19
  250. data/views/storage_volumes/show.xml.haml +21 -21
  251. metadata +77 -65
  252. data/views/cimi/cloudEntryPoint/index.html.haml +0 -5
  253. data/views/cimi/cloudEntryPoint/index.xml.haml +0 -9
  254. data/views/cimi/collection/index.html.haml +0 -45
  255. data/views/cimi/collection/response.xml.haml +0 -3
  256. data/views/cimi/error.html.haml +0 -31
  257. data/views/cimi/errors/400.xml.haml +0 -3
  258. data/views/cimi/errors/401.xml.haml +0 -2
  259. data/views/cimi/errors/403.xml.haml +0 -2
  260. data/views/cimi/errors/404.xml.haml +0 -2
  261. data/views/cimi/errors/405.xml.haml +0 -5
  262. data/views/cimi/errors/500.xml.haml +0 -6
  263. data/views/cimi/errors/502.xml.haml +0 -7
  264. data/views/cimi/layout.html.haml +0 -32
  265. data/views/cimi/machine_configurations/show.html.haml +0 -159
  266. data/views/cimi/machine_configurations/show.xml.haml +0 -27
  267. data/views/cimi/machine_images/show.html.haml +0 -79
  268. data/views/cimi/machine_images/show.xml.haml +0 -17
  269. data/views/cimi/machines/show.html.haml +0 -177
  270. data/views/cimi/machines/show.xml.haml +0 -28
  271. data/views/cimi/volumes/show.html.haml +0 -68
  272. data/views/cimi/volumes/show.xml.haml +0 -17
  273. data/views/docs/collection.html.haml +0 -26
  274. data/views/docs/collection.xml.haml +0 -14
  275. data/views/docs/index.html.haml +0 -11
  276. data/views/docs/index.xml.haml +0 -5
  277. data/views/docs/operation.html.haml +0 -33
  278. data/views/docs/operation.xml.haml +0 -10
  279. data/views/root/index.html.haml +0 -4
@@ -29,39 +29,268 @@ module Deltacloud::Drivers::Fgcp
29
29
  def systems(credentials, opts={})
30
30
  safely do
31
31
  client = new_client(credentials)
32
+ xml = client.list_vsys['vsyss']
33
+ return [] if xml.nil?
34
+ context = opts[:env]
32
35
 
33
- if opts and opts[:id]
34
- vsys_ids = [opts[:id]]
35
- else
36
- xml = client.list_vsys['vsyss']
37
- return [] if xml.nil?
38
- vsys_ids = xml[0]['vsys'].collect { |vsys| vsys['vsysId'][0] }
39
- end
40
-
41
- vsys_ids.collect do |vsys_id|
42
- vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
36
+ systems = xml[0]['vsys'].collect do |vsys|
37
+ vsys_id = vsys['vsysId'][0]
43
38
  vsys_description_el = vsys['description']
44
39
  CIMI::Model::System.new(
45
- :id => vsys['vsysId'][0],
40
+ :id => vsys_id,
46
41
  :name => vsys['vsysName'][0],
47
- # :machines => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/machines?realm_id=#{vsys['vsysId'][0]}",
48
- # :volumes => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/volumes?realm_id=#{vsys['vsysId'][0]}",
49
- # :networks => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/networks?realm_id=#{vsys['vsysId'][0]}",
50
- # :addresses => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/addresses?realm_id=#{vsys['vsysId'][0]}",
51
- :description => vsys_description_el ? vsys_description_el[0] : nil
42
+ :description => vsys_description_el ? vsys_description_el[0] : nil,
43
+ :machines => { :href => context.system_machines_url(vsys_id) },
44
+ :volumes => { :href => context.system_volumes_url(vsys_id) },
45
+ :networks => { :href => context.system_networks_url(vsys_id) },
46
+ :addresses => { :href => context.system_addresses_url(vsys_id) },
47
+ :operations => []
52
48
  )
53
49
  end
50
+ systems = systems.select { |s| opts[:id] == s[:id] } if opts[:id]
51
+
52
+ # now add system state and advertise operations
53
+ systems.each do |system|
54
+ vservers = client.list_vservers(system[:id])['vservers'][0]['vserver']
55
+ if vservers.nil?
56
+ system[:state] = client.get_vsys_status(system[:id])['vsysStatus'][0] == 'DEPLOYING' ? 'CREATING' : 'MIXED'
57
+ else
58
+ vservers.each do |vserver|
59
+ state = @@MACHINE_STATE_MAP[client.get_vserver_status(vserver['vserverId'][0])['vserverStatus'][0]]
60
+ system[:state] ||= state
61
+ system[:operations] << { :href => context.system_url("#{system[:id]}/start"), :rel => "http://schemas.dmtf.org/cimi/1/action/start" } if state == 'STOPPED'
62
+ system[:operations] << { :href => context.system_url("#{system[:id]}/stop"), :rel => "http://schemas.dmtf.org/cimi/1/action/stop" } if state == 'STARTED'
63
+ if system[:state] != state
64
+ system[:state] = 'MIXED'
65
+ # this case could have been caused by one machine in capturing state and one in e.g. creating,
66
+ # but just advertise both operations to cut it short
67
+ system[:operations] << { :href => context.system_url("#{system[:id]}/start"), :rel => "http://schemas.dmtf.org/cimi/1/action/start" }
68
+ system[:operations] << { :href => context.system_url("#{system[:id]}/stop"), :rel => "http://schemas.dmtf.org/cimi/1/action/stop" }
69
+ break
70
+ end
71
+ end
72
+ system[:operations].uniq!
73
+ end
74
+ # check for special case: in destroy_system the FW is stopped before the system is deleted
75
+ system[:state] = 'DELETING' if ((vservers.nil? and system[:state] != 'CREATING') or system[:state] == 'STOPPED') and
76
+ ['STOPPED', 'STOPPING'].include? client.get_efm_status("#{system[:id]}-S-0001")['efmStatus'][0]
77
+ system[:operations] << { :href => context.system_url(system[:id]), :rel => "delete" } if system[:state] == 'STOPPED'
78
+ end
79
+ systems
80
+ end
81
+ end
82
+
83
+ def create_system(credentials, opts={})
84
+ safely do
85
+ client = new_client(credentials)
86
+ name = opts[:name] || "system_#{Time.now.to_s}"
87
+ template = opts[:system_template]
88
+ template_id = template.id || template.href.to_s.gsub(/.*\/([^\/]+)$/, '\1')
89
+ vsys_id = client.create_vsys(template_id, name)['vsysId'][0]
90
+ opts[:id] = vsys_id
91
+ systems(credentials, opts).first
92
+ end
93
+ end
94
+
95
+ def destroy_system(credentials, id)
96
+ delete_firewall(credentials, :id => "#{id}-S-0001")
97
+ end
98
+
99
+ def start_system(credentials, opts={})
100
+ safely do
101
+ client = new_client(credentials)
102
+ context = opts[:env]
103
+ vsys_id = opts[:id]
104
+ xml = client.list_vservers(vsys_id)['vservers']
105
+ return unless xml and xml[0]['vserver']
106
+
107
+ # FIXME: maybe this should be done in a separate thread (in case of gigantic number of servers)
108
+ # FIXME: error handling (ok to exit loop? Cleanup?) - at this time the cimi spec is quiet on that
109
+ xml[0]['vserver'].each do |vserver|
110
+ begin
111
+ client.start_vserver(vserver['vserverId'][0])
112
+ rescue Exception => ex
113
+ raise ex if not ex.message =~ /(ALREADY_STARTED|ILLEGAL_STATE).*/
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ def stop_system(credentials, opts={})
120
+ safely do
121
+ client = new_client(credentials)
122
+ context = opts[:env]
123
+ vsys_id = opts[:id]
124
+ xml = client.list_vservers(vsys_id)['vservers']
125
+ return unless xml and xml[0]['vserver']
126
+
127
+ # FIXME: maybe this should be done in a separate thread (in case of gigantic number of servers)
128
+ # FIXME: error handling (ok to exit loop? Cleanup?) - at this time the cimi spec is quiet on that
129
+ xml[0]['vserver'].each do |vserver|
130
+ begin
131
+ client.stop_vserver(vserver['vserverId'][0])
132
+ rescue Exception => ex
133
+ raise ex if not ex.message =~ /(ALREADY_STOPPED|ILLEGAL_STATE).*/
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ def system_machines(credentials, opts={})
140
+ safely do
141
+ client = new_client(credentials)
142
+ #if :expand not specified, list of hrefs only, else convert from :instances?
143
+ context = opts[:env]
144
+ vsys_id = opts[:system_id]
145
+ xml = client.list_vservers(vsys_id)['vservers']
146
+ return [] unless xml and xml[0]['vserver']
147
+
148
+ machines = xml[0]['vserver'].collect do |vserver|
149
+ vserver_id = vserver['vserverId'][0]
150
+ CIMI::Model::SystemMachine.new(
151
+ :id => context.system_machine_url(:id => vsys_id, :ent_id => vserver_id),
152
+ :name => vserver['vserverName'][0],
153
+ :machine => { :href => context.machine_url(vserver_id)}
154
+ ) unless opts[:id] and opts[:id] != vserver_id
155
+ end
156
+ machines.compact
157
+ end
158
+ end
159
+
160
+ def system_volumes(credentials, opts={})
161
+ safely do
162
+ client = new_client(credentials)
163
+ context = opts[:env]
164
+ vsys_id = opts[:system_id]
165
+ #if :expand not specified, list of hrefs only, else convert from :storage_volumes?
166
+ xml = client.list_vdisk(vsys_id)['vdisks']
167
+ return [] unless xml and xml[0]['vdisk']
168
+
169
+ volumes = xml[0]['vdisk'].collect do |vdisk|
170
+ vdisk_id = vdisk['vdiskId'][0]
171
+ CIMI::Model::SystemVolume.new(
172
+ :id => context.system_volume_url(:id => vsys_id, :ent_id => vdisk_id),
173
+ :name => vdisk['vdiskName'][0],
174
+ :volume => { :href => context.volume_url(vdisk_id)}
175
+ ) unless (opts[:id] and opts[:id] != vdisk_id) or determine_storage_type(vdisk_id) == 'system'
176
+ end
177
+ volumes.compact
178
+ end
179
+ end
180
+
181
+ def system_networks(credentials, opts={})
182
+ safely do
183
+ client = new_client(credentials)
184
+ context = opts[:env]
185
+ vsys_id = opts[:system_id]
186
+ #if :expand not specified, list of hrefs only, else ??
187
+ vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
188
+
189
+ # retrieve network segment (subnet) info
190
+ networks = vsys['vnets'][0]['vnet'].collect do |vnet|
191
+ network_id = vnet['networkId'][0]
192
+ network_id =~ /.*-(\w)$/
193
+ CIMI::Model::SystemNetwork.new(
194
+ :id => context.system_network_url(:id => vsys_id, :ent_id => network_id),
195
+ :name => "#{$1} for system #{vsys['vsysName'][0]}",
196
+ :network => { :href => context.network_url(network_id)}
197
+ ) unless opts[:id] and opts[:id] != network_id
198
+ end
199
+ networks.compact
200
+ end
201
+ end
202
+
203
+ def system_addresses(credentials, opts={})
204
+ safely do
205
+ client = new_client(credentials)
206
+ context = opts[:env]
207
+ vsys_id = opts[:system_id]
208
+ #if :expand not specified, list of hrefs only, else ??
209
+ xml = client.list_public_ips(vsys_id)['publicips']
210
+ return [] unless xml and xml[0]['publicip']
211
+
212
+ # retrieve network segment (subnet) info
213
+ addresses = xml[0]['publicip'].collect do |ip|
214
+ address = ip['address'][0]
215
+ CIMI::Model::SystemAddress.new(
216
+ :id => context.system_address_url(:id => vsys_id, :ent_id => address),
217
+ :name => "Public IP address allocated to system #{ip['vsysId'][0]}",
218
+ :address => { :href => context.address_url(address)}
219
+ ) unless opts[:id] and opts[:id] != address
220
+ end
221
+ addresses.compact
222
+ end
223
+ end
224
+
225
+ def system_forwarding_groups(credentials, opts={})
226
+ safely do
227
+ client = new_client(credentials)
228
+ context = opts[:env]
229
+ vsys_id = opts[:system_id]
230
+ #if :expand not specified, list of hrefs only, else ??
231
+ vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
232
+
233
+ group_id = "#{vsys_id}-INTRA"
234
+ groups = []
235
+ groups << CIMI::Model::SystemForwardingGroup.new(
236
+ :id => context.system_forwarding_group_url(:id => vsys_id, :ent_id => group_id),
237
+ :name => "Routing group of system #{vsys['vsysName'][0]}",
238
+ :forwarding_group => { :href => context.forwarding_group_url(group_id)}
239
+ ) unless vsys['vnets'][0]['vnet'].size <= 1 or (opts[:id] and opts[:id] != group_id)
240
+ groups
54
241
  end
55
242
  end
56
243
 
57
244
  def system_templates(credentials, opts={})
58
245
  safely do
59
246
  client = new_client(credentials)
247
+ context = opts[:env]
60
248
  templates = client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].collect do |desc|
249
+ conf = client.get_vsys_descriptor_configuration(desc['vsysdescriptorId'][0])['vsysdescriptor'][0]
250
+ components = conf['vservers'][0]['vserver'].collect do |vserver|
251
+ next if vserver['vserverType'][0] == 'firewall'
252
+ volume_templates = vserver['vdisks'][0]['vdisk'].collect do |vdisk|
253
+ CIMI::Model::VolumeTemplateWithLocation.new(
254
+ :volume_config => CIMI::Model::VolumeConfiguration.new(:capacity => vdisk['size'][0].to_i * 1024 * 1024)
255
+ )
256
+ end if vserver['vdisks']
257
+ {
258
+ :name => desc['vsysdescriptorName'][0],
259
+ :description => '',
260
+ :type => "http://schemas.dmtf.org/cimi/1/Machine",
261
+ :machine_template => CIMI::Model::MachineTemplate.new(
262
+ :name => vserver['vserverName'][0],
263
+ :description => '',
264
+ :machine_config => CIMI::Service::MachineConfiguration.find(vserver['vserverType'][0], context),
265
+ :machine_image => { :href => context.machine_image_url(vserver['diskimageId'][0]) },
266
+ :volume_templates => volume_templates
267
+ )
268
+ }
269
+ end
270
+ # add network templates
271
+ if conf['vsysdescriptorId'][0] =~ /(1|2|3)-tier Skeleton/
272
+ tiers = ['DMZ', 'Secure1', 'Secure2']
273
+ components += 1.upto($1.to_i).collect do |n|
274
+ {
275
+ :name => tiers[n],
276
+ :description => "Network tier #{n}",
277
+ :type => "http://schemas.dmtf.org/cimi/1/Network",
278
+ :network_template => CIMI::Model::NetworkTemplate.new(
279
+ :name => 'Private network',
280
+ :description => '',
281
+ :network_config => CIMI::Model::NetworkConfiguration.new(
282
+ :network_type => 'PRIVATE',
283
+ :class_of_service => 'BRONZE'
284
+ )
285
+ )
286
+ }
287
+ end
288
+ end
61
289
  CIMI::Model::SystemTemplate.new(
62
- :id => desc['vsysdescriptorId'][0],
63
- :name => desc['vsysdescriptorName'][0],
64
- :description => desc['description'][0]
290
+ :id => desc['vsysdescriptorId'][0],
291
+ :name => desc['vsysdescriptorName'][0],
292
+ :description => desc['description'][0],
293
+ :component_descriptors => components.compact
65
294
  )
66
295
  end
67
296
  templates = templates.select { |t| opts[:id] == t[:id] } if opts[:id]
@@ -69,6 +298,24 @@ module Deltacloud::Drivers::Fgcp
69
298
  end
70
299
  end
71
300
 
301
+ # FGCP instance states mapped to CIMI machine states
302
+ @@MACHINE_STATE_MAP = {
303
+ 'DEPLOYING' => 'CREATING',
304
+ 'RUNNING' => 'STARTED',
305
+ 'STOPPING' => 'STOPPING',
306
+ 'STOPPED' => 'STOPPED',
307
+ 'STARTING' => 'STARTING', # not sure about this one
308
+ 'FAILOVER' => 'STARTED',
309
+ 'UNEXPECTED_STOP' => 'STOPPED',
310
+ 'RESTORING' => 'RESTORING',
311
+ 'BACKUP_ING' => 'CAPTURING',
312
+ 'ERROR' => 'ERROR', # allowed actions limited
313
+ 'START_ERROR' => 'STOPPED', # allowed actions are same as for STOPPED
314
+ 'STOP_ERROR' => 'STARTED', # allowed actions are same as for RUNNING
315
+ 'REGISTERING' => 'PENDING',
316
+ 'CHANGE_TYPE' => 'PENDING'
317
+ }
318
+
72
319
  end
73
320
 
74
321
  end
@@ -16,6 +16,12 @@
16
16
  require 'fog'
17
17
  require_relative '../../helpers/blob_stream_helper.rb'
18
18
 
19
+ module Excon
20
+ class Connection
21
+ def connection;@data;end
22
+ end
23
+ end
24
+
19
25
  module Deltacloud
20
26
  module Drivers
21
27
  module Google
@@ -114,7 +114,7 @@ module Deltacloud::Drivers::Mock
114
114
  results
115
115
  end
116
116
 
117
- def filter_by_owner(images, owner_id)
117
+ def filter_by_owner(credentials, images, owner_id)
118
118
  return images unless owner_id
119
119
  if owner_id == 'self'
120
120
  images.select { |e| e.owner_id == credentials.user }
@@ -131,7 +131,7 @@ module Deltacloud::Drivers::Mock
131
131
  images = @client.build_all(Image)
132
132
 
133
133
  images = filter_on(images, opts, :id, :architecture)
134
- images = filter_by_owner(images, opts[:owner_id])
134
+ images = filter_by_owner(credentials, images, opts[:owner_id])
135
135
 
136
136
  # Add hardware profiles to each image
137
137
  images = images.map { |i| (i.hardware_profiles = hardware_profiles(nil)) && i }
@@ -32,7 +32,110 @@ module Deltacloud::Drivers::Mock
32
32
  return []
33
33
  end
34
34
  end
35
- systems.map{|sys|convert_cimi_mock_urls(:system, sys ,opts[:env])}.flatten
35
+ systems.map{|sys| convert_urls(sys, opts[:env])}.flatten
36
+ end
37
+
38
+ def create_system(credentials, opts={})
39
+ check_credentials(credentials)
40
+ id = "#{opts[:env].send("systems_url")}/#{opts[:name]}"
41
+ sys_hsh = { "id"=> id,
42
+ "name" => opts[:name],
43
+ "description" => opts[:description],
44
+ "created" => Time.now,
45
+ "state" => "STOPPED",
46
+ "systemTemplate"=> { "href" => opts[:system_template].id },
47
+ "operations" => [{"rel"=>"http://schemas.dmtf.org/cimi/1/action/start", "href"=> "#{id}/start"},
48
+ {"rel"=>"edit", "href"=> id},
49
+ {"rel"=>"delete", "href"=> id}] }
50
+ system = CIMI::Model::System.from_json(JSON.generate(sys_hsh))
51
+
52
+ @client.store_cimi(:system, system)
53
+ system
54
+ end
55
+
56
+ def destroy_system(credentials, id)
57
+ check_credentials(credentials)
58
+ @client.destroy_cimi(:system, id)
59
+ end
60
+
61
+ def start_system(credentials, id)
62
+ check_credentials(credentials)
63
+ update_object_state(id, "System", "STARTED")
64
+ end
65
+
66
+ def stop_system(credentials, id)
67
+ check_credentials(credentials)
68
+ update_object_state(id, "System", "STOPPED")
69
+ end
70
+
71
+ def system_machines(credentials, opts={})
72
+ check_credentials(credentials)
73
+ if opts[:id].nil?
74
+ machines = @client.load_all_cimi(:system_machine).map{|mach| CIMI::Model::SystemMachine.from_json(mach)}
75
+ else
76
+ begin
77
+ machines = [CIMI::Model::SystemMachine.from_json(@client.load_cimi(:system_machine, opts[:id]))]
78
+ rescue Errno::ENOENT
79
+ return []
80
+ end
81
+ end
82
+ machines.map{|m|convert_urls(m, opts[:env])}.flatten
83
+ end
84
+
85
+ def system_volumes(credentials, opts={})
86
+ check_credentials(credentials)
87
+ if opts[:id].nil?
88
+ volumes = @client.load_all_cimi(:system_volume).map{|vol| CIMI::Model::SystemVolume.from_json(vol)}
89
+ else
90
+ begin
91
+ volumes = [CIMI::Model::SystemVolume.from_json(@client.load_cimi(:system_volume, opts[:id]))]
92
+ rescue Errno::ENOENT
93
+ return []
94
+ end
95
+ end
96
+ volumes.map{|vol|convert_urls(vol, opts[:env])}.flatten
97
+ end
98
+
99
+ def system_networks(credentials, opts={})
100
+ check_credentials(credentials)
101
+ if opts[:id].nil?
102
+ networks = @client.load_all_cimi(:system_network).map{|net| CIMI::Model::SystemNetwork.from_json(net)}
103
+ else
104
+ begin
105
+ networks = [CIMI::Model::SystemNetwork.from_json(@client.load_cimi(:system_network, opts[:id]))]
106
+ rescue Errno::ENOENT
107
+ return []
108
+ end
109
+ end
110
+ networks.map{|n|convert_urls(n, opts[:env])}.flatten
111
+ end
112
+
113
+ def system_addresses(credentials, opts={})
114
+ check_credentials(credentials)
115
+ if opts[:id].nil?
116
+ addresses = @client.load_all_cimi(:system_address).map{|a| CIMI::Model::SystemAddress.from_json(a)}
117
+ else
118
+ begin
119
+ addresses = [CIMI::Model::SystemVolume.from_json(@client.load_cimi(:system_address, opts[:id]))]
120
+ rescue Errno::ENOENT
121
+ return []
122
+ end
123
+ end
124
+ addresses.map{|a|convert_urls(a, opts[:env])}.flatten
125
+ end
126
+
127
+ def system_forwarding_groups(credentials, opts={})
128
+ check_credentials(credentials)
129
+ if opts[:id].nil?
130
+ groups = @client.load_all_cimi(:system_forwarding_group).map{|group| CIMI::Model::SystemForwardingGroup.from_json(group)}
131
+ else
132
+ begin
133
+ groups = [CIMI::Model::SystemForwardingGroup.from_json(@client.load_cimi(:system_forwarding_group, opts[:id]))]
134
+ rescue Errno::ENOENT
135
+ return []
136
+ end
137
+ end
138
+ groups.map{|g|convert_urls(g, opts[:env])}.flatten
36
139
  end
37
140
 
38
141
  def system_templates(credentials, opts={})
@@ -46,17 +149,17 @@ module Deltacloud::Drivers::Mock
46
149
  return []
47
150
  end
48
151
  end
49
- system_templates.map{|sys_templ|convert_cimi_mock_urls(:system_template, sys_templ, opts[:env])}.flatten
152
+ system_templates.map{|sys_templ| convert_urls(sys_templ, opts[:env])}.flatten
50
153
  end
51
154
 
52
155
  def networks(credentials, opts={})
53
156
  check_credentials(credentials)
54
157
  if opts[:id].nil?
55
158
  networks = @client.load_all_cimi(:network).map{|net| CIMI::Model::Network.from_json(net)}
56
- networks.map{|net|convert_cimi_mock_urls(:network, net ,opts[:env])}.flatten
159
+ networks.map{|net| convert_urls(net, opts[:env])}.flatten
57
160
  else
58
161
  network = CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:id]))
59
- convert_cimi_mock_urls(:network, network, opts[:env])
162
+ convert_urls(network, opts[:env])
60
163
  end
61
164
  end
62
165
 
@@ -106,10 +209,10 @@ module Deltacloud::Drivers::Mock
106
209
  check_credentials(credentials)
107
210
  if opts[:id].nil?
108
211
  network_configs = @client.load_all_cimi(:network_configuration).map{|net_config| CIMI::Model::NetworkConfiguration.from_json(net_config)}
109
- network_configs.map{|net_config|convert_cimi_mock_urls(:network_configuration, net_config, opts[:env])}.flatten
212
+ network_configs.map{|net_config| convert_urls(net_config, opts[:env])}.flatten
110
213
  else
111
214
  network_config = CIMI::Model::NetworkConfiguration.from_json(@client.load_cimi(:network_configuration, opts[:id]))
112
- convert_cimi_mock_urls(:network_configuration, network_config, opts[:env])
215
+ convert_urls(network_config, opts[:env])
113
216
  end
114
217
  end
115
218
 
@@ -117,10 +220,10 @@ module Deltacloud::Drivers::Mock
117
220
  check_credentials(credentials)
118
221
  if opts[:id].nil?
119
222
  network_templates = @client.load_all_cimi(:network_template).map{|net_templ| CIMI::Model::NetworkTemplate.from_json(net_templ)}
120
- network_templates.map{|net_templ|convert_cimi_mock_urls(:network_template, net_templ, opts[:env])}.flatten
223
+ network_templates.map{|net_templ| convert_urls(net_templ, opts[:env])}.flatten
121
224
  else
122
225
  network_template = CIMI::Model::NetworkTemplate.from_json(@client.load_cimi(:network_template, opts[:id]))
123
- convert_cimi_mock_urls(:network_template, network_template, opts[:env])
226
+ convert_urls(network_template, opts[:env])
124
227
  end
125
228
  end
126
229
 
@@ -128,10 +231,10 @@ module Deltacloud::Drivers::Mock
128
231
  check_credentials(credentials)
129
232
  if opts[:id].nil?
130
233
  forwarding_groups = @client.load_all_cimi(:forwarding_group).map{|fg| CIMI::Model::ForwardingGroup.from_json(fg)}
131
- forwarding_groups.map{|fg|convert_cimi_mock_urls(:forwarding_group, fg, opts[:env])}.flatten
234
+ forwarding_groups.map{|fg| convert_urls(fg, opts[:env])}.flatten
132
235
  else
133
236
  forwarding_group = CIMI::Model::ForwardingGroup.from_json(@client.load_cimi(:forwarding_group, opts[:id]))
134
- convert_cimi_mock_urls(:forwarding_group, forwarding_group, opts[:env])
237
+ convert_urls(forwarding_group, opts[:env])
135
238
  end
136
239
  end
137
240
 
@@ -139,10 +242,10 @@ module Deltacloud::Drivers::Mock
139
242
  check_credentials(credentials)
140
243
  if opts[:id].nil?
141
244
  forwarding_group_templates = @client.load_all_cimi(:forwarding_group_template).map{|fg_templ| CIMI::Model::ForwardingGroupTemplate.from_json(fg_templ)}
142
- forwarding_group_templates.map{|fg_templ|convert_cimi_mock_urls(:forwarding_group_template, fg_templ, opts[:env])}.flatten
245
+ forwarding_group_templates.map{|fg_templ| convert_urls(fg_templ, opts[:env])}.flatten
143
246
  else
144
247
  forwarding_group_template = CIMI::Model::ForwardingGroupTemplate.from_json(@client.load_cimi(:forwarding_group_template, opts[:id]))
145
- convert_cimi_mock_urls(:forwarding_group_template, forwarding_group_template, opts[:env])
248
+ convert_urls(forwarding_group_template, opts[:env])
146
249
  end
147
250
  end
148
251
 
@@ -150,10 +253,10 @@ module Deltacloud::Drivers::Mock
150
253
  check_credentials(credentials)
151
254
  if opts[:id].nil?
152
255
  ports = @client.load_all_cimi(:network_port).map{|net_port| CIMI::Model::NetworkPort.from_json(net_port)}
153
- ports.map{|net_port|convert_cimi_mock_urls(:network_port, net_port, opts[:env])}.flatten
256
+ ports.map{|net_port| convert_urls(net_port, opts[:env])}.flatten
154
257
  else
155
258
  port = CIMI::Model::NetworkPort.from_json(@client.load_cimi(:network_port, opts[:id]))
156
- convert_cimi_mock_urls(:network_port, port, opts[:env])
259
+ convert_urls(port, opts[:env])
157
260
  end
158
261
  end
159
262
 
@@ -161,10 +264,10 @@ module Deltacloud::Drivers::Mock
161
264
  check_credentials(credentials)
162
265
  if opts[:id].nil?
163
266
  network_port_configurations = @client.load_all_cimi(:network_port_configuration).map{|network_port_config| CIMI::Model::NetworkPortConfiguration.from_json(network_port_config)}
164
- network_port_configurations.map{|network_port_config|convert_cimi_mock_urls(:network_port_configuration, network_port_config, opts[:env])}.flatten
267
+ network_port_configurations.map{|network_port_config| convert_urls(network_port_config, opts[:env])}.flatten
165
268
  else
166
269
  network_port_configuration = CIMI::Model::NetworkPortConfiguration.from_json(@client.load_cimi(:network_port_configuration, opts[:id]))
167
- convert_cimi_mock_urls(:network_port_configuration, network_port_configuration, opts[:env])
270
+ convert_urls(network_port_configuration, opts[:env])
168
271
  end
169
272
  end
170
273
 
@@ -172,10 +275,10 @@ module Deltacloud::Drivers::Mock
172
275
  check_credentials(credentials)
173
276
  if opts[:id].nil?
174
277
  network_port_templates = @client.load_all_cimi(:network_port_template).map{|net_port_templ| CIMI::Model::NetworkPortTemplate.from_json(net_port_templ)}
175
- network_port_templates.map{|net_port_templ|convert_cimi_mock_urls(:network_port_template, net_port_templ, opts[:env])}.flatten
278
+ network_port_templates.map{|net_port_templ| convert_urls(net_port_templ, opts[:env])}.flatten
176
279
  else
177
280
  network_port_template = CIMI::Model::NetworkPortTemplate.from_json(@client.load_cimi(:network_port_template, opts[:id]))
178
- convert_cimi_mock_urls(:network_port_template, network_port_template, opts[:env])
281
+ convert_urls(network_port_template, opts[:env])
179
282
  end
180
283
  end
181
284
 
@@ -183,54 +286,63 @@ module Deltacloud::Drivers::Mock
183
286
  check_credentials(credentials)
184
287
  if opts[:id].nil?
185
288
  address_templates = @client.load_all_cimi(:address_template).map{|addr_templ| CIMI::Model::AddressTemplate.from_json(addr_templ)}
186
- address_templates.map{|addr_templ|convert_cimi_mock_urls(:address_template, addr_templ, opts[:env])}.flatten
289
+ address_templates.map{|addr_templ| convert_urls(addr_templ, opts[:env])}.flatten
187
290
  else
188
291
  address_template = CIMI::Model::AddressTemplate.from_json(@client.load_cimi(:address_template, opts[:id]))
189
- convert_cimi_mock_urls(:address_template, address_template, opts[:env])
292
+ convert_urls(address_template, opts[:env])
190
293
  end
191
294
  end
192
295
 
193
296
  private
194
297
 
195
- def convert_cimi_mock_urls(model_name, cimi_object, context)
196
- cimi_object.attribute_values.each do |k,v|
197
- if ( v.is_a?(Struct) || ( v.is_a?(Array) && v.first.is_a?(Struct)))
198
- case v
199
- when Array
200
- v.each do |item|
201
- convert_struct_urls(item, k.to_s.singularize.to_sym, context)
202
- end
203
- else
204
- opts = nil
205
- if is_subcollection?(v, cimi_object.id)
206
- opts = {:parent_model_name => model_name, :parent_item_name => cimi_object.name}
207
- end
208
- convert_struct_urls(v, k, context, opts)
209
- end
298
+ # Convert all attributes that have values of the form
299
+ # http://cimi.example.org/COLL/ID
300
+ # or
301
+ # http://cimi.example.org/COLL/ID/SUBCOLL/ENT_ID
302
+ def convert_urls(val, context)
303
+ if val.nil? || val.is_a?(Fixnum)
304
+ # Nothing to do
305
+ elsif val.is_a?(Struct)
306
+ val.members.each { |m| val[m] = convert_urls(val[m], context) }
307
+ elsif val.is_a?(Hash)
308
+ val.keys.each { |m| val[m] = convert_urls(val[m], context) }
309
+ elsif val.is_a?(Array)
310
+ val.each_index { |i| val[i] = convert_urls(val[i], context) }
311
+ elsif val.is_a?(String)
312
+ val = rewrite_url(val, context)
313
+ elsif val.is_a?(CIMI::Model::Resource)
314
+ val.attribute_values.each do |k, v|
315
+ val[k] = convert_urls(val[k], context)
210
316
  end
317
+ else
318
+ # Need to add a branch for val.class
319
+ raise "Whoa ! #{val.inspect}"
211
320
  end
212
- object_url = context.send(:"#{model_name}_url", cimi_object.name)
213
- cimi_object.id=object_url
214
- cimi_object.operations.each{|op| op.href=object_url }
215
- cimi_object
321
+ val
216
322
  end
217
323
 
218
- def is_subcollection?(struct, cimi_object_id)
219
- return false if struct.href.nil?
220
- struct.href.include?(cimi_object_id)
221
- end
222
-
223
- def convert_struct_urls(struct, cimi_name, context, opts = nil)
224
- return unless (struct.respond_to?(:href) && (not struct.href.nil?) && (not cimi_name == :operation ))
225
- if opts
226
- struct.href = context.send(:"#{opts[:parent_model_name]}_url", opts[:parent_item_name]) + "/#{cimi_name}"
324
+ # Rewrite URL assuming it points at a valid resource; if that's not
325
+ # possible, return +s+
326
+ #
327
+ # URLs that should be rewritten need to be in the form
328
+ # http://cimi.example.org/COLLECTION/ID
329
+ # or
330
+ # http://cimi.example.org/COLLECTION/SYSTEM_ID/SUBCOLLECTION/ENT_ID
331
+ def rewrite_url(s, context)
332
+ begin
333
+ u = URI.parse(s)
334
+ rescue URI::InvalidURIError
335
+ return s
336
+ end
337
+ return s unless u.scheme == 'http' && u.host == 'cimi.example.org'
338
+ _, coll, id, sub_coll, sub_id = u.path.split("/")
339
+ method = sub_coll ? "#{coll.singularize}_#{sub_coll.singularize}_url"
340
+ : "#{coll.singularize}_url"
341
+ if context.respond_to?(method)
342
+ sub_coll ? context.send(method, :id => id, :ent_id => sub_id)
343
+ : context.send(method, id)
227
344
  else
228
- obj_name = struct.href.split("/").last
229
- if cimi_name.to_s.end_with?("config")
230
- struct.href = context.send(:"#{cimi_name}uration_url", obj_name)
231
- else
232
- struct.href = context.send(:"#{cimi_name}_url", obj_name)
233
- end
345
+ s
234
346
  end
235
347
  end
236
348