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
@@ -22,69 +22,4 @@ class CIMI::Model::MachineVolume < CIMI::Model::Base
22
22
  scalar :rel, :href
23
23
  end
24
24
 
25
- def self.find(instance_id, context, id=:all)
26
- if id == :all
27
- volumes = context.driver.storage_volumes(context.credentials)
28
- volumes.inject([]) do |attached, vol|
29
- id = context.machine_url(instance_id)+"/volumes/#{vol.id}"
30
- attached << self.new(
31
- :id => id,
32
- :name => vol.id,
33
- :description => "MachineVolume #{vol.id} for Machine #{instance_id}",
34
- :created => vol.created.nil? ? nil : Time.parse(vol.created).xmlschema,
35
- :initial_location => vol.device,
36
- :volume => {:href=>context.volume_url(vol.id)},
37
- :operations => [{:href=>id, :rel => "delete" }]
38
- ) if vol.instance_id == instance_id
39
- attached
40
- end
41
- else
42
- vol = context.driver.storage_volume(context.credentials, {:id=>id})
43
- id = context.machine_url(instance_id)+"/volumes/#{vol.id}"
44
- raise CIMI::Model::NotFound unless vol.instance_id == instance_id
45
- self.new(
46
- :id => id,
47
- :name => vol.id,
48
- :description => "MachineVolume #{vol.id} for Machine #{instance_id}",
49
- :created => vol.created.nil? ? nil : Time.parse(vol.created).xmlschema,
50
- :initial_location => vol.device,
51
- :volume => {:href=>context.volume_url(vol.id)},
52
- :operations => [{:href=>id, :rel => "delete" }]
53
- )
54
- end
55
- end
56
-
57
- def self.find_to_attach_from_xml(xml_in, context)
58
- xml = XmlSimple.xml_in(xml_in)
59
- vol_id = xml["volume"].first["href"].split("/").last
60
- location = xml["initialLocation"].first.strip
61
- [vol_id, location]
62
- end
63
-
64
- def self.find_to_attach_from_json(json_in, context)
65
- json = JSON.parse(json_in)
66
- vol_id = json["volume"]["href"].split("/").last
67
- location = json["initialLocation"]
68
- [vol_id, location]
69
- end
70
-
71
-
72
- def self.collection_for_instance(instance_id, context)
73
- machine_volumes = self.find(instance_id, context)
74
- volumes_url = context.url("/machines/#{instance_id}/volumes")
75
- unless CIMI::Model.const_defined?('MachineVolumeCollection')
76
- collection_class = CIMI::Model::Collection.generate(self)
77
- else
78
- collection_class = CIMI::Model::MachineVolumeCollection
79
- end
80
- collection_class.new(
81
- :id => volumes_url,
82
- :name => 'default',
83
- :count => machine_volumes.size,
84
- :description => "Volume collection for Machine #{instance_id}",
85
- :entries => machine_volumes,
86
- :operations => [{ :href => volumes_url.singularize+"_attach", :rel => "add" }]
87
- )
88
- end
89
-
90
25
  end
@@ -37,36 +37,4 @@ class CIMI::Model::Network < CIMI::Model::Base
37
37
  scalar :rel, :href
38
38
  end
39
39
 
40
- def self.find(id, context)
41
- networks=[]
42
- if id==:all
43
- networks = context.driver.networks(context.credentials, {:env=>context})
44
- else
45
- networks = context.driver.networks(context.credentials, {:id=>id, :env=>context})
46
- end
47
- if context.expand? :networkPorts
48
- networks.each do |network|
49
- network.network_ports = CIMI::Model::NetworkPort.collection_for_network(network.id, context)
50
- end
51
- end
52
- networks
53
- end
54
-
55
-
56
- def self.delete!(id, context)
57
- context.driver.delete_network(context.credentials, id)
58
- end
59
-
60
- def perform(action, context, &block)
61
- begin
62
- if context.driver.send(:"#{action.name}_network", context.credentials, self.name)
63
- block.callback :success
64
- else
65
- raise "Operation #{action.name} failed to execute on the Network #{self.name} "
66
- end
67
- rescue => e
68
- block.callback :failure, e.message
69
- end
70
- end
71
-
72
40
  end
