deltacloud-core 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/Rakefile +40 -28
  2. data/bin/deltacloud-db-upgrade +24 -0
  3. data/bin/deltacloudd +20 -9
  4. data/config.ru +12 -53
  5. data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
  6. data/deltacloud-core.gemspec +11 -5
  7. data/lib/cimi/collections.rb +4 -31
  8. data/lib/cimi/collections/address_templates.rb +2 -5
  9. data/lib/cimi/collections/addresses.rb +2 -5
  10. data/lib/cimi/collections/base.rb +18 -6
  11. data/lib/cimi/collections/credentials.rb +2 -5
  12. data/lib/cimi/collections/machine_images.rb +2 -1
  13. data/lib/cimi/collections/machine_templates.rb +2 -5
  14. data/lib/cimi/collections/machines.rb +6 -9
  15. data/lib/cimi/collections/network_ports.rb +3 -3
  16. data/lib/cimi/collections/networks.rb +5 -8
  17. data/lib/cimi/collections/system_templates.rb +72 -0
  18. data/lib/cimi/collections/systems.rb +194 -0
  19. data/lib/cimi/collections/volume_configurations.rb +1 -1
  20. data/lib/cimi/collections/volume_images.rb +2 -1
  21. data/lib/cimi/collections/volume_templates.rb +3 -2
  22. data/lib/cimi/collections/volumes.rb +2 -2
  23. data/lib/cimi/dependencies.rb +0 -2
  24. data/lib/cimi/helpers/cimi_helper.rb +12 -57
  25. data/lib/cimi/helpers/database_helper.rb +0 -4
  26. data/lib/cimi/models.rb +25 -14
  27. data/lib/cimi/models/address.rb +4 -31
  28. data/lib/cimi/models/address_create.rb +51 -0
  29. data/lib/cimi/models/address_template.rb +8 -52
  30. data/lib/cimi/models/address_template_create.rb +44 -0
  31. data/lib/cimi/models/base.rb +44 -6
  32. data/lib/cimi/models/cloud_entry_point.rb +1 -1
  33. data/lib/cimi/models/credential.rb +1 -1
  34. data/lib/cimi/models/credential_create.rb +46 -0
  35. data/lib/cimi/models/credential_template.rb +24 -0
  36. data/lib/cimi/models/machine.rb +1 -71
  37. data/lib/cimi/models/machine_configuration.rb +3 -3
  38. data/lib/cimi/models/machine_create.rb +49 -0
  39. data/lib/cimi/models/machine_image.rb +2 -25
  40. data/lib/cimi/models/machine_image_create.rb +41 -0
  41. data/lib/cimi/models/machine_template.rb +14 -34
  42. data/lib/cimi/models/machine_template_create.rb +33 -0
  43. data/lib/cimi/models/network.rb +0 -38
  44. data/lib/cimi/models/network_create.rb +43 -0
  45. data/lib/cimi/models/network_port.rb +17 -17
  46. data/lib/cimi/models/network_template.rb +2 -3
  47. data/lib/cimi/models/resource.rb +22 -3
  48. data/lib/cimi/models/schema.rb +94 -8
  49. data/lib/cimi/models/system.rb +67 -0
  50. data/lib/cimi/models/system_template.rb +63 -0
  51. data/lib/cimi/models/volume.rb +2 -42
  52. data/lib/cimi/models/volume_configuration.rb +4 -4
  53. data/lib/cimi/models/volume_create.rb +58 -0
  54. data/lib/cimi/models/volume_image.rb +8 -17
  55. data/lib/cimi/models/volume_image_create.rb +47 -0
  56. data/lib/cimi/models/volume_template.rb +6 -19
  57. data/lib/cimi/models/volume_template_create.rb +33 -0
  58. data/lib/db.rb +14 -22
  59. data/lib/db/volume_template.rb +1 -1
  60. data/lib/deltacloud/api.rb +6 -5
  61. data/lib/deltacloud/collections.rb +4 -27
  62. data/lib/deltacloud/collections/base.rb +4 -0
  63. data/lib/deltacloud/collections/images.rb +1 -1
  64. data/lib/deltacloud/collections/instances.rb +2 -2
  65. data/lib/deltacloud/core_ext/array.rb +1 -0
  66. data/lib/deltacloud/core_ext/integer.rb +13 -9
  67. data/lib/deltacloud/core_ext/string.rb +45 -28
  68. data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
  69. data/lib/deltacloud/drivers/base_driver.rb +45 -16
  70. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
  71. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
  72. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
  73. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
  74. data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
  75. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
  76. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
  77. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
  78. data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
  79. data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
  80. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
  81. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
  82. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
  83. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
  84. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
  85. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
  86. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
  87. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
  88. data/lib/deltacloud/helpers/collection_helper.rb +106 -0
  89. data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
  90. data/lib/deltacloud/models/address.rb +19 -17
  91. data/lib/deltacloud/models/base_model.rb +29 -26
  92. data/lib/deltacloud/models/blob.rb +22 -20
  93. data/lib/deltacloud/models/bucket.rb +21 -16
  94. data/lib/deltacloud/models/firewall.rb +18 -16
  95. data/lib/deltacloud/models/firewall_rule.rb +22 -20
  96. data/lib/deltacloud/models/image.rb +29 -28
  97. data/lib/deltacloud/models/instance.rb +92 -94
  98. data/lib/deltacloud/models/instance_address.rb +42 -40
  99. data/lib/deltacloud/models/instance_profile.rb +28 -26
  100. data/lib/deltacloud/models/key.rb +47 -45
  101. data/lib/deltacloud/models/load_balancer.rb +32 -31
  102. data/lib/deltacloud/models/metric.rb +76 -29
  103. data/lib/deltacloud/models/provider.rb +15 -13
  104. data/lib/deltacloud/models/realm.rb +15 -21
  105. data/lib/deltacloud/models/storage_snapshot.rb +23 -19
  106. data/lib/deltacloud/models/storage_volume.rb +35 -34
  107. data/lib/deltacloud/version.rb +1 -1
  108. data/lib/deltacloud_rack.rb +22 -0
  109. data/lib/initialize.rb +28 -0
  110. data/lib/initializers/database_initialize.rb +76 -0
  111. data/lib/initializers/frontend_initialize.rb +42 -0
  112. data/lib/initializers/mock_initialize.rb +33 -0
  113. data/lib/sinatra/rack_logger.rb +35 -24
  114. data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
  115. data/tests/cimi/collections/machine_images_test.rb +2 -2
  116. data/tests/cimi/collections/machine_templates_test.rb +75 -0
  117. data/tests/cimi/collections/machines_test.rb +2 -2
  118. data/tests/cimi/collections/system_templates_test.rb +41 -0
  119. data/tests/cimi/collections/systems_test.rb +50 -0
  120. data/tests/cimi/db/database_helper_test.rb +17 -25
  121. data/tests/cimi/db/db_helper.rb +1 -12
  122. data/tests/cimi/db/entity_test.rb +7 -8
  123. data/tests/cimi/model/machine_create_spec.rb +44 -0
  124. data/tests/cimi/model/machine_template_spec.rb +29 -0
  125. data/tests/cimi/model/resource_spec.rb +40 -0
  126. data/tests/cimi/model/schema_spec.rb +37 -0
  127. data/tests/cimi/spec_helper.rb +3 -0
  128. data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
  129. data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
  130. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
  131. data/tests/deltacloud/collections/images_collection_test.rb +2 -2
  132. data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
  133. data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
  134. data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
  135. data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
  136. data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
  137. data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
  138. data/tests/deltacloud/collections_test.rb +5 -5
  139. data/tests/deltacloud/common.rb +2 -13
  140. data/tests/deltacloud/launcher_test.rb +3 -3
  141. data/tests/deltacloud/rack_test.rb +2 -2
  142. data/tests/deltacloud/server_test.rb +1 -1
  143. data/tests/drivers/base/base_driver_test.rb +5 -5
  144. data/tests/drivers/base/common.rb +2 -12
  145. data/tests/drivers/ec2/buckets_test.rb +1 -1
  146. data/tests/drivers/ec2/images_test.rb +2 -2
  147. data/tests/drivers/ec2/instance_test.rb +6 -6
  148. data/tests/drivers/ec2/keys_test.rb +3 -3
  149. data/tests/drivers/ec2/realms_test.rb +2 -2
  150. data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
  151. data/tests/drivers/fgcp/common.rb +32 -0
  152. data/tests/drivers/fgcp/firewall_test.rb +70 -0
  153. data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
  154. data/tests/drivers/fgcp/images_test.rb +46 -0
  155. data/tests/drivers/fgcp/provider_test.rb +27 -0
  156. data/tests/drivers/fgcp/realms_test.rb +53 -0
  157. data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
  158. data/tests/drivers/gogrid/images_test.rb +2 -2
  159. data/tests/drivers/gogrid/instances_test.rb +2 -2
  160. data/tests/drivers/gogrid/realms_test.rb +2 -2
  161. data/tests/drivers/mock/images_test.rb +4 -4
  162. data/tests/drivers/mock/instances_test.rb +9 -9
  163. data/tests/drivers/mock/keys_test.rb +3 -3
  164. data/tests/drivers/mock/realms_test.rb +2 -2
  165. data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
  166. data/tests/drivers/mock/storage_volumes_test.rb +4 -4
  167. data/tests/drivers/models/instance_test.rb +2 -2
  168. data/tests/drivers/openstack/images_test.rb +2 -2
  169. data/tests/drivers/openstack/instances_test.rb +2 -3
  170. data/tests/drivers/openstack/keys_test.rb +1 -1
  171. data/tests/drivers/openstack/realms_test.rb +2 -11
  172. data/tests/drivers/rhevm/common.rb +33 -12
  173. data/tests/drivers/rhevm/images_test.rb +20 -12
  174. data/tests/drivers/rhevm/instance_test.rb +62 -46
  175. data/tests/drivers/rhevm/provider_test.rb +12 -6
  176. data/tests/drivers/rhevm/realms_test.rb +15 -9
  177. data/tests/ec2/query_parser_test.rb +1 -1
  178. data/tests/test_helper.rb +68 -12
  179. data/views/addresses/show.html.haml +1 -1
  180. data/views/buckets/show.html.haml +1 -1
  181. data/views/errors/{500.html.haml → common.html.haml} +0 -0
  182. data/views/errors/common.xml.haml +17 -0
  183. data/views/firewalls/index.xml.haml +2 -2
  184. data/views/firewalls/new.html.haml +2 -2
  185. data/views/images/show.html.haml +1 -1
  186. data/views/instances/run_command.html.haml +1 -1
  187. data/views/instances/show.html.haml +3 -3
  188. data/views/keys/index.html.haml +1 -0
  189. data/views/keys/show.html.haml +8 -4
  190. data/views/keys/show.xml.haml +3 -2
  191. data/views/load_balancers/new.html.haml +1 -1
  192. data/views/load_balancers/show.html.haml +2 -2
  193. data/views/metrics/show.html.haml +1 -1
  194. data/views/realms/index.html.haml +0 -2
  195. data/views/realms/show.html.haml +0 -4
  196. data/views/realms/show.xml.haml +0 -3
  197. data/views/storage_snapshots/index.html.haml +1 -1
  198. data/views/storage_snapshots/new.html.haml +1 -1
  199. data/views/storage_volumes/new.html.haml +2 -2
  200. data/views/storage_volumes/show.html.haml +3 -3
  201. metadata +90 -41
  202. data/views/errors/400.html.haml +0 -41
  203. data/views/errors/400.xml.haml +0 -3
  204. data/views/errors/401.html.haml +0 -26
  205. data/views/errors/401.xml.haml +0 -3
  206. data/views/errors/403.html.haml +0 -42
  207. data/views/errors/403.xml.haml +0 -9
  208. data/views/errors/404.html.haml +0 -28
  209. data/views/errors/404.xml.haml +0 -3
  210. data/views/errors/405.html.haml +0 -29
  211. data/views/errors/405.xml.haml +0 -5
  212. data/views/errors/409.html.haml +0 -47
  213. data/views/errors/409.xml.haml +0 -11
  214. data/views/errors/500.xml.haml +0 -13
  215. data/views/errors/501.html.haml +0 -44
  216. data/views/errors/501.xml.haml +0 -1
  217. data/views/errors/502.html.haml +0 -44
  218. data/views/errors/502.xml.haml +0 -1
  219. data/views/errors/504.html.haml +0 -43
  220. data/views/errors/504.xml.haml +0 -1
