deltacloud-core 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/Rakefile +2 -2
  2. data/config/drivers/aruba.yaml +3 -3
  3. data/deltacloud-core.gemspec +2 -2
  4. data/lib/cimi/collections/address_templates.rb +1 -2
  5. data/lib/cimi/collections/addresses.rb +1 -2
  6. data/lib/cimi/collections/base.rb +1 -1
  7. data/lib/cimi/collections/credentials.rb +2 -3
  8. data/lib/cimi/collections/forwarding_group_templates.rb +1 -2
  9. data/lib/cimi/collections/forwarding_groups.rb +1 -2
  10. data/lib/cimi/collections/machine_configurations.rb +1 -2
  11. data/lib/cimi/collections/machine_images.rb +1 -2
  12. data/lib/cimi/collections/machines.rb +9 -9
  13. data/lib/cimi/collections/network_configurations.rb +1 -2
  14. data/lib/cimi/collections/network_port_configurations.rb +1 -2
  15. data/lib/cimi/collections/network_port_templates.rb +1 -2
  16. data/lib/cimi/collections/network_ports.rb +1 -2
  17. data/lib/cimi/collections/network_templates.rb +1 -2
  18. data/lib/cimi/collections/networks.rb +2 -3
  19. data/lib/cimi/collections/volume_configurations.rb +1 -2
  20. data/lib/cimi/collections/volume_images.rb +1 -2
  21. data/lib/cimi/collections/volumes.rb +3 -4
  22. data/lib/cimi/helpers/cimi_helper.rb +7 -2
  23. data/lib/cimi/models.rb +6 -10
  24. data/lib/cimi/models/base.rb +48 -35
  25. data/lib/cimi/models/cloud_entry_point.rb +22 -1
  26. data/lib/cimi/models/collection.rb +42 -5
  27. data/lib/cimi/models/credential.rb +1 -1
  28. data/lib/cimi/models/disk.rb +39 -10
  29. data/lib/cimi/models/machine.rb +39 -22
  30. data/lib/cimi/models/machine_configuration.rb +4 -5
  31. data/lib/cimi/models/machine_image.rb +1 -1
  32. data/lib/cimi/models/machine_volume.rb +1 -1
  33. data/lib/cimi/models/network.rb +6 -3
  34. data/lib/cimi/models/network_port.rb +13 -2
  35. data/lib/cimi/models/schema.rb +66 -5
  36. data/lib/cimi/models/volume.rb +17 -16
  37. data/lib/cimi/models/volume_configuration.rb +7 -10
  38. data/lib/cimi/models/volume_image.rb +1 -1
  39. data/lib/deltacloud/collections/base.rb +1 -1
  40. data/lib/deltacloud/collections/firewalls.rb +2 -2
  41. data/lib/deltacloud/collections/load_balancers.rb +8 -2
  42. data/lib/deltacloud/core_ext.rb +1 -0
  43. data/lib/deltacloud/core_ext/base.rb +30 -0
  44. data/lib/deltacloud/drivers.rb +1 -1
  45. data/lib/deltacloud/drivers/base_driver.rb +1 -1
  46. data/lib/deltacloud/drivers/condor/condor_driver.rb +1 -1
  47. data/lib/deltacloud/drivers/exceptions.rb +24 -14
  48. data/lib/deltacloud/drivers/features.rb +3 -3
  49. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +163 -92
  50. data/lib/deltacloud/drivers/mock/data/images/img1.yml +1 -0
  51. data/lib/deltacloud/drivers/mock/data/images/img2.yml +1 -0
  52. data/lib/deltacloud/drivers/mock/data/images/img3.yml +1 -0
  53. data/lib/deltacloud/drivers/mock/mock_client.rb +4 -4
  54. data/lib/deltacloud/drivers/mock/mock_driver.rb +16 -16
  55. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +25 -9
  56. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +2 -1
  57. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +1 -1
  58. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +2 -0
  59. data/lib/deltacloud/helpers/deltacloud_helper.rb +29 -8
  60. data/lib/deltacloud/models/image.rb +1 -0
  61. data/lib/deltacloud/models/instance_profile.rb +4 -0
  62. data/lib/deltacloud/version.rb +1 -1
  63. data/lib/ec2/query_parser.rb +1 -1
  64. data/lib/sinatra/rack_accept.rb +5 -1
  65. data/lib/sinatra/rack_logger.rb +9 -2
  66. data/tests/cimi/collections/machine_images_test.rb +23 -6
  67. data/tests/cimi/collections/machines_test.rb +39 -0
  68. data/tests/cimi/model/collection_spec.rb +109 -0
  69. data/tests/cimi/{spec/cimi/model → model}/credential_spec.rb +1 -1
  70. data/tests/cimi/{spec/cimi/model → model}/machine_configuration_spec.rb +1 -1
  71. data/tests/cimi/{spec/cimi/model → model}/machine_image_spec.rb +1 -1
  72. data/tests/cimi/{spec/cimi/model → model}/machine_spec.rb +1 -1
  73. data/tests/cimi/{spec/cimi/model → model}/machine_template_spec.rb +1 -1
  74. data/tests/cimi/{spec/cimi/model → model}/schema_spec.rb +1 -1
  75. data/tests/cimi/{spec/cimi/model → model}/volume_configuration_spec.rb +1 -1
  76. data/tests/cimi/{spec/cimi/model → model}/volume_image_spec.rb +1 -1
  77. data/tests/cimi/{spec/cimi/model → model}/volume_spec.rb +1 -1
  78. data/tests/cimi/{spec/cimi/model → model}/volume_template_spec.rb +1 -1
  79. data/tests/cimi/{spec/spec_helper.rb → spec_helper.rb} +7 -4
  80. data/tests/drivers/base/exceptions_test.rb +8 -8
  81. data/tests/drivers/ec2/buckets_test.rb +1 -1
  82. data/tests/drivers/ec2/images_test.rb +1 -1
  83. data/tests/drivers/ec2/instance_test.rb +1 -1
  84. data/tests/drivers/ec2/keys_test.rb +2 -2
  85. data/tests/drivers/ec2/realms_test.rb +1 -1
  86. data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
  87. data/tests/drivers/gogrid/hardware_profiles_test.rb +1 -1
  88. data/tests/drivers/gogrid/images_test.rb +1 -1
  89. data/tests/drivers/gogrid/instances_test.rb +1 -1
  90. data/tests/drivers/gogrid/realms_test.rb +1 -1
  91. data/tests/drivers/mock/images_test.rb +7 -2
  92. data/tests/drivers/mock/instances_test.rb +1 -1
  93. data/tests/drivers/mock/keys_test.rb +2 -2
  94. data/tests/drivers/mock/realms_test.rb +1 -1
  95. data/tests/drivers/mock/storage_snapshots_test.rb +1 -1
  96. data/tests/drivers/mock/storage_volumes_test.rb +1 -1
  97. data/tests/drivers/openstack/hardware_profiles_test.rb +3 -3
  98. data/tests/drivers/openstack/images_test.rb +1 -1
  99. data/tests/drivers/openstack/instances_test.rb +1 -1
  100. data/tests/drivers/openstack/keys_test.rb +2 -2
  101. data/tests/drivers/openstack/realms_test.rb +1 -1
  102. data/tests/drivers/rhevm/common.rb +3 -3
  103. data/tests/drivers/rhevm/images_test.rb +13 -13
  104. data/tests/drivers/rhevm/instance_test.rb +22 -22
  105. data/tests/drivers/rhevm/provider_test.rb +3 -3
  106. data/tests/drivers/rhevm/realms_test.rb +7 -7
  107. data/tests/test_helper.rb +0 -5
  108. data/views/api/show.xml.haml +6 -3
  109. data/views/errors/401.html.haml +0 -16
  110. data/views/errors/404.html.haml +2 -3
  111. data/views/errors/500.html.haml +6 -5
  112. data/views/images/show.html.haml +5 -1
  113. data/views/images/show.xml.haml +8 -3
  114. data/views/instances/new.html.haml +1 -1
  115. data/views/instances/show.xml.haml +1 -1
  116. data/views/load_balancers/show.html.haml +1 -1
  117. metadata +761 -778
  118. data/lib/cimi/models/disk_collection.rb +0 -37
  119. data/lib/cimi/models/machine_volume_collection.rb +0 -34
  120. data/lib/cimi/models/network_port_collection.rb +0 -51
  121. data/lib/cimi/models/network_port_configuration_collection.rb +0 -35
  122. data/lib/cimi/models/network_port_template_collection.rb +0 -37