@@ -27,19 +27,4 @@ class CIMI::Model::NetworkConfiguration < CIMI::Model::Base
27
27
  scalar :rel, :href
28
28
  end
29
29
 
30
- def self.find(id, context)
31
- network_configs = []
32
- if id==:all
33
- network_configs = context.driver.network_configurations(context.credentials, {:env=>context})
34
- else
35
- network_configs = context.driver.network_configurations(context.credentials, {:env=>context, :id=>id})
36
- end
37
- network_configs
38
- end
39
-
40
- def self.create_from_xml(request_body, context)
41
- end
42
-
43
- def self.create_from_json(request_body, context)
44
- end
45
30
  end
@@ -17,27 +17,4 @@ class CIMI::Model::NetworkCreate < CIMI::Model::Base
17
17
 
18
18
  ref :network_template, :required => true
19
19
 
20
- def create(context)
21
- validate!
22
- if network_template.href?
23
- template = network_template.find(context)
24
- network_config = template.network_config.find(context)
25
- forwarding_group = template.forwarding_group.find(context)
26
- else
27
- network_config = CIMI::Model::NetworkConfiguration.find(context.href_id(network_template.network_config.href, :network_configurations), context)
28
- forwarding_group = CIMI::Model::ForwardingGroup.find(context.href_id(network_template.forwarding_group.href, :forwarding_groups), context)
29
- end
30
- params = {
31
- :network_config => network_config,
32
- :forwarding_group => forwarding_group,
33
- :name => name,
34
- :description => description,
35
- :env => context # FIXME: We should not pass the context to the driver (!)
36
- }
37
- network = context.driver.create_network(context.credentials, params)
38
- network.property = property if property
39
- network.save
40
- network
41
- end
42
-
43
20
  end
@@ -33,77 +33,4 @@ class CIMI::Model::NetworkPort < CIMI::Model::Base
33
33
  scalar :rel, :href
34
34
  end
35
35
 
36
- def self.find(id, context)
37
- if id==:all
38
- context.driver.network_ports(context.credentials, {:env=>context})
39
- else
40
- context.driver.network_ports(context.credentials, {:id=>id, :env=>context})
41
- end
42
- end
43
-
44
- def self.create(request_body, context, type)
45
- input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false, "NormaliseSpace"=>2}) : JSON.parse(request_body)
46
- if input["networkPortTemplate"]["href"] #template by reference
47
- network_port_config, network = get_by_reference(input, context)
48
- else
49
- if input["networkPortTemplate"]["networkPortConfig"]["href"] # configuration by reference
50
- network_port_config = CIMI::Model::NetworkPortConfiguration.find(context.href_id(input["networkPortTemplate"]["networkPortConfig"]["href"],:network_port_configurations), context)
51
- else #configuration by value
52
- network_port_config = get_by_value(request_body, type)
53
- end
54
- network = CIMI::Model::Network.find(context.href_id(input["networkPortTemplate"]["network"]["href"], :networks), context)
55
- end
56
- params = {:network_port_config => network_port_config, :network => network, :name=>input["name"], :description=>input["description"], :env=>context}
57
- raise CIMI::Model::BadRequest.new("Bad request - missing required parameters. Client sent: #{request_body} which produced #{params.inspect}") if params.has_value?(nil)
58
- context.driver.create_network_port(context.credentials, params)
59
- end
60
-
61
- def self.delete!(id, context)
62
- context.driver.delete_network_port(context.credentials, id)
63
- end
64
-
65
- def perform(action, context, &block)
66
- begin
67
- if context.driver.send(:"#{action.name}_network_port", context.credentials, self.name)
68
- block.callback :success
69
- else
70
- raise "Operation #{action.name} failed to execute on the NetworkPort #{self.name} "
71
- end
72
- rescue => e
73
- block.callback :failure, e.message
74
- end
75
- end
76
-
77
- def self.collection_for_network(network_id, context)
78
- net_url = context.network_url(network_id)
79
- network_ports = CIMI::Model::NetworkPort.all(context)
80
- ports_collection = network_ports.inject([]){|res, current| res << current if current.network.href == net_url ; res}
81
- CIMI::Model::NetworkPortCollection.new(
82
- :id => net_url+"/network_ports",
83
- :name => 'default',
84
- :created => Time.now,
85
- :description => "#{context.driver.name.capitalize} NetworkPortCollection",
86
- :count => ports_collection.size,
87
- :network_ports => ports_collection
88
- )
89
- end
90
-
91
- private
92
-
93
- def self.get_by_reference(input, context)
94
- network_port_template = CIMI::Model::NetworkPortTemplate.find(context.href_id(input["networkPortTemplate"]["href"], :network_port_templates), context)
95
- network_port_config = CIMI::Model::NetworkPortConfiguration.find(context.href_id(network_port_template.network_port_config.href, :network_port_configurations), context)
96
- network = CIMI::Model::Network.find(context.href_id(network_port_template.network.href, :networks), context)
97
- return network_port_config, network
98
- end
99
-
100
- def self.get_by_value(request_body, type)
101
- if type == :xml
102
- xml_arrays = XmlSimple.xml_in(request_body, {"NormaliseSpace"=>2})
103
- network_port_config = CIMI::Model::NetworkPortConfiguration.from_xml(XmlSimple.xml_out(xml_arrays["networkPortTemplate"][0]["networkPortConfig"][0]))
104
- else
105
- json = JSON.parse(request_body)
106
- network_port_config = CIMI::Model::NetworkPortConfiguration.from_json(JSON.generate(json["networkPortTemplate"]["networkPortConfig"]))
107
- end
108
- end
109
36
  end