@@ -46,11 +46,8 @@ module CIMI::Collections
46
46
  operation :create, :with_capability => :create_key do
47
47
  description "Show specific machine admin"
48
48
  control do
49
- if grab_content_type(request.content_type, request.body) == :json
50
- new_admin = Credential.create_from_json(request.body.read, self)
51
- else
52
- new_admin = Credential.create_from_xml(request.body.read, self)
53
- end
49
+ c = CIMI::Model::CredentialCreate.parse(request.body, request.content_type)
50
+ new_admin = c.create(self)
54
51
  headers_for_create new_admin
55
52
  respond_to do |format|
56
53
  format.json { new_admin.to_json }
@@ -46,7 +46,8 @@ module CIMI::Collections
46
46
  operation :create, :with_capability => :create_image do
47
47
  description "Create a new machine image."
48
48
  control do
49
- machine_image = CIMI::Model::MachineImage.create(request.body, self)
49
+ mi = CIMI::Model::MachineImageCreate.parse(request.body, request.content_type)
50
+ machine_image = mi.create(self)
50
51
  headers_for_create machine_image
51
52
  respond_to do |format|
52
53
  format.xml { machine_image.to_xml }
@@ -45,11 +45,8 @@ module CIMI::Collections
45
45
  operation :create do
46
46
  description "Create new machine template"