data/Rakefile CHANGED
@@ -199,8 +199,8 @@ namespace :test do
199
199
  t.loader = :testrb
200
200
  end
201
201
  t.test_files = FileList[
202
- 'tests/cimi/spec/cimi/model/*spec.rb', # CIMI frontend serialization API tests
203
- 'tests/cimi/collections/*test.rb', # CIMI frontend API tests
202
+ 'tests/cimi/model/*spec.rb', # CIMI frontend serialization API tests
203
+ 'tests/cimi/collections/*test.rb', # CIMI frontend API tests
204
204
  ]
205
205
  end
206
206
  end
@@ -2,7 +2,7 @@
2
2
  :aruba:
3
3
  :entrypoints:
4
4
  compute:
5
- dc1: https://api.dc1.computing.cloud.it/WsEndUser/v1.7/WsEndUser.svc?wsdl
6
- dc2: https://api.dc2.computing.cloud.it/WsEndUser/v1.7/WsEndUser.svc?wsdl
7
- dc3: https://api.dc3.computing.cloud.it/WsEndUser/v1.7/WsEndUser.svc?wsdl
5
+ dc1: https://api.dc1.computing.cloud.it/WsEndUser/v2.0/WsEndUser.svc?wsdl
6
+ dc2: https://api.dc2.computing.cloud.it/WsEndUser/v2.0/WsEndUser.svc?wsdl
7
+ dc3: https://api.dc3.computing.cloud.it/WsEndUser/v2.0/WsEndUser.svc?wsdl
8
8
  :name: Aruba