@@ -25,12 +25,4 @@ class CIMI::Model::NetworkPortConfiguration < CIMI::Model::Base
25
25
  scalar :rel, :href
26
26
  end
27
27
 
28
- def self.find(id, context)
29
- if id==:all
30
- context.driver.network_port_configurations(context.credentials, {:env=>context})
31
- else
32
- context.driver.network_port_configurations(context.credentials, {:env=>context, :id=>id})
33
- end
34
- end
35
-
36
28
  end
@@ -25,12 +25,4 @@ class CIMI::Model::NetworkPortTemplate < CIMI::Model::Base
25
25
  scalar :rel, :href
26
26
  end
27
27
 
28
- def self.find(id, context)
29
- if id==:all
30
- context.driver.network_port_templates(context.credentials, {:env=>context})
31
- else
32
- context.driver.network_port_templates(context.credentials, {:env=>context, :id=>id})
33
- end
34
- end
35
-
36
28
  end
@@ -17,21 +17,11 @@ class CIMI::Model::NetworkTemplate < CIMI::Model::Base
17
17
 
18
18
  acts_as_root_entity
19
19
 
20
- ref :network_config, :required => true
21
- ref :forwarding_group, :required => true
20
+ ref :network_config, :class => CIMI::Model::NetworkConfiguration
21
+ ref :forwarding_group, :class => CIMI::Model::ForwardingGroup
22
22
 
23
23
  array :operations do
24
24
  scalar :rel, :href
25
25
  end
26
26
 
27
- def self.find(id, context)
28
- network_templates = []
29
- if id==:all
30
- network_templates = context.driver.network_templates(context.credentials, {:env=>context})
31
- else
32
- network_templates = context.driver.network_templates(context.credentials, {:env=>context, :id=>id})
33
- end
34
- network_templates
35
- end
36
-
37
27
  end
@@ -89,12 +89,6 @@ module CIMI
89
89
  end
90
90
  end
91
91
 
92
- # Return Array of links to current CIMI object
93
- #
94
- def all_uri(context)
95
- self.all(context).map { |e| { :href => e.id } }
96
- end
97
-
98
92
  # Construct a new object from the XML representation +xml+
99
93
  def from_xml(text)
100
94
  xml = XmlSimple.xml_in(text, :force_content => true)
@@ -16,6 +16,7 @@
16
16
 
17
17
  class CIMI::Model::ResourceMetadata < CIMI::Model::Base
18
18
 