47
47
  control do
48
- if grab_content_type(request.content_type, request.body) == :json
49
- new_machine_template = CIMI::Model::MachineTemplate.create_from_json(request.body.read, self)
50
- else
51
- new_machine_template = CIMI::Model::MachineTemplate.create_from_xml(request.body.read, self)
52
- end
48
+ mt = CIMI::Model::MachineTemplateCreate.parse(request.body, request.content_type)
49
+ new_machine_template = mt.create(self)
53
50
  headers_for_create new_machine_template
54
51
  respond_to do |format|
55
52
  format.json { new_machine_template.to_json }
@@ -46,11 +46,8 @@ module CIMI::Collections
46
46
  operation :create, :with_capability => :create_instance do
47
47
  description "Create a new Machine entity."
48
48
  control do
49
- if grab_content_type(request.content_type, request.body) == :json
50
- new_machine = Machine.create_from_json(request.body.read, self)
51
- else
52
- new_machine = Machine.create_from_xml(request.body.read, self)
53
- end
49
+ mc = MachineCreate.parse(request.body, request.content_type)
50
+ new_machine = mc.create(self)
54
51
  headers_for_create new_machine
55
52
  respond_to do |format|
56
53
  format.json { new_machine.to_json }
@@ -72,7 +69,7 @@ module CIMI::Collections
72
69
  param :id, :string, :required