@@ -82,7 +82,7 @@ Gem::Specification.new do |s|
82
82
  # dependencies for various cloud providers:
83
83
 
84
84
  # RHEV-M and oVirt
85
- s.add_dependency('rbovirt', '>=0.0.12')
85
+ s.add_dependency('rbovirt', '>=0.0.13')
86
86
 
87
87
  # Amazon EC2 S3
88
88
  s.add_dependency('aws', '>=2.5.4')
@@ -104,7 +104,7 @@ Gem::Specification.new do |s|
104
104
  s.add_dependency('uuidtools', '>= 2.1.1')
105
105
 
106
106
  # Openstack Compute and Object-Storage
107
- s.add_dependency('openstack', '>= 1.0.4')
107
+ s.add_dependency('openstack', '>= 1.0.6')
108
108
 
109
109
  # Aruba Cloud
110
110
  s.add_dependency('savon', '>= 1.0.0')
@@ -22,9 +22,8 @@ module CIMI::Collections
22
22
 
23
23
  operation :index, :with_capability => :address_templates do
24
24
  description 'List all AddressTemplates in the AddressTemplateCollection'
25
- param :CIMISelect, :string, :optional
26
25
  control do
27
- address_templates = AddressTemplate.list(self).filter_by(params[:CIMISelect])
26
+ address_templates = AddressTemplate.list(self).filter_by(params['$select'])
28
27
  respond_to do |format|
29
28
  format.xml {address_templates.to_xml}
30
29
  format.json {address_templates.to_json}
@@ -24,9 +24,8 @@ module CIMI::Collections
24
24
 
25
25
  operation :index, :with_capability => :addresses do
26
26
  description 'List all Addresses in the AddressCollection'
27
- param :CIMISelect, :string, :optional
28
27
  control do
29
- addresses = Address.list(self).filter_by(params[:CIMISelect])
28
+ addresses = Address.list(self).filter_by(params['$select'])
30
29
  respond_to do |format|
31
30
  format.xml {addresses.to_xml}
32
31
  format.json {addresses.to_json}
@@ -47,7 +47,7 @@ module CIMI::Collections
47
47
  report_error
48
48
  end
49
49
 
50
- error Deltacloud::ExceptionHandler::ValidationFailure do
50
+ error Deltacloud::Exceptions::ValidationFailure do
51
51
  report_error
52
52
  end
53
53
 
@@ -23,9 +23,8 @@ module CIMI::Collections
23
23
 
24
24
  operation :index, :with_capability => :keys do
25
25
  description "List all machine admins"
26
- param :CIMISelect, :string, :optional
27
26
  control do