19
+ # FIXME: Is this property really needed? (Base model include 'name'
19
20
  text :name
20
21
 
21
22
  text :type_uri
@@ -50,99 +51,4 @@ class CIMI::Model::ResourceMetadata < CIMI::Model::Base
50
51
  array :operations do
51
52
  scalar :rel, :href
52
53
  end
53
-
54
- def self.find(id, context)
55
- if id == :all
56
- resource_metadata = []
57
- CIMI::Model.root_entities.each do |resource_class|
58
- meta = resource_metadata_for(resource_class, context)
59
- resource_metadata << meta unless none_defined(meta)
60
- end
61
- return resource_metadata
62
- else
63
- resource_class = CIMI::Model.const_get("#{id.camelize}")
64
- resource_metadata_for(resource_class, context)
65
- end
66
- end
67
-
68
- def self.resource_metadata_for(resource_class, context)
69
- attributes = rm_attributes_for(resource_class, context)
70
- capabilities = rm_capabilities_for(resource_class, context)
71
- actions = rm_actions_for(resource_class, context)
72
- cimi_resource = resource_class.name.split("::").last
73
- self.new({ :id => context.resource_metadata_url(cimi_resource.underscore),
74
- :name => cimi_resource,
75
- :type_uri => resource_class.resource_uri,
76
- :attributes => attributes,
77
- :capabilities => capabilities,
78
- :actions => actions
79
- })
80
- end
81
-
82
- def self.resource_attributes
83
- @resource_attributes ||= {}
84
- end
85
-
86
- def self.add_resource_attribute!(klass, name, opts={})
87
- resource_attributes[klass.name] ||= {}
88
- resource_attributes[klass.name][name] = opts
89
- end
90
-
91
- private
92
-
93
- def self.rm_attributes_for(resource_class, context)
94
- return [] if resource_attributes[resource_class.name].nil?
95
- resource_attributes[resource_class.name].map do |attr_name, attr_def|
96
- if attr_def.has_key? :constraints
97
- constraints = attr_def[:constraints].call(context)
98
- else
99
- constraints = []
100
- end
101
- {
102
- :name => attr_name.to_s,
103
- # TODO: We need to make this URI return description of this 'non-CIMI'
104
- # attribute
105
- :namespace => "http://deltacloud.org/cimi/#{resource_class.name.split('::').last}/#{attr_name}",
106
- :type => translate_attr_type(attr_def[:type]),
107
- :required => attr_def[:required] ? 'true' : 'false',
108
- :constraints => constraints.map { |v| { :value => v }}
109
- }
110
- end
111
- end
112
-
113
- def self.rm_capabilities_for(resource_class,context)
114
- cimi_object = resource_class.name.split("::").last.underscore.pluralize.to_sym
115
- capabilities = (context.driver.class.features[cimi_object] || []).inject([]) do |res, cur|
116
- feat = CIMI::FakeCollection.feature(cur)
117
- values = (context.driver.class.constraints[cimi_object][feat.name][:values] || []).inject([]) do |vals, val|
118
- vals << val
119
- vals
120
- end
121
- res << {:name => feat.name.to_s.camelize,
122
- :uri => CMWG_NAMESPACE+"/capability/#{cimi_object.to_s.camelize.singularize}/#{feat.name.to_s.camelize}",
123
- :description => feat.description,
124
- :value => values.join(",") }
125
- res
126
- end
127
- #cimi_resource.underscore.pluralize.to_sym
128
- end
129
-
130
- def self.rm_actions_for(resource_class, context)
131
- []
132
- end
133
-
134
- def self.translate_attr_type(type)
135
- case type
136
- when :href then 'URI'
137
- when :text then 'string'
138
- when :boolean then 'boolean'
139
- else 'text'
140
- end
141
- end
142
-
143
- def self.none_defined(metadata)
144
- return true if metadata.capabilities.empty? && metadata.capabilities.empty? && metadata.attributes.empty?
145
- return false
146
- end
147
-
148
54
  end
@@ -124,12 +124,12 @@ class CIMI::Model::Schema
124
124
  end
125
125
 
126
126
  def to_xml(model, xml)