73
70
  control do
74
71
  machine = Machine.find(params[:id], self)
75
- if grab_content_type(request.content_type, request.body) == :json
72
+ if current_content_type == :json
76
73
  action = Action.from_json(request.body.read)
77
74
  else
78
75
  action = Action.from_xml(request.body.read)
@@ -89,7 +86,7 @@ module CIMI::Collections
89
86
  param :id, :string, :required
90
87
  control do
91
88
  machine = Machine.find(params[:id], self)
92
- if grab_content_type(request.content_type, request.body) == :json
89
+ if current_content_type == :json
93
90
  action = Action.from_json(request.body.read.gsub("restart", "reboot"))
94
91
  else
95
92
  action = Action.from_xml(request.body.read.gsub("restart", "reboot"))
@@ -106,7 +103,7 @@ module CIMI::Collections
106
103
  param :id, :string, :required
107
104
  control do
108
105
  machine = Machine.find(params[:id], self)
109
- if grab_content_type(request.content_type, request.body) == :json
106
+ if current_content_type == :json
110
107
  action = Action.from_json(request.body.read)
111
108
  else
112
109
  action = Action.from_xml(request.body.read)
@@ -174,7 +171,7 @@ module CIMI::Collections
174
171
  description "Attach CIMI Volume(s) to a machine."
175
172
  param :id, :string, :required
176
173
  control do
177
- if grab_content_type(request.content_type, request.body) == :json
174
+ if current_content_type == :json
178
175
  volume_to_attach, location = MachineVolume.find_to_attach_from_json(request.body.read, self)
179
176
  else
180
177
  volume_to_attach, location = MachineVolume.find_to_attach_from_xml(request.body.read, self)
@@ -47,7 +47,7 @@ module CIMI::Collections
47
47
  operation :create, :with_capability => :create_network_port do