28
- credentials = Credential.list(self).filter_by(params[:CIMISelect])
27
+ credentials = Credential.list(self).filter_by(params['$select'])
29
28
  respond_to do |format|
30
29
  format.xml { credentials.to_xml }
31
30
  format.json { credentials.to_json }
@@ -47,7 +46,7 @@ module CIMI::Collections
47
46
  operation :create, :with_capability => :create_key do
48
47
  description "Show specific machine admin"
49
48
  control do
50
- if request.content_type.end_with?("+json")
49
+ if request.content_type.end_with?("json")
51
50
  new_admin = Credential.create_from_json(request.body.read, self)
52
51
  else
53
52
  new_admin = Credential.create_from_xml(request.body.read, self)
@@ -21,9 +21,8 @@ module CIMI::Collections
21
21
 
22
22
  operation :index, :with_capability => :forwarding_groups do
23
23
  description 'List all ForwardingGroupTemplates in the ForwardingGroupTemplateCollection'
24
- param :CIMISelect, :string, :optional
25
24
  control do
26
- forwarding_group_templates = ForwardingGroupTemplate.list(self).filter_by(params[:CIMISelect])
25
+ forwarding_group_templates = ForwardingGroupTemplate.list(self).filter_by(params['$select'])
27
26
  respond_to do |format|
28
27
  format.xml {forwarding_group_templates.to_xml}
29
28
  format.json {forwarding_group_templates.to_json}
@@ -21,9 +21,8 @@ module CIMI::Collections
21
21
 
22
22
  operation :index, :with_capability => :forwarding_groups do
23
23
  description 'List all ForwardingGroups in the ForwardingGroupsCollection'
24
- param :CIMISelect, :string, :optional
25
24
  control do
26
- forwarding_groups = ForwardingGroup.list(self).filter_by(params[:CIMISelect])
25
+ forwarding_groups = ForwardingGroup.list(self).filter_by(params['$select'])
27
26
  respond_to do |format|
28
27
  format.xml {forwarding_groups.to_xml}
29
28
  format.json {forwarding_groups.to_json}
@@ -22,10 +22,9 @@ module CIMI::Collections
22
22
  description 'List all machine configurations'
23
23
 
24
24
  operation :index, :with_capability => :hardware_profiles do
25
- param :CIMISelect, :string, :optional
26
25
  description "List all machine configurations"
27
26
  control do
28
- machine_configs = MachineConfiguration.list(self).filter_by(params[:CIMISelect])
27
+ machine_configs = MachineConfiguration.list(self).filter_by(params['$select'])
29
28
  respond_to do |format|
30
29
  format.xml { machine_configs.to_xml }
31
30
  format.json { machine_configs.to_json }
@@ -23,9 +23,8 @@ module CIMI::Collections
23
23
 
24
24
  operation :index, :with_capability => :images do
25
25
  description "List all machine configurations"
26
- param :CIMISelect, :string, :optional
27
26
  control do
28
- machine_images = MachineImage.list(self).filter_by(params[:CIMISelect])
27
+ machine_images = MachineImage.list(self).filter_by(params['$select'])
29
28
  respond_to do |format|
30
29
  format.xml { machine_images.to_xml }
31
30
  format.json { machine_images.to_json }
@@ -22,10 +22,9 @@ module CIMI::Collections
22
22
  description 'List all machine'
23
23
 
24
24
  operation :index, :with_capability => :instances do
25
- param :CIMISelect, :string, :optional
26
25
  description "List all machines"
27
26
  control do
28
- machines = Machine.list(self).filter_by(params[:CIMISelect])
27
+ machines = Machine.list(self).filter_by(params['$select'])
29
28
  respond_to do |format|
30
29
  format.xml { machines.to_xml }
31
30
  format.json { machines.to_json }
@@ -47,12 +46,13 @@ module CIMI::Collections
47
46
  operation :create, :with_capability => :create_instance do
48
47
  description "Create a new Machine entity."
49
48
  control do
50
- if request.content_type.end_with?("+json")
49
+ if request.content_type.end_with?("json")
51
50
  new_machine = Machine.create_from_json(request.body.read, self)
52
51
  else
53
52
  new_machine = Machine.create_from_xml(request.body.read, self)
54
53
  end
55
54
  status 201 # Created
55
+ headers 'Location' => new_machine.id
56
56
  respond_to do |format|