127
- conv = convert_to_xml(model[name])
127
+ conv = convert_to_xml(extract(model))
128
128
  xml[xml_name] = [conv] unless conv.empty?
129
129
  end
130
130
 
131
131
  def to_json(model, json)
132
- conv = convert_to_json(model[name])
132
+ conv = convert_to_json(extract(model))
133
133
  json[json_name] = conv unless conv.empty?
134
134
  end
135
135
 
@@ -179,6 +179,14 @@ class CIMI::Model::Schema
179
179
  @struct_class ||= ::Struct.new(nil, *@schema.attribute_names)
180
180
  end
181
181
  end
182
+ def extract(model)
183
+ if model.respond_to?("[]")
184
+ model[name] || {}
185
+ else
186
+ {}
187
+ end
188
+ end
189
+
182
190
  end
183
191
 
184
192
  class Ref < CIMI::Model::Schema::Struct
@@ -191,20 +199,6 @@ class CIMI::Model::Schema
191
199
  else
192
200
  @klass = Class.new(opts[:class]) do |m|
193
201
  scalar :href
194
-
195
- def ref_id(ctx)
196
- # FIXME: We should use ctx's routes to split
197
- # out the :id
198
- href.split('/').last
199
- end
200
-
201
- def find(ctx)
202
- klass.find(ref_id(ctx), ctx)
203
- end
204
-
205
- def klass
206
- self.class.superclass
207
- end
208
202
  end
209
203
  CIMI::Model::const_set(refname, @klass)
210
204
  end
@@ -282,13 +276,21 @@ class CIMI::Model::Schema
282
276
  end
283
277
 
284
278
  def to_xml(model, xml)
285
- ary = (model[name] || {}).map { |k, v| { "key" => k, "content" => v } }
286
- xml[xml_name] = ary unless ary.empty?
279
+ mapped = extract(model).map { |k, v| { "key" => k, "content" => v } }
280
+ xml[xml_name] = mapped unless mapped.empty?
287
281
  end
288
282
 
289
283
  def to_json(model, json)
290
- if model[name] && ! model[name].empty?
291
- json[json_name] = model[name]
284
+ h = extract(model)
285
+ json[json_name] = h unless h.empty?
286
+ end
287
+
288
+ private
289
+ def extract(model)
290
+ if model.respond_to?("[]")
291
+ model[name] || {}
292
+ else
293
+ {}
292
294
  end
293
295
  end
294
296
  end
@@ -302,7 +304,10 @@ class CIMI::Model::Schema
302
304
  raise "Specify the class of collection entries using :class"
303
305
  end
304
306
  params[:embedded] = true
305
- @collection_class = CIMI::Model::Collection.generate(opts[:class], params)
307
+ unless opts[:class].collection_class
308
+ opts[:class].collection_class = CIMI::Model::Collection.generate(opts[:class], params)
309
+ end
310
+ @collection_class = opts[:class].collection_class
306
311
  end
307
312
 
308
313
  def from_xml(xml, model)
@@ -422,15 +427,6 @@ class CIMI::Model::Schema
422
427
  # +add_attributes!+ method
423
428
  module DSL
424
429
 
425
- def resource_attr(name, opts={})
426
- CIMI::Model::ResourceMetadata.add_resource_attribute!(self, name, opts)
427
- if opts[:type]
428
- send(opts[:type], name)
429
- else
430
- text name
431
- end
432
- end
433
-
434
430
  def href(*args)
435
431
  opts = args.extract_opts!
436
432
  args.each { |arg| struct(arg, opts) { scalar :href, :required => opts[:required] } }
@@ -461,12 +457,12 @@ class CIMI::Model::Schema
461
457
  add_attributes!([name, opts], Ref)
462
458
  end
463
459
 
464
- def hash(name)
460
+ def hash_map(name)
465
461
  add_attributes!([name, {}], Hash)
466
462
  end
467
463
 
468
464
  def collection(name, opts={})
469
- opts[:scope] = self.class
465
+ opts[:scope] = self
470
466
  add_attributes!([name, opts], Collection)
471
467
  end
472
468
  end