48
48
  description "Create a new NetworkPort"
49
49
  control do
50
- if grab_content_type(request.content_type, request.body) == :json
50
+ if current_content_type == :json
51
51
  network_port = CIMI::Model::NetworkPort.create(request.body.read, self, :json)
52
52
  else
53
53
  network_port = CIMI::Model::NetworkPort.create(request.body.read, self, :xml)
@@ -73,7 +73,7 @@ module CIMI::Collections
73
73
  control do
74
74
  network_port = NetworkPort.find(params[:id], self)
75
75
  report_error(404) unless network_port
76
- if grab_content_type(request.content_type, request.body) == :json
76
+ if current_content_type == :json
77
77
  action = Action.from_json(request.body.read)
78
78
  else
79
79
  action = Action.from_xml(request.body.read)
@@ -91,7 +91,7 @@ module CIMI::Collections
91
91
  control do
92
92
  network_port = NetworkPort.find(params[:id], self)
93
93
  report_error(404) unless network_port
94
- if grab_content_type(request.content_type, request.body) == :json
94
+ if current_content_type == :json
95
95
  action = Action.from_json(request.body.read)
96
96
  else
97
97
  action = Action.from_xml(request.body.read)
@@ -46,11 +46,8 @@ module CIMI::Collections
46
46
  operation :create, :with_capability => :create_network do
47
47
  description "Create a new Network"
48
48
  control do
49
- if grab_content_type(request.content_type, request.body) == :json
50
- network = Network.create(request.body.read, self, :json)
51
- else
52
- network = Network.create(request.body.read, self, :xml)
53
- end
49
+ n = CIMI::Model::NetworkCreate.parse(request.body, request.content_type)
50
+ network = n.create(self)
54
51
  respond_to do |format|
55
52
  format.xml { network.to_xml}
56
53
  format.json { network.to_json }
@@ -72,7 +69,7 @@ module CIMI::Collections
72
69
  control do
73
70
  network = Network.find(params[:id], self)
74
71
  report_error(404) unless network
75
- if grab_content_type(request.content_type, request.body) == :json
72
+ if current_content_type == :json
76
73
  action = Action.from_json(request.body.read)
77
74
  else
78
75
  action = Action.from_xml(request.body.read)
@@ -90,7 +87,7 @@ module CIMI::Collections
90
87
  control do
91
88
  network = Network.find(params[:id], self)
92
89
  report_error(404) unless network
93
- if grab_content_type(request.content_type, request.body) == :json
90
+ if current_content_type == :json
94
91
  action = Action.from_json(request.body.read)
95
92
  else
96
93
  action = Action.from_xml(request.body.read)
@@ -108,7 +105,7 @@ module CIMI::Collections
108
105
  control do
109
106
  network = Network.find(params[:id], self)
110
107
  report_error(404) unless network
111
- if grab_content_type(request.content_type, request.body) == :json
108
+ if current_content_type == :json
112
109
  action = Action.from_json(request.body.read)
113
110
  else
114
111
  action = Action.from_xml(request.body.read)