57
57
  format.json { new_machine.to_json }
58
58
  format.xml { new_machine.to_xml }
@@ -73,7 +73,7 @@ module CIMI::Collections
73
73
  param :id, :string, :required
74
74
  control do
75
75
  machine = Machine.find(params[:id], self)
76
- if request.content_type.end_with?("+json")
76
+ if request.content_type.end_with?("json")
77
77
  action = Action.from_json(request.body.read)
78
78
  else
79
79
  action = Action.from_xml(request.body.read)
@@ -90,7 +90,7 @@ module CIMI::Collections
90
90
  param :id, :string, :required
91
91
  control do
92
92
  machine = Machine.find(params[:id], self)
93
- if request.content_type.end_with?("+json")
93
+ if request.content_type.end_with?("json")
94
94
  action = Action.from_json(request.body.read)
95
95
  else
96
96
  action = Action.from_xml(request.body.read)
@@ -107,7 +107,7 @@ module CIMI::Collections
107
107
  param :id, :string, :required
108
108
  control do
109
109
  machine = Machine.find(params[:id], self)
110
- if request.content_type.end_with?("+json")
110
+ if request.content_type.end_with?("json")
111
111
  action = Action.from_json(request.body.read)
112
112
  else
113
113
  action = Action.from_xml(request.body.read)
@@ -123,7 +123,7 @@ module CIMI::Collections
123
123
  description "Retrieve the Machine's DiskCollection"
124
124
  param :id, :string, :required
125
125
  control do
126
- disks = DiskCollection.default(params[:id], self)
126
+ disks = CIMI::Model::Disk.collection_for_instance(params[:id], self)
127
127
  respond_to do |format|
128
128
  format.json {disks.to_json}
129
129
  format.xml {disks.to_xml}
@@ -150,7 +150,7 @@ module CIMI::Collections
150
150
  description "Attach CIMI Volume(s) to a machine."
151
151
  param :id, :string, :required
152
152
  control do
153
- if request.content_type.end_with?("+json")
153
+ if request.content_type.end_with?("json")
154
154
  volumes_to_attach = Volume.find_to_attach_from_json(request.body.read, self)
155
155
  else
156
156
  volumes_to_attach = Volume.find_to_attach_from_xml(request.body.read, self)
@@ -167,7 +167,7 @@ module CIMI::Collections
167
167
  description "Detach CIMI Volume(s) from a machine."
168
168
  param :id, :string, :required
169
169
  control do
170
- if request.content_type.end_with?("+json")
170
+ if request.content_type.end_with?("json")
171
171
  volumes_to_detach = Volume.find_to_attach_from_json(request.body.read, self)
172
172
  else
173
173
  volumes_to_detach = Volume.find_to_attach_from_xml(request.body.read, self)
@@ -22,9 +22,8 @@ module CIMI::Collections
22
22
 
23
23
  operation :index, :with_capability => :network_configurations do
24
24
  description 'List all NetworkConfigurations'
25
- param :CIMISelect, :string, :optional
26
25
  control do
27
- network_configurations = NetworkConfiguration.list(self).filter_by(params[:CIMISelect])
26
+ network_configurations = NetworkConfiguration.list(self).filter_by(params['$select'])
28
27
  respond_to do |format|
29
28
  format.xml { network_configurations.to_xml }
30
29
  format.json { network_configurations.to_json }
@@ -22,9 +22,8 @@ module CIMI::Collections
22
22
 
23
23
  operation :index, :with_capability => :network_port_configurations do
24
24
  description 'List all NetworkPortConfigurations in the NetworkPortConfigurationCollection'
25
- param :CIMISelect, :string, :optional
26
25
  control do
27
- net_port_configs = NetworkPortConfiguration.list(self).filter_by(params[:CIMISelect])
26
+ net_port_configs = NetworkPortConfiguration.list(self).filter_by(params['$select'])
28
27
  respond_to do |format|
29
28
  format.xml {net_port_configs.to_xml}
30
29
  format.json {net_port_configs.to_json}
@@ -24,9 +24,8 @@ module CIMI::Collections
24
24
 
25
25
  operation :index, :with_capability => :network_port_templates do
26
26
  description 'List all NetworkPortTemplates in the NetworkPortTemplateCollection'
27
- param :CIMISelect, :string, :optional
28
27
  control do
29
- network_port_templates = NetworkPortTemplate.list(self).filter_by(params[:CIMISelect])
28
+ network_port_templates = NetworkPortTemplate.list(self).filter_by(params['$select'])
30
29
  respond_to do |format|
31
30
  format.xml {network_port_templates.to_xml}
32
31
  format.json {network_port_templates.to_json}
@@ -24,9 +24,8 @@ module CIMI::Collections
24
24
 
25
25
  operation :index, :with_capability => :network_ports do
26
26
  description 'List all NetworkPorts in the NetworkPortCollection'
27
- param :CIMISelect, :string, :optional
28
27
  control do
29
- network_ports = NetworkPort.list(self).filter_by(params[:CIMISelect])
28
+ network_ports = NetworkPort.list(self).filter_by(params['$select'])
30
29
  respond_to do |format|
31
30
  format.xml {network_ports.to_xml}
32
31
  format.json {network_ports.to_json}
@@ -22,9 +22,8 @@ module CIMI::Collections
22
22
 
23
23
  operation :index, :with_capability => :network_templates do
24
24
  description 'List all Network Templates in the NetworkTemplateCollection'
25
- param :CIMISelect, :string, :optional
26
25
  control do
27
- network_templates = NetworkTemplate.list(self).filter_by(params[:CIMISelect])
26
+ network_templates = NetworkTemplate.list(self).filter_by(params['$select'])
28
27
  respond_to do |format|
29
28
  format.xml {network_templates.to_xml}
30
29
  format.json {network_templates.to_json}
@@ -23,9 +23,8 @@ module CIMI::Collections
23
23
 
24
24
  operation :index, :with_capability => :networks do
25
25
  description "List all Networks"
26
- param :CIMISelect, :string, :optional
27
26
  control do
28
- networks = Network.list(self).filter_by(params[:CIMISelect])
27
+ networks = Network.list(self).filter_by(params['$select'])
29
28
  respond_to do |format|
30
29
  format.xml { networks.to_xml }
31
30
  format.json { networks.to_json }
@@ -125,7 +124,7 @@ module CIMI::Collections
125
124
  description "Retrieve the Network's NetworkPortCollection"
126
125
  param :id, :string, :required
127
126
  control do
128
- network_ports = NetworkPortCollection.for_network(params[:id], self)
127
+ network_ports = NetworkPort.collection_for_network(params[:id], self)
129
128
  respond_to do |format|
130
129
  format.json {network_ports.to_json}
131
130
  format.xml {network_ports.to_xml}
@@ -22,9 +22,8 @@ module CIMI::Collections
22
22
 
23
23
  operation :index, :with_capability => :storage_volumes do
24
24
  description "Get list all VolumeConfigurations"
25
- param :CIMISelect, :string, :optional
26
25
  control do
27
- volume_configuration = VolumeConfiguration.list(self).filter_by(params[:CIMISelect])
26
+ volume_configuration = VolumeConfiguration.list(self).filter_by(params['$select'])
28
27
  respond_to do |format|
29
28
  format.xml { volume_configuration.to_xml }
30
29
  format.json { volume_configuration.to_json }
@@ -23,9 +23,8 @@ module CIMI::Collections
23
23
 
24
24
  operation :index, :with_capability => :storage_snapshots do
25
25
  description "List all volumes images"
26
- param :CIMISelect, :string, :optional
27
26
  control do
28
- volume_images = VolumeImage.list(self).filter_by(params[:CIMISelect])
27
+ volume_images = VolumeImage.list(self).filter_by(params['$select'])
29
28
  respond_to do |format|
30
29
  format.xml { volume_images.to_xml }
31
30
  format.json { volume_images.to_json }
@@ -22,9 +22,8 @@ module CIMI::Collections
22
22
 
23
23
  operation :index, :with_capability => :storage_volumes do
24
24
  description "List all volumes"
25
- param :CIMISelect, :string, :optional
26
25
  control do
27
- volumes = Volume.list(self).filter_by(params[:CIMISelect])
26
+ volumes = Volume.list(self).filter_by(params['$select'])
28
27
  respond_to do |format|
29
28
  format.xml { volumes.to_xml }
30
29
  format.json { volumes.to_json }
@@ -50,8 +49,8 @@ module CIMI::Collections
50
49
  operation :create do
51
50
  description "Create a new Volume."
52
51
  control do
53
- content_type = (request.content_type.end_with?("+json") ? :json : :xml)
54
- #((request.content_type.end_with?("+xml")) ? :xml : report_error(415) ) FIXME
52
+ content_type = (request.content_type.end_with?("json") ? :json : :xml)
53
+ #((request.content_type.end_with?("xml")) ? :xml : report_error(415) ) FIXME
55
54
  case content_type
56
55
  when :json
57
56
  new_volume = Volume.create_from_json(request.body.read, self)
@@ -16,6 +16,11 @@
16
16
  module CIMI
17
17
  module Helper
18
18
 
19
+ def expand?(collection)
20
+ params['$expand'] == '*' ||
21
+ (params['$expand'] || '').split(',').include?(collection.to_s)
22
+ end
23
+
19
24
  def no_content_with_status(code=200)
20
25
  body ''
21
26
  status code
@@ -29,9 +34,9 @@ module CIMI
29
34
  def to_kibibyte(value, unit)
30
35
  case unit
31
36
  when "GB"
32
- value*1024*1024
37
+ (value*1024*1024).to_i
33
38
  when "MB"
34
- value*1024
39
+ (value*1024).to_i
35
40
  else
36
41
  nil # should probably be exploding something here...
37
42
  end
@@ -24,28 +24,24 @@ require_relative './models/base'
24
24
  require_relative './models/collection'
25
25
  require_relative './models/errors'
26
26
  require_relative './models/action'
27
- require_relative './models/disk'
28
- require_relative './models/disk_collection'
29
27
  require_relative './models/machine_volume'
30
- require_relative './models/machine_volume_collection'
28
+ require_relative './models/disk'
31
29
 
32
- # Toplevel entities; order matters as it determines the order
33
- # in which the entities appear in the CEP
34
30
  require_relative './models/cloud_entry_point'
35
31
  require_relative './models/resource_metadata'
32
+ require_relative './models/volume'
33
+ require_relative './models/volume_template'
34
+ require_relative './models/volume_configuration'
35
+ require_relative './models/volume_image'
36
36
  require_relative './models/machine'
37
37
  require_relative './models/machine_template'
38
38
  require_relative './models/machine_configuration'
39
39
  require_relative './models/machine_image'
40
40
  require_relative './models/credential'
41
- require_relative './models/volume'
42
- require_relative './models/volume_template'
43
- require_relative './models/volume_configuration'
44
- require_relative './models/volume_image'
41
+ require_relative './models/network_port'
45
42
  require_relative './models/network'
46
43
  require_relative './models/network_template'
47
44
  require_relative './models/network_configuration'
48
- require_relative './models/network_port'
49
45
  require_relative './models/network_port_template'
50
46
  require_relative './models/network_port_configuration'
51
47
  require_relative './models/address'
@@ -66,6 +66,9 @@ require 'json'
66
66
  # [array(name, opts, &block)]
67
67
  # An array of structured subobjects; the block defines the schema of
68
68
  # the subobjects.
69
+ # [collection(name, opts)]
70
+ # A collection of associated objects; use the +:class+ option to
71
+ # specify the type of the collection entries
69
72
 
70
73
  module CIMI::Model
71
74
 
@@ -88,13 +91,15 @@ module CIMI::Model
88
91
 
89
92
  end
90
93
 
91
- class CIMI::Model::Base
94
+ class CIMI::Model::Resource
92
95
 
93
96
  #
94
97
  # We keep the values of the attributes in a hash
95
98
  #
96
99
  attr_reader :attribute_values
97
100
 
101
+ CMWG_NAMESPACE = "http://schemas.dmtf.org/cimi/1"
102
+
98
103
  # Keep the list of all attributes in an array +attributes+; for each
99
104
  # attribute, we also define a getter and a setter to access/change the
100
105
  # value for that attribute
@@ -143,8 +148,8 @@ class CIMI::Model::Base
143
148
  base_schema.add_attributes!(names, attr_klass, &block)
144
149
  end
145
150
  names.each do |name|
146
- define_method(name) { @attribute_values[name] }
147
- define_method(:"#{name}=") { |newval| @attribute_values[name] = newval }
151
+ define_method(name) { self[name] }
152
+ define_method(:"#{name}=") { |newval| self[name] = newval }
148
153
  end
149
154
  end
150
155
 
@@ -161,14 +166,26 @@ class CIMI::Model::Base
161
166
  end
162
167
 
163
168
  def []=(a, v)
164
- @attribute_values[a] = v
169
+ @attribute_values[a] = self.class.schema.convert(a, v)
170
+ end
171
+
172
+ # Prepare to serialize
173
+ def prepare
174
+ self.class.schema.collections.map { |coll| coll.name }.each do |n|
175
+ self[n].href = "#{self.id}/#{n}" unless self[n].href
176
+ self[n].id = "#{self.id}/#{n}" if !self[n].entries.empty?
177
+ end
165
178
  end
166
179
 
167
180
  #
168
181
  # Factory methods
169
182
  #
170
183
  def initialize(values = {})
171
- @attribute_values = values
184
+ names = self.class.schema.attribute_names
185
+ @attribute_values = names.inject({}) do |hash, name|
186
+ hash[name] = self.class.schema.convert(name, values[name])
187
+ hash
188
+ end
172
189
  end
173
190
 
174
191
  # Construct a new object from the XML representation +xml+
@@ -205,13 +222,20 @@ class CIMI::Model::Base
205
222
  self.name.split("::").last
206
223
  end
207
224
 
225
+ def self.resource_uri
226
+ CMWG_NAMESPACE + "/" + self.name.split("::").last
227
+ end
228
+
208
229
  def self.to_json(model)
209
- JSON::unparse(@schema.to_json(model))
230
+ json = @schema.to_json(model)
231
+ json[:resourceURI] = resource_uri
232
+ JSON::unparse(json)
210
233
  end
211
234
 
212
235
  def self.to_xml(model)
213
236
  xml = @schema.to_xml(model)
214
- xml["xmlns"] = "http://schemas.dmtf.org/cimi/1"
237
+ xml["xmlns"] = CMWG_NAMESPACE
238
+ xml["resourceURI"] = resource_uri
215
239
  XmlSimple.xml_out(xml, :root_name => xml_tag_name)
216
240
  end
217
241
 
@@ -223,24 +247,6 @@ class CIMI::Model::Base
223
247
  self.class.to_xml(self)
224
248
  end
225
249
 
226
- #
227
- # Common attributes for all resources
228
- #
229
- text :id, :name, :description, :created
230
-
231
- hash :property
232
-
233
- def self.acts_as_root_entity(name=nil)
234
- if name
235
- name = name.to_s.camelize.pluralize
236
- else
237
- name = xml_tag_name.pluralize.uncapitalize
238
- end
239
- CIMI::Model.register_as_root_entity! name
240
- end
241
-
242
- def self.all(_self); find(:all, _self); end
243
-
244
250
  def filter_by(filter_opts)
245
251
  return self if filter_opts.nil?
246
252
  return filter_attributes(filter_opts.split(',').map{ |a| a.intern }) if filter_opts.include? ','
@@ -252,16 +258,6 @@ class CIMI::Model::Base
252
258
  end
253
259
  end
254
260
 
255
- private
256
-
257
- def filter_attributes(attr_list)
258
- attrs = attr_list.inject({}) do |result, attr|
259
- result[attr] = self.send(attr) if self.respond_to?(attr)
260
- result
261
- end
262
- self.class.new(attrs)
263
- end
264
-
265
261
  def filter_by_arr_index(attr, filter)
266
262
  return self unless self.respond_to?(attr)
267
263
  self.class.new(attr => [self.send(attr)[filter.to_i]])
@@ -273,3 +269,20 @@ class CIMI::Model::Base
273
269
  self.class.new(attr => self.send(attr)[filter])
274
270
  end
275
271
  end
272
+
273
+ class CIMI::Model::Base < CIMI::Model::Resource
274
+ #
275
+ # Common attributes for all resources
276
+ #
277
+ text :id, :name, :description, :created
278
+
279
+ hash :property
280
+
281
+ def filter_attributes(attr_list)
282
+ attrs = attr_list.inject({}) do |result, attr|
283
+ result[attr] = self.send(attr) if self.respond_to?(attr)
284
+ result
285
+ end
286
+ self.class.new(attrs)
287
+ end
288
+ end