deltacloud-core 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/Rakefile +2 -1
  2. data/bin/deltacloudd +11 -5
  3. data/config.ru +3 -3
  4. data/deltacloud-core.gemspec +24 -18
  5. data/lib/cimi/collections/address_templates.rb +3 -3
  6. data/lib/cimi/collections/addresses.rb +6 -5
  7. data/lib/cimi/collections/entity_metadata.rb +0 -2
  8. data/lib/cimi/collections/machine_admins.rb +5 -5
  9. data/lib/cimi/collections/machine_configurations.rb +2 -2
  10. data/lib/cimi/collections/machine_images.rb +3 -3
  11. data/lib/cimi/collections/machines.rb +32 -10
  12. data/lib/cimi/collections/network_configurations.rb +4 -3
  13. data/lib/cimi/collections/network_templates.rb +4 -3
  14. data/lib/cimi/collections/networks.rb +8 -8
  15. data/lib/cimi/collections/routing_group_templates.rb +4 -3
  16. data/lib/cimi/collections/routing_groups.rb +4 -3
  17. data/lib/cimi/collections/volume_configurations.rb +3 -3
  18. data/lib/cimi/collections/volume_images.rb +3 -3
  19. data/lib/cimi/collections/volumes.rb +4 -3
  20. data/lib/cimi/collections/vsp_configurations.rb +4 -3
  21. data/lib/cimi/collections/vsp_templates.rb +4 -3
  22. data/lib/cimi/collections/vsps.rb +8 -7
  23. data/lib/cimi/helpers.rb +1 -1
  24. data/lib/cimi/helpers/cimi_helper.rb +11 -1
  25. data/lib/cimi/models.rb +4 -0
  26. data/lib/cimi/models/base.rb +11 -1
  27. data/lib/cimi/models/cloud_entry_point.rb +7 -14
  28. data/lib/cimi/models/disk.rb +40 -0
  29. data/lib/cimi/models/disk_collection.rb +38 -0
  30. data/lib/cimi/models/machine.rb +9 -43
  31. data/lib/cimi/models/machine_collection.rb +7 -4
  32. data/lib/cimi/models/machine_configuration.rb +8 -15
  33. data/lib/cimi/models/machine_configuration_collection.rb +6 -4
  34. data/lib/cimi/models/machine_image_collection.rb +6 -4
  35. data/lib/cimi/models/machine_template_collection.rb +6 -4
  36. data/lib/cimi/models/machine_volume.rb +42 -0
  37. data/lib/cimi/models/machine_volume_collection.rb +34 -0
  38. data/lib/cimi/models/network.rb +5 -9
  39. data/lib/cimi/models/network_collection.rb +6 -5
  40. data/lib/cimi/models/schema.rb +20 -0
  41. data/lib/cimi/models/volume_collection.rb +6 -4
  42. data/lib/cimi/models/volume_configuration_collection.rb +6 -4
  43. data/lib/cimi/models/volume_image_collection.rb +6 -4
  44. data/lib/cimi/models/volume_template_collection.rb +6 -4
  45. data/lib/deltacloud/api.rb +3 -3
  46. data/lib/deltacloud/collections/addresses.rb +1 -1
  47. data/lib/deltacloud/collections/firewalls.rb +4 -2
  48. data/lib/deltacloud/collections/keys.rb +1 -1
  49. data/lib/deltacloud/collections/load_balancers.rb +1 -1
  50. data/lib/deltacloud/collections/storage_volumes.rb +4 -4
  51. data/lib/deltacloud/drivers/base_driver.rb +12 -20
  52. data/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb +294 -0
  53. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +38 -6
  54. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +4 -0
  55. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +40 -4
  56. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +8 -7
  57. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +422 -416
  58. data/lib/deltacloud/drivers/google/google_driver.rb +2 -1
  59. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +30 -16
  60. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +1 -0
  61. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +3 -9
  62. data/lib/deltacloud/helpers/deltacloud_helper.rb +0 -2
  63. data/lib/deltacloud/models/firewall_rule.rb +2 -0
  64. data/lib/deltacloud/models/hardware_profile.rb +61 -59
  65. data/{tests/deprecated/core_ext/string.rb → lib/deltacloud/version.rb} +3 -15
  66. data/lib/deltacloud_rack.rb +1 -0
  67. data/lib/ec2/server.rb +5 -3
  68. data/lib/sinatra/rack_accept.rb +53 -53
  69. data/lib/sinatra/rack_etag.rb +1 -1
  70. data/tests/cimi/collections/cloud_entry_point_test.rb +11 -2
  71. data/tests/deltacloud/common.rb +1 -1
  72. data/tests/deltacloud/rack_test.rb +3 -3
  73. data/tests/drivers/base/base_driver_test.rb +6 -2
  74. data/tests/drivers/base/common.rb +1 -0
  75. data/tests/drivers/base/library_test.rb +6 -2
  76. data/tests/drivers/ec2/common.rb +34 -15
  77. data/tests/drivers/ec2/images_test.rb +2 -3
  78. data/tests/drivers/ec2/instance_test.rb +12 -2
  79. data/tests/drivers/ec2/keys_test.rb +2 -2
  80. data/tests/drivers/ec2/realms_test.rb +7 -3
  81. data/tests/drivers/ec2/storage_snapshots_test.rb +2 -3
  82. data/tests/drivers/gogrid/common.rb +24 -0
  83. data/tests/drivers/gogrid/hardware_profiles_test.rb +51 -0
  84. data/tests/drivers/gogrid/images_test.rb +57 -0
  85. data/tests/drivers/gogrid/instances_test.rb +92 -0
  86. data/tests/drivers/gogrid/realms_test.rb +45 -0
  87. data/tests/drivers/google/buckets_test.rb +105 -0
  88. data/tests/drivers/google/common.rb +20 -0
  89. data/tests/drivers/mock/common.rb +1 -0
  90. data/tests/drivers/mock/images_test.rb +3 -2
  91. data/tests/drivers/mock/instances_test.rb +3 -2
  92. data/tests/drivers/mock/keys_test.rb +3 -2
  93. data/tests/drivers/mock/realms_test.rb +3 -2
  94. data/tests/drivers/mock/storage_snapshots_test.rb +3 -2
  95. data/tests/drivers/mock/storage_volumes_test.rb +3 -2
  96. data/tests/drivers/models/address_test.rb +3 -3
  97. data/tests/drivers/models/base_test.rb +4 -2
  98. data/tests/drivers/models/blob_test.rb +3 -3
  99. data/tests/drivers/models/common.rb +3 -0
  100. data/tests/drivers/models/hardware_profile_test.rb +5 -4
  101. data/tests/drivers/models/instance_address_test.rb +3 -3
  102. data/tests/drivers/models/instance_profile_test.rb +3 -3
  103. data/tests/drivers/models/instance_test.rb +3 -3
  104. data/tests/drivers/models/keys_test.rb +3 -3
  105. data/tests/drivers/models/metrics_test.rb +3 -3
  106. data/tests/drivers/openstack/common.rb +26 -0
  107. data/tests/drivers/openstack/hardware_profiles_test.rb +46 -0
  108. data/tests/drivers/openstack/images_test.rb +50 -0
  109. data/tests/drivers/openstack/instances_test.rb +66 -0
  110. data/tests/drivers/openstack/keys_test.rb +61 -0
  111. data/tests/drivers/openstack/realms_test.rb +46 -0
  112. data/tests/drivers/rhevm/common.rb +2 -0
  113. data/tests/drivers/rhevm/images_test.rb +3 -4
  114. data/tests/drivers/rhevm/instance_test.rb +2 -2
  115. data/tests/drivers/rhevm/provider_test.rb +2 -2
  116. data/tests/drivers/rhevm/realms_test.rb +2 -3
  117. data/tests/ec2/common.rb +5 -4
  118. data/tests/ec2/server_test.rb +3 -2
  119. data/tests/helpers/rack/common.rb +3 -0
  120. data/tests/helpers/rack/rack_accept_test.rb +65 -0
  121. data/tests/helpers/rack/rack_date_test.rb +27 -0
  122. data/tests/helpers/rack/rack_driver_select_test.rb +53 -0
  123. data/tests/helpers/rack/rack_etag_test.rb +29 -0
  124. data/tests/helpers/rack/rack_matrix_params_test.rb +72 -0
  125. data/tests/test_helper.rb +44 -36
  126. data/views/hardware_profiles/index.html.haml +1 -1
  127. data/views/hardware_profiles/show.html.haml +2 -2
  128. data/views/hardware_profiles/show.xml.haml +2 -1
  129. data/views/images/show.html.haml +6 -5
  130. metadata +74 -117
  131. data/tests/deprecated/api/common.rb +0 -1
  132. data/tests/deprecated/api/driver_test.rb +0 -79
  133. data/tests/deprecated/api/library_test.rb +0 -6
  134. data/tests/deprecated/cimi/features/step_definitions/common_steps.rb +0 -59
  135. data/tests/deprecated/cimi/features/step_definitions/machine_images_steps.rb +0 -0
  136. data/tests/deprecated/cimi/features/step_definitions/machines_steps.rb +0 -100
  137. data/tests/deprecated/cimi/features/step_definitions/volumes_steps.rb +0 -115
  138. data/tests/deprecated/cimi/features/support/env.rb +0 -75
  139. data/tests/deprecated/common.rb +0 -279
  140. data/tests/deprecated/drivers/ec2/api_test.rb +0 -19
  141. data/tests/deprecated/drivers/ec2/common.rb +0 -23
  142. data/tests/deprecated/drivers/ec2/drivers_test.rb +0 -120
  143. data/tests/deprecated/drivers/ec2/hardware_profiles_test.rb +0 -224
  144. data/tests/deprecated/drivers/ec2/images_test.rb +0 -230
  145. data/tests/deprecated/drivers/ec2/instances_test.rb +0 -356
  146. data/tests/deprecated/drivers/ec2/keys_test.rb +0 -181
  147. data/tests/deprecated/drivers/ec2/realms_test.rb +0 -146
  148. data/tests/deprecated/drivers/fgcp/api_test.rb +0 -47
  149. data/tests/deprecated/drivers/fgcp/hardware_profiles_test.rb +0 -54
  150. data/tests/deprecated/drivers/fgcp/realms_test.rb +0 -42
  151. data/tests/deprecated/drivers/fgcp/setup.rb +0 -13
  152. data/tests/deprecated/drivers/google/api_test.rb +0 -19
  153. data/tests/deprecated/drivers/google/buckets_test.rb +0 -100
  154. data/tests/deprecated/drivers/google/common.rb +0 -54
  155. data/tests/deprecated/drivers/mock/api_test.rb +0 -10
  156. data/tests/deprecated/drivers/mock/buckets_test.rb +0 -195
  157. data/tests/deprecated/drivers/mock/common.rb +0 -7
  158. data/tests/deprecated/drivers/mock/drivers_test.rb +0 -123
  159. data/tests/deprecated/drivers/mock/hardware_profiles_test.rb +0 -224
  160. data/tests/deprecated/drivers/mock/images_test.rb +0 -197
  161. data/tests/deprecated/drivers/mock/instances_test.rb +0 -343
  162. data/tests/deprecated/drivers/mock/keys_test.rb +0 -161
  163. data/tests/deprecated/drivers/mock/realms_test.rb +0 -132
  164. data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +0 -114
  165. data/tests/deprecated/drivers/mock/storage_volumes_test.rb +0 -122
  166. data/tests/deprecated/drivers/openstack/api_test.rb +0 -46
  167. data/tests/deprecated/drivers/openstack/common.rb +0 -21
  168. data/tests/deprecated/drivers/openstack/hardware_profiles_test.rb +0 -64
  169. data/tests/deprecated/drivers/openstack/images_test.rb +0 -46
  170. data/tests/deprecated/drivers/openstack/instances_test.rb +0 -208
  171. data/tests/deprecated/drivers/openstack/realms_test.rb +0 -40
  172. data/tests/deprecated/drivers/rackspace/api_test.rb +0 -46
  173. data/tests/deprecated/drivers/rackspace/buckets_test.rb +0 -150
  174. data/tests/deprecated/drivers/rackspace/common.rb +0 -16
  175. data/tests/deprecated/drivers/rackspace/hardware_profiles_test.rb +0 -58
  176. data/tests/deprecated/drivers/rackspace/images_test.rb +0 -45
  177. data/tests/deprecated/drivers/rackspace/instances_test.rb +0 -166
  178. data/tests/deprecated/drivers/rackspace/realms_test.rb +0 -41
  179. data/tests/deprecated/drivers/rhevm/api_test.rb +0 -45
  180. data/tests/deprecated/drivers/rhevm/common.rb +0 -21
  181. data/tests/deprecated/drivers/rhevm/hardware_profiles_test.rb +0 -58
  182. data/tests/deprecated/drivers/rhevm/images_test.rb +0 -48
  183. data/tests/deprecated/drivers/rhevm/instances_test.rb +0 -182
  184. data/tests/deprecated/drivers/rhevm/realms_test.rb +0 -40
  185. data/tests/deprecated/minitest_common.rb +0 -58
  186. data/tests/deprecated/minitest_common_api_test.rb +0 -115
  187. data/tests/deprecated/rabbit_test.rb +0 -52
@@ -0,0 +1,38 @@
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
+ class CIMI::Model::DiskCollection < CIMI::Model::Base
16
+ text :count
17
+
18
+ #add disks array:
19
+ self.schema.add_collection_member_array(CIMI::Model::Disk)
20
+
21
+ array :operations do
22
+ scalar :rel, :href
23
+ end
24
+
25
+ def self.default(instance_id, context)
26
+ instance = context.driver.instance(context.credentials, :id=>instance_id)
27
+ machine_conf = CIMI::Model::MachineConfiguration.find(instance.instance_profile.name, context)
28
+ disks = CIMI::Model::Disk.find(instance, machine_conf, context, :all)
29
+ storage_override = instance.instance_profile.overrides.find { |p, v| p == :storage }
30
+ self.new(
31
+ :id => context.machine_url(instance_id)+"/disks",
32
+ :description => "DiskCollection for Machine #{instance_id}",
33
+ :created => instance.launch_time,
34
+ :count => disks.size,
35
+ :disks => disks
36
+ )
37
+ end
38
+ end
@@ -18,33 +18,15 @@ class CIMI::Model::Machine < CIMI::Model::Base
18
18
  text :state
19
19
  text :cpu
20
20
 
21
- struct :memory do
22
- scalar :quantity
23
- scalar :units
24
- end
21
+ text :memory
25
22
 
26
23
  href :event_log
27
24
 
28
- array :disks do
29
- struct :capacity do
30
- scalar :quantity
31
- scalar :units
32
- end
33
- scalar :format
34
- scalar :attachment_point
35
- end
25
+ href :disks
36
26
 
37
- array :volumes do
38
- scalar :href
39
- scalar :protocol
40
- scalar :attachment_point
41
- end
27
+ href :volumes
42
28
 
43
- array :network_interfaces do
44
- href :vsp
45
- text :hostname, :mac_address, :state, :protocol, :allocation
46
- text :address, :default_gateway, :dns, :max_transmission_unit
47
- end
29
+ href :network_interfaces
48
30
 
49
31
  array :meters do
50
32
  scalar :href
@@ -133,7 +115,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
133
115
 
134
116
  private
135
117
  def self.from_instance(instance, context)
136
- cpu = memory = disks = (instance.instance_profile.id == "opaque")? "n/a" : nil
118
+ cpu = memory = (instance.instance_profile.id == "opaque")? "n/a" : nil
137
119
  self.new(
138
120
  :name => instance.id,
139
121
  :description => instance.name,
@@ -142,10 +124,10 @@ class CIMI::Model::Machine < CIMI::Model::Base
142
124
  :state => convert_instance_state(instance.state),
143
125
  :cpu => cpu || convert_instance_cpu(instance.instance_profile, context),
144
126
  :memory => memory || convert_instance_memory(instance.instance_profile, context),
145
- :disks => disks || convert_instance_storage(instance.instance_profile, context),
146
- :network_interfaces => convert_instance_addresses(instance),
127
+ :disks => {:href => context.machine_url(instance.id)+"/disks"},
128
+ :network_interfaces => {:href => context.machine_url(instance.id+"/network_interfaces")},
147
129
  :operations => convert_instance_actions(instance, context),
148
- :volumes=>convert_storage_volumes(instance, context),
130
+ :volumes=>{:href=>context.machine_url(instance.id)+"/volumes"},
149
131
  :property => convert_instance_properties(instance, context)
150
132
  )
151
133
  end
@@ -178,23 +160,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
178
160
  def self.convert_instance_memory(profile, context)
179
161
  machine_conf = CIMI::Model::MachineConfiguration.find(profile.name, context)
180
162
  memory_override = profile.overrides.find { |p, v| p == :memory }
181
- {
182
- :quantity => memory_override.nil? ? machine_conf.memory[:quantity] : memory_override[1],
183
- :units => machine_conf.memory[:units]
184
- }
185
- end
186
-
187
- def self.convert_instance_storage(profile, context)
188
- machine_conf = CIMI::Model::MachineConfiguration.find(profile.name, context)
189
- return nil unless machine_conf.disks
190
- storage_override = profile.overrides.find { |p, v| p == :storage }
191
- [
192
- { :capacity => {
193
- :quantity => storage_override.nil? ? machine_conf.disks.first[:capacity][:quantity] : storage_override[1],
194
- :units => machine_conf.disks.first[:capacity][:units]
195
- }
196
- }
197
- ]
163
+ memory_override.nil? ? machine_conf.memory : context.to_kibibyte(memory_override[1].to_i,"MB")
198
164
  end
199
165
 
200
166
  def self.convert_instance_addresses(instance)
@@ -17,17 +17,20 @@ class CIMI::Model::MachineCollection < CIMI::Model::Base
17
17
 
18
18
  act_as_root_entity :machine
19
19
 
20
- array :machines do
21
- scalar :href
22
- end
20
+ text :count
21
+
22
+ #add machines array:
23
+ self.schema.add_collection_member_array(CIMI::Model::Machine)
23
24
 
24
25
  def self.default(context)
26
+ machines = CIMI::Model::Machine.all(context)
25
27
  self.new(
26
28
  :id => context.machines_url,
27
29
  :name => 'default',
28
30
  :created => Time.now,
29
31
  :description => "#{context.driver.name.capitalize} MachineCollection",
30
- :machines => CIMI::Model::Machine.all_uri(context)
32
+ :count => machines.size,
33
+ :machines => machines
31
34
  )
32
35
  end
33
36
 
@@ -15,20 +15,13 @@
15
15
 
16
16
  class CIMI::Model::MachineConfiguration < CIMI::Model::Base
17
17
 
18
- struct :memory do
19
- scalar :quantity
20
- scalar :units
21
- end
22
-
18
+ text :memory
23
19
  text :cpu
24
20
 
25
21
  array :disks do
26
- struct :capacity do
27
- scalar :quantity
28
- scalar :units
29
- end
30
- scalar :format
31
- scalar :attachment_point
22
+ text :capacity
23
+ text :format
24
+ text :attachment_point
32
25
  end
33
26
 
34
27
  array :operations do
@@ -51,17 +44,17 @@ class CIMI::Model::MachineConfiguration < CIMI::Model::Base
51
44
  def self.from_hardware_profile(profile, context)
52
45
  # We accept just profiles with all properties set
53
46
  return unless profile.memory or profile.cpu or profile.storage
54
- memory = profile.memory.value || profile.memory.default
47
+ memory = profile.memory ? context.to_kibibyte((profile.memory.value || profile.memory.default), profile.memory.unit) : nil
55
48
  cpu = (profile.cpu ? (profile.cpu.value || profile.cpu.default) : nil )
56
- storage = (profile.storage ? (profile.storage.value || profile.storage.default) : nil )
49
+ storage = profile.storage ? context.to_kibibyte((profile.storage.value || profile.storage.default), profile.storage.unit) : nil
57
50
  machine_hash = {
58
51
  :name => profile.name,
59
52
  :description => "Machine Configuration with #{memory} #{profile.memory.unit} "+
60
53
  "of memory and #{cpu} CPU",
61
54
  :cpu => ( cpu if cpu ) ,
62
55
  :created => Time.now.to_s, # FIXME: DC hardware_profile has no mention about created_at
63
- :memory => { :quantity => profile.memory.value || profile.memory.default, :units => profile.memory.unit },
64
- :disks => ( [ { :capacity => { :quantity => profile.storage.value || profile.storage.default, :units => profile.storage.unit } } ] if storage ),
56
+ :memory => (memory if memory),
57
+ :disks => ( [ { :capacity => storage } ] if storage ),
65
58
  :id => context.machine_configuration_url(profile.name)
66
59
  }
67
60
  self.new(machine_hash)
@@ -17,17 +17,19 @@ class CIMI::Model::MachineConfigurationCollection < CIMI::Model::Base
17
17
 
18
18
  act_as_root_entity :machine_configuration
19
19
 
20
- array :machine_configurations do
21
- scalar :href
22
- end
20
+ text :count
21
+
22
+ self.schema.add_collection_member_array(CIMI::Model::MachineConfiguration)
23
23
 
24
24
  def self.default(context)
25
+ machine_configurations = CIMI::Model::MachineConfiguration.all(context)
25
26
  self.new(
26
27
  :id => context.machine_configurations_url,
27
28
  :name => 'default',
28
29
  :created => Time.now,
29
30
  :description => "#{context.driver.name.capitalize} MachineConfigurationCollection",
30
- :machine_configurations => CIMI::Model::MachineConfiguration.all_uri(context)
31
+ :count => machine_configurations.count,
32
+ :machine_configurations => machine_configurations
31
33
  )
32
34
  end
33
35
 
@@ -17,17 +17,19 @@ class CIMI::Model::MachineImageCollection < CIMI::Model::Base
17
17
 
18
18
  act_as_root_entity :machine_image
19
19
 
20
- array :machine_images do
21
- scalar :href
22
- end
20
+ text :count
21
+
22
+ self.schema.add_collection_member_array(CIMI::Model::MachineImage)
23
23
 
24
24
  def self.default(context)
25
+ machine_images = CIMI::Model::MachineImage.all(context)
25
26
  self.new(
26
27
  :id => context.machine_images_url,
27
28
  :name => 'default',
28
29
  :created => Time.now,
29
30
  :description => "#{context.driver.name.capitalize} MachineImageCollection",
30
- :machine_images => CIMI::Model::MachineImage.all_uri(context)
31
+ :count => machine_images.count,
32
+ :machine_images => machine_images
31
33
  )
32
34
  end
33
35
 
@@ -17,17 +17,19 @@ class CIMI::Model::MachineTemplateCollection < CIMI::Model::Base
17
17
 
18
18
  act_as_root_entity :machine_template
19
19
 
20
- array :machine_templates do
21
- scalar :href
22
- end
20
+ text :count
21
+
22
+ self.schema.add_collection_member_array(CIMI::Model::MachineTemplate)
23
23
 
24
24
  def self.default(context)
25
+ machine_templates = CIMI::Model::MachineTemplate.all(context)
25
26
  self.new(
26
27
  :id => context.machine_template_url,
27
28
  :name => 'default',
28
29
  :created => Time.now,
29
30
  :description => "#{context.driver.name.capitalize} MachineTemplateCollection",
30
- :machine_templates => CIMI::Model::MachineTemplate.all_uri(context)
31
+ :count => machine_templates.size,
32
+ :machine_templates => machine_templates
31
33
  )
32
34
  end
33
35
 
@@ -0,0 +1,42 @@
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
+ class CIMI::Model::MachineVolume < CIMI::Model::Base
17
+
18
+ text :initial_location
19
+ href :volume
20
+
21
+ array :operations do
22
+ scalar :rel, :href
23
+ end
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
+ attached << self.new(
30
+ :id => context.machine_url(instance_id)+"/volumes/#{vol.id}",
31
+ :name => vol.id,
32
+ :description => "MachineVolume #{vol.id} for Machine #{instance_id}",
33
+ :created => vol.created,
34
+ :initial_location => vol.device,
35
+ :volume => {:href=>context.volume_url(vol.id)}
36
+ ) if vol.instance_id == instance_id
37
+ attached
38
+ end
39
+ else
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,34 @@
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
+ class CIMI::Model::MachineVolumeCollection < CIMI::Model::Base
16
+
17
+ text :count
18
+
19
+ self.schema.add_collection_member_array(CIMI::Model::MachineVolume)
20
+
21
+ array :operations do
22
+ scalar :rel, :href
23
+ end
24
+
25
+ def self.default(instance_id, context)
26
+ volumes = CIMI::Model::MachineVolume.find(instance_id, context)
27
+ self.new(
28
+ :id => context.machine_url(instance_id)+"/volumes",
29
+ :description => "MachineVolumeCollection for Machine #{instance_id}",
30
+ :count => volumes.size,
31
+ :machine_volumes => volumes
32
+ )
33
+ end
34
+ end
@@ -17,19 +17,15 @@ class CIMI::Model::Network < CIMI::Model::Base
17
17
 
18
18
  text :state
19
19
 
20
- text :access
20
+ text :network_type
21
21
 
22
- text :bandwidth_limit
22
+ text :mtu
23
23
 
24
- text :traffic_priority
24
+ text :class_of_service
25
25
 
26
- text :max_traffic_delay
26
+ href :network_ports
27
27
 
28
- text :max_traffic_loss
29
-
30
- text :max_traffic_jitter
31
-
32
- href :routing_group
28
+ href :forwarding_group
33
29
 
34
30
  href :event_log
35
31
 
@@ -12,22 +12,23 @@
12
12
  # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
13
  # License for the specific language governing permissions and limitations
14
14
  # under the License.
15
-
16
15
  class CIMI::Model::NetworkCollection < CIMI::Model::Base
17
16
 
18
17
  act_as_root_entity :network
18
+ text :count
19
19
 
20
- array :networks do
21
- scalar :href
22
- end
20
+ #add networks Array:
21
+ self.schema.add_collection_member_array(CIMI::Model::Network)
23
22
 
24
23
  def self.default(context)
24
+ networks = CIMI::Model::Network.all(context)
25
25
  self.new(
26
26
  :id => context.networks_url,
27
27
  :name => 'default',
28
28
  :created => Time.now,
29
29
  :description => "#{context.driver.name.capitalize} NetworkCollection",
30
- :networks => CIMI::Model::Network.all(context).map { |c| { :href => c.id } }
30
+ :count => networks.size,
31
+ :networks => networks
31
32
  )
32
33
  end
33
34
 
@@ -14,6 +14,8 @@
14
14
  # under the License.
15
15
  #
16
16
 
17
+ require_relative "../../deltacloud/core_ext"
18
+
17
19
  # The smarts of converting from XML and JSON into internal objects
18
20
  class CIMI::Model::Schema
19
21
 
@@ -79,6 +81,9 @@ class CIMI::Model::Schema
79
81
  end
80
82
 
81
83
  class Struct < Attribute
84
+
85
+ attr_accessor :schema
86
+
82
87
  def initialize(name, opts, &block)
83
88
  content = opts[:content]
84
89
  super(name, opts)
@@ -144,6 +149,9 @@ class CIMI::Model::Schema
144
149
  end
145
150
 
146
151
  class Array < Attribute
152
+
153
+ attr_accessor :struct
154
+
147
155
  # For an array :funThings, we collect all <funThing/> elements (XmlSimple
148
156
  # actually does the collecting)
149
157
  def initialize(name, opts = {}, &block)
@@ -206,6 +214,9 @@ class CIMI::Model::Schema
206
214
  #
207
215
  # The actual Schema class
208
216
  #
217
+
218
+ attr_accessor :attributes
219
+
209
220
  def initialize
210
221
  @attributes = []
211
222
  end
@@ -228,6 +239,15 @@ class CIMI::Model::Schema
228
239
  xml
229
240
  end
230
241
 
242
+ #For MachineCollection, copy over the schema of Machine to hold
243
+ #each member of the collection - avoid duplicating the schemas
244
+ def add_collection_member_array(model)
245
+ member_symbol = model.name.split("::").last.underscore.pluralize.to_sym
246
+ members = CIMI::Model::Schema::Array.new(member_symbol)
247
+ members.struct.schema.attributes = model.schema.attributes
248
+ self.attributes << members
249
+ end
250
+
231
251
  def to_json(model, json = {})
232
252
  @attributes.freeze
233
253
  @attributes.each { |attr| attr.to_json(model, json) }