@@ -0,0 +1,72 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ module CIMI::Collections
17
+ class SystemTemplates < Base
18
+
19
+ set :capability, lambda { |m| driver.respond_to? m }
20
+
21
+ collection :system_templates do
22
+
23
+ operation :index, :with_capability => :system_templates do
24
+ description "List all system templates"
25
+ control do
26
+ system_templates = CIMI::Model::SystemTemplate.list(self).select_by(params['$select'])
27
+ respond_to do |format|
28
+ format.xml { system_templates.to_xml }
29
+ format.json { system_templates.to_json }
30
+ end
31
+ end
32
+ end
33
+
34
+ operation :show, :with_capability => :system_templates do
35
+ description "Show specific system template"
36
+ control do
37
+ system_template = CIMI::Model::SystemTemplate.find(params[:id], self)
38
+ respond_to do |format|
39
+ format.xml { system_template.to_xml }
40
+ format.json { system_template.to_json }
41
+ end
42
+ end
43
+ end
44
+
45
+ operation :create, :with_capability => :create_system_template do
46
+ description "Create new system template"
47
+ control do
48
+ if grab_content_type(request.content_type, request.body) == :json
49
+ new_system_template = CIMI::Model::SystemTemplate.create_from_json(request.body.read, self)
50
+ else
51
+ new_system_template = CIMI::Model::SystemTemplate.create_from_xml(request.body.read, self)
52
+ end
53
+ headers_for_create new_system_template
54
+ respond_to do |format|
55
+ format.json { new_system_template.to_json }
56
+ format.xml { new_system_template.to_xml }
57
+ end
58
+ end
59
+ end
60
+
61
+ operation :destroy, :with_capability => :destroy_system_template do
62
+ description "Delete a specified system template"
63
+ control do
64
+ CIMI::Model::SystemTemplate.delete!(params[:id], self)
65
+ no_content_with_status(200)
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,194 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ module CIMI::Collections
17
+ class Systems < Base
18
+
19
+ set :capability, lambda { |m| driver.respond_to? m }
20
+
21
+ collection :systems do
22
+ description 'List all systems'
23
+
24
+ operation :index, :with_capability => :systems do
25
+ description "List all systems"
26
+ control do
27
+ systems = System.list(self).select_by(params['$select']).filter_by(params['$filter'])
28
+ respond_to do |format|
29
+ format.xml { systems.to_xml }
30
+ format.json { systems.to_json }
31
+ end
32
+ end
33
+ end
34
+
35
+ operation :show, :with_capability => :systems do
36
+ description "Show specific system."
37
+ control do
38
+ system = System.find(params[:id], self)
39
+ respond_to do |format|
40
+ format.xml { system.to_xml }
41
+ format.json { system.to_json }
42
+ end
43
+ end
44
+ end
45
+
46
+ operation :create, :with_capability => :create_system do
47
+ description "Create a new System entity."
48
+ control do
49
+ if grab_content_type(request.content_type, request.body) == :json
50
+ new_system = System.create_from_json(request.body.read, self)
51
+ else
52
+ new_system = System.create_from_xml(request.body.read, self)
53
+ end
54
+ headers_for_create new_system
55
+ respond_to do |format|
56
+ format.json { new_system.to_json }
57
+ format.xml { new_system.to_xml }
58
+ end
59
+ end
60
+ end
61
+
62
+ operation :destroy, :with_capability => :destroy_system do
63
+ description "Delete a specified system."
64
+ control do
65
+ System.delete!(params[:id], self)
66
+ no_content_with_status(200)
67
+ end
68
+ end
69
+
70
+ action :stop, :with_capability => :stop_system do
71
+ description "Stop specific system."
72
+ param :id, :string, :required
73
+ control do
74
+ system = System.find(params[:id], self)
75
+ action = Action.parse(request.body,
76
+ request.content_type)
77
+ system.perform(action, self) do |operation|
78
+ no_content_with_status(202) if operation.success?
79
+ # Handle errors using operation.failure?
80
+ end
81
+ end
82
+ end
83
+
84
+ action :restart, :with_capability => :reboot_system do
85
+ description "Restart specific system."
86
+ param :id, :string, :required
87
+ control do
88
+ system = System.find(params[:id], self)
89
+ if grab_content_type(request.content_type, request.body) == :json
90
+ action = Action.from_json(request.body.read.gsub("restart", "reboot"))
91
+ else
92
+ action = Action.from_xml(request.body.read.gsub("restart", "reboot"))
93
+ end
94
+ system.perform(action, self) do |operation|
95
+ no_content_with_status(202) if operation.success?
96
+ # Handle errors using operation.failure?
97
+ end
98
+ end
99
+ end
100
+
101
+ action :start, :with_capability => :start_system do
102
+ description "Start specific system."
103
+ param :id, :string, :required
104
+ control do
105
+ system = System.find(params[:id], self)
106
+ if grab_content_type(request.content_type, request.body) == :json
107
+ action = Action.from_json(request.body.read)
108
+ else
109
+ action = Action.from_xml(request.body.read)
110
+ end
111
+ system.perform(action, self) do |operation|
112
+ no_content_with_status(202) if operation.success?
113
+ # Handle errors using operation.failure?
114
+ end
115
+ end
116
+ end
117
+
118
+ action :pause, :with_capability => :pause_system do
119
+ description "Pause specific system."
120
+ param :id, :string, :required
121
+ control do
122
+ system = System.find(params[:id], self)
123
+ if grab_content_type(request.content_type, request.body) == :json
124
+ action = Action.from_json(request.body.read)
125
+ else
126
+ action = Action.from_xml(request.body.read)
127
+ end
128
+ system.perform(action, self) do |operation|
129
+ no_content_with_status(202) if operation.success?
130
+ # Handle errors using operation.failure?
131
+ end
132
+ end
133
+ end
134
+
135
+ action :suspend, :with_capability => :suspend_system do
136
+ description "Suspend specific system."
137
+ param :id, :string, :required
138
+ control do
139
+ system = System.find(params[:id], self)
140
+ if grab_content_type(request.content_type, request.body) == :json
141
+ action = Action.from_json(request.body.read)
142
+ else
143
+ action = Action.from_xml(request.body.read)
144
+ end
145
+ system.perform(action, self) do |operation|
146
+ no_content_with_status(202) if operation.success?
147
+ # Handle errors using operation.failure?
148
+ end
149
+ end
150
+ end
151
+
152
+ #use rabbit subcollections for volumes index/show:
153
+ collection :volumes, :with_id => :vol_id do
154
+
155
+ operation :index, :with_capability => :storage_volumes do
156
+ description "Retrieve the System's SystemVolumeCollection"
157
+ control do
158
+ volumes = CIMI::Model::SystemVolume.collection_for_system(params[:id], self)
159
+ respond_to do |format|
160
+ format.json {volumes.to_json}
161
+ format.xml {volumes.to_xml}
162
+ end
163
+ end
164
+ end
165
+
166
+ operation :show, :with_capability => :storage_volumes do
167
+ description "Retrieve a System's specific SystemVolume"
168
+ control do
169
+ volume = CIMI::Model::SystemVolume.find(params[:id], self, params[:vol_id])
170
+ respond_to do |format|
171
+ format.json {volume.to_json}
172
+ format.xml {volume.to_xml}
173
+ end
174
+ end
175
+ end
176
+
177
+ operation :destroy, :with_capability => :detach_storage_volume do
178
+ description "Remove/detach a volume from the System's SystemVolumeCollection"
179
+ control do
180
+ system_volume = CIMI::Model::SystemVolume.find(params[:id], self, params[:vol_id])
181
+ location = system_volume.initial_location
182
+ system_volumes = System.detach_volume(params[:vol_id], location, self)
183
+ respond_to do |format|
184
+ format.json{ system_volumes.to_json}
185
+ format.xml{ system_volumes.to_xml}
186
+ end
187
+ end
188
+ end
189
+
190
+ end
191
+ end
192
+
193
+ end
194
+ end
@@ -45,7 +45,7 @@ module CIMI::Collections
45
45
  operation :create, :with_capability => :create_storage_volume do
46
46
  description "Create new VolumeConfiguration"
47
47
  control do
48
- if grab_content_type(request.content_type, request.body) == :json
48
+ if current_content_type == :json
49
49
  new_config = CIMI::Model::VolumeConfiguration.create_from_json(request.body.read, self)
50
50
  else
51
51
  new_config = CIMI::Model::VolumeConfiguration.create_from_xml(request.body.read, self)
@@ -46,7 +46,8 @@ module CIMI::Collections
46
46
  operation :create, :with_capability => :create_storage_snapshot do
47
47
  description "Create a new volume image."
48
48
  control do
49
- volume_image = CIMI::Model::VolumeImage.create(request.body, self)
49
+ img = CIMI::Model::VolumeImageCreate.parse(request.body, request.content_type)
50
+ volume_image = img.create(self)
50
51
  headers_for_create volume_image
51
52
  respond_to do |format|
52
53
  format.xml { volume_image.to_xml }
@@ -45,8 +45,9 @@ module CIMI::Collections
45
45
  operation :create, :with_capability => :create_storage_volume do
46
46
  description "Create new VolumeTemplate"
47
47
  control do
48
- content_type = grab_content_type(request.content_type, request.body)
49
- new_template = CIMI::Model::VolumeTemplate.create(request.body.read, self, content_type)
48
+ puts request.body
49
+ vol = CIMI::Model::VolumeTemplateCreate.parse(request.body, request.content_type)
50
+ new_template = vol.create(self)
50
51
  headers_for_create new_template
51
52
  respond_to do |format|
52
53
  format.json { new_template.to_json }