deltacloud-core 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. data/Rakefile +10 -12
  2. data/config/drivers/{aruba.yaml → arubacloud.yaml} +2 -2
  3. data/deltacloud-core.gemspec +4 -4
  4. data/lib/cimi/collections/address_templates.rb +1 -1
  5. data/lib/cimi/collections/addresses.rb +2 -2
  6. data/lib/cimi/collections/base.rb +1 -0
  7. data/lib/cimi/collections/credentials.rb +1 -1
  8. data/lib/cimi/collections/forwarding_group_templates.rb +1 -1
  9. data/lib/cimi/collections/forwarding_groups.rb +1 -1
  10. data/lib/cimi/collections/machine_configurations.rb +1 -1
  11. data/lib/cimi/collections/machine_images.rb +1 -1
  12. data/lib/cimi/collections/machine_templates.rb +1 -1
  13. data/lib/cimi/collections/machines.rb +2 -2
  14. data/lib/cimi/collections/network_configurations.rb +1 -1
  15. data/lib/cimi/collections/network_port_configurations.rb +1 -1
  16. data/lib/cimi/collections/network_port_templates.rb +1 -1
  17. data/lib/cimi/collections/network_ports.rb +1 -1
  18. data/lib/cimi/collections/network_templates.rb +1 -1
  19. data/lib/cimi/collections/networks.rb +1 -1
  20. data/lib/cimi/collections/volume_configurations.rb +1 -1
  21. data/lib/cimi/collections/volume_images.rb +1 -1
  22. data/lib/cimi/collections/volume_templates.rb +1 -1
  23. data/lib/cimi/collections/volumes.rb +1 -1
  24. data/lib/cimi/helpers/database_helper.rb +16 -61
  25. data/lib/cimi/helpers/filter_helper.rb +41 -0
  26. data/lib/cimi/helpers/select_helper.rb +62 -0
  27. data/lib/cimi/models.rb +21 -2
  28. data/lib/cimi/models/address.rb +9 -7
  29. data/lib/cimi/models/address_template.rb +4 -4
  30. data/lib/cimi/models/base.rb +62 -197
  31. data/lib/cimi/models/collection.rb +78 -70
  32. data/lib/cimi/models/disk.rb +15 -8
  33. data/lib/cimi/models/machine.rb +27 -29
  34. data/lib/cimi/models/machine_image.rb +10 -13
  35. data/lib/cimi/models/machine_template.rb +3 -3
  36. data/lib/cimi/models/resource.rb +190 -0
  37. data/lib/cimi/models/schema.rb +9 -0
  38. data/lib/cimi/models/volume.rb +10 -13
  39. data/lib/cimi/models/volume_configuration.rb +3 -3
  40. data/lib/cimi/models/volume_template.rb +2 -2
  41. data/lib/cimi/server.rb +1 -0
  42. data/lib/db.rb +15 -0
  43. data/lib/db/address_template.rb +15 -0
  44. data/lib/db/entity.rb +55 -0
  45. data/lib/db/machine_template.rb +15 -0
  46. data/lib/db/provider.rb +40 -0
  47. data/lib/db/volume_configuration.rb +15 -0
  48. data/lib/db/volume_template.rb +15 -0
  49. data/lib/deltacloud/collections/base.rb +1 -0
  50. data/lib/deltacloud/collections/instances.rb +2 -1
  51. data/lib/deltacloud/collections/storage_snapshots.rb +3 -1
  52. data/lib/deltacloud/core_ext/array.rb +5 -0
  53. data/lib/deltacloud/drivers/{aruba/aruba_driver.rb → arubacloud/arubacloud_driver.rb} +3 -6
  54. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +48 -75
  55. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +18 -3
  56. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +25 -0
  57. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +1 -1
  58. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +34 -14
  59. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +2 -0
  60. data/lib/deltacloud/drivers/mock/mock_driver.rb +3 -3
  61. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +93 -33
  62. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +2 -0
  63. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +2 -2
  64. data/lib/deltacloud/helpers/deltacloud_helper.rb +3 -1
  65. data/lib/deltacloud/helpers/rabbit_helper.rb +1 -2
  66. data/lib/deltacloud/models/address.rb +1 -0
  67. data/lib/deltacloud/models/blob.rb +1 -0
  68. data/lib/deltacloud/models/bucket.rb +1 -0
  69. data/lib/deltacloud/models/firewall.rb +1 -0
  70. data/lib/deltacloud/models/hardware_profile.rb +3 -1
  71. data/lib/deltacloud/models/image.rb +7 -0
  72. data/lib/deltacloud/models/instance.rb +12 -3
  73. data/lib/deltacloud/models/key.rb +1 -0
  74. data/lib/deltacloud/models/load_balancer.rb +1 -0
  75. data/lib/deltacloud/models/metric.rb +1 -0
  76. data/lib/deltacloud/models/realm.rb +10 -1
  77. data/lib/deltacloud/models/storage_snapshot.rb +1 -0
  78. data/lib/deltacloud/models/storage_volume.rb +2 -1
  79. data/lib/deltacloud/runner.rb +2 -1
  80. data/lib/deltacloud/server.rb +1 -0
  81. data/lib/deltacloud/version.rb +1 -1
  82. data/lib/deltacloud_rack.rb +4 -0
  83. data/tests/cimi/collections/machines_test.rb +80 -0
  84. data/tests/cimi/db/database_helper_test.rb +54 -99
  85. data/tests/cimi/db/db_helper.rb +2 -0
  86. data/tests/cimi/db/entity_test.rb +29 -0
  87. data/tests/cimi/model/collection_spec.rb +2 -2
  88. data/tests/cimi/model/credential_spec.rb +2 -2
  89. data/tests/cimi/model/machine_configuration_spec.rb +2 -2
  90. data/tests/cimi/model/machine_image_spec.rb +2 -2
  91. data/tests/cimi/model/machine_spec.rb +4 -4
  92. data/tests/cimi/model/machine_template_spec.rb +2 -2
  93. data/tests/cimi/model/volume_configuration_spec.rb +2 -2
  94. data/tests/cimi/model/volume_image_spec.rb +2 -2
  95. data/tests/cimi/model/volume_spec.rb +2 -2
  96. data/tests/cimi/model/volume_template_spec.rb +2 -2
  97. data/tests/cimi/spec_helper.rb +4 -0
  98. data/tests/deltacloud/collections/instances_collection_test.rb +3 -1
  99. data/tests/deltacloud/launcher_test.rb +3 -5
  100. data/tests/drivers/ec2/images_test.rb +7 -0
  101. data/tests/drivers/gogrid/images_test.rb +7 -0
  102. data/tests/drivers/openstack/instances_test.rb +8 -8
  103. data/tests/drivers/openstack/realms_test.rb +13 -13
  104. data/views/errors/403.xml.haml +2 -1
  105. data/views/images/show.html.haml +4 -1
  106. data/views/images/show.xml.haml +1 -0
  107. data/views/instances/new.html.haml +1 -1
  108. data/views/instances/show.html.haml +3 -0
  109. data/views/realms/index.html.haml +2 -0
  110. data/views/realms/show.html.haml +4 -0
  111. data/views/realms/show.xml.haml +3 -0
  112. metadata +19 -14
data/Rakefile CHANGED
@@ -146,8 +146,8 @@ task :test do
146
146
  Rake::Task["mock:fixtures:reset"].invoke
147
147
  puts "\n[ \033[1;37;mrake test:ec2\33[0m ]\n"
148
148
  Rake::Task["test:ec2"].invoke
149
- puts "\n[ \033[1;37;mrake test:cimi:models\33[0m ]\n"
150
- Rake::Task["test:cimi:models"].invoke
149
+ puts "\n[ \033[1;37;mrake test:cimi\33[0m ]\n"
150
+ Rake::Task["test:cimi"].invoke
151
151
  DRIVERS.each do |driver|
152
152
  puts "\n[ \033[1;37;mrake drivers:#{driver}\33[0m ]\n"
153
153
  Rake::Task["test:drivers:#{driver}"].invoke
@@ -200,17 +200,15 @@ namespace :test do
200
200
  ]
201
201
  end
202
202
 
203
- namespace :cimi do
204
- Rake::TestTask.new(:models) do |t|
205
- unless RUBY_VERSION < '1.9.0'
206
- t.loader = :testrb
207
- end
208
- t.test_files = FileList[
209
- 'tests/cimi/db/*test.rb', # CIMI frontend database tests
210
- 'tests/cimi/model/*spec.rb', # CIMI frontend serialization API tests
211
- 'tests/cimi/collections/*test.rb', # CIMI frontend API tests
212
- ]
203
+ Rake::TestTask.new(:cimi) do |t|
204
+ unless RUBY_VERSION < '1.9.0'
205
+ t.loader = :testrb
213
206
  end
207
+ t.test_files = FileList[
208
+ 'tests/cimi/db/*test.rb', # CIMI frontend database tests
209
+ 'tests/cimi/model/*spec.rb', # CIMI frontend serialization API tests
210
+ 'tests/cimi/collections/*test.rb', # CIMI frontend API tests
211
+ ]
214
212
  end
215
213
 
216
214
  end
@@ -1,8 +1,8 @@
1
1
  ---
2
- :aruba:
2
+ :arubacloud:
3
3
  :entrypoints:
4
4
  compute:
5
5
  dc1: https://api.dc1.computing.cloud.it/WsEndUser/v2.0/WsEndUser.svc?wsdl
6
6
  dc2: https://api.dc2.computing.cloud.it/WsEndUser/v2.0/WsEndUser.svc?wsdl
7
7
  dc3: https://api.dc3.computing.cloud.it/WsEndUser/v2.0/WsEndUser.svc?wsdl
8
- :name: Aruba
8
+ :name: Arubacloud
@@ -72,7 +72,7 @@ Gem::Specification.new do |s|
72
72
  s.add_dependency('sinatra-rabbit', '>= 1.0.11')
73
73
  s.add_dependency('rack', '>= 1.0.0')
74
74
  s.add_dependency('rack-accept')
75
- s.add_dependency('json', '>= 1.1.9')
75
+ s.add_dependency('json_pure', '>= 1.5.0')
76
76
  s.add_dependency('net-ssh', '>= 2.0.0')
77
77
  s.add_dependency('nokogiri', '>= 1.4.3')
78
78
  s.add_dependency('require_relative') if RUBY_VERSION < '1.9'
@@ -89,10 +89,10 @@ Gem::Specification.new do |s|
89
89
  # dependencies for various cloud providers:
90
90
 
91
91
  # RHEV-M and oVirt
92
- s.add_dependency('rbovirt', '>=0.0.16')
92
+ s.add_dependency('rbovirt', '>=0.0.17')
93
93
 
94
94
  # Amazon EC2 S3
95
- s.add_dependency('aws', '>=2.6.0')
95
+ s.add_dependency('aws', '>=2.7.0')
96
96
  # Microsoft Azure
97
97
  s.add_dependency('waz-storage', '>=1.1.0')
98
98
 
@@ -111,7 +111,7 @@ Gem::Specification.new do |s|
111
111
  s.add_dependency('uuidtools', '>= 2.1.1')
112
112
 
113
113
  # Openstack Compute and Object-Storage
114
- s.add_dependency('openstack', '>= 1.0.7')
114
+ s.add_dependency('openstack', '>= 1.0.9')
115
115
 
116
116
  # Aruba Cloud
117
117
  s.add_dependency('savon', '>= 1.0.0')
@@ -23,7 +23,7 @@ module CIMI::Collections
23
23
  operation :index do
24
24
  description 'List all AddressTemplates in the AddressTemplateCollection'
25
25
  control do
26
- address_templates = AddressTemplate.list(self).filter_by(params['$select'])
26
+ address_templates = AddressTemplate.list(self).select_by(params['$select'])
27
27
  respond_to do |format|
28
28
  format.xml {address_templates.to_xml}
29
29
  format.json {address_templates.to_json}
@@ -20,12 +20,12 @@ module CIMI::Collections
20
20
 
21
21
  collection :addresses do
22
22
 
23
- description 'An Address represents an IP address, and its associated metdata, for a particular Network.'
23
+ description 'An Address represents an IP address, and its associated metadata, for a particular Network.'
24
24
 
25
25
  operation :index, :with_capability => :addresses do
26
26
  description 'List all Addresses in the AddressCollection'
27
27
  control do
28
- addresses = Address.list(self).filter_by(params['$select'])
28
+ addresses = Address.list(self).select_by(params['$select'])
29
29
  respond_to do |format|
30
30
  format.xml {addresses.to_xml}
31
31
  format.json {addresses.to_json}
@@ -43,6 +43,7 @@ module CIMI::Collections
43
43
  set :views, root + '/views/cimi'
44
44
  set :public_folder, root + '/public'
45
45
  set :documentation_class, CIMI
46
+ set :haml, :format => :xhtml
46
47
 
47
48
  error do
48
49
  report_error
@@ -24,7 +24,7 @@ module CIMI::Collections
24
24
  operation :index, :with_capability => :keys do
25
25
  description "List all machine admins"
26
26
  control do
27
- credentials = Credential.list(self).filter_by(params['$select'])
27
+ credentials = Credential.list(self).select_by(params['$select'])
28
28
  respond_to do |format|
29
29
  format.xml { credentials.to_xml }
30
30
  format.json { credentials.to_json }
@@ -22,7 +22,7 @@ module CIMI::Collections
22
22
  operation :index, :with_capability => :forwarding_groups do
23
23
  description 'List all ForwardingGroupTemplates in the ForwardingGroupTemplateCollection'
24
24
  control do
25
- forwarding_group_templates = ForwardingGroupTemplate.list(self).filter_by(params['$select'])
25
+ forwarding_group_templates = ForwardingGroupTemplate.list(self).select_by(params['$select'])
26
26
  respond_to do |format|
27
27
  format.xml {forwarding_group_templates.to_xml}
28
28
  format.json {forwarding_group_templates.to_json}
@@ -22,7 +22,7 @@ module CIMI::Collections
22
22
  operation :index, :with_capability => :forwarding_groups do
23
23
  description 'List all ForwardingGroups in the ForwardingGroupsCollection'
24
24
  control do
25
- forwarding_groups = ForwardingGroup.list(self).filter_by(params['$select'])
25
+ forwarding_groups = ForwardingGroup.list(self).select_by(params['$select'])
26
26
  respond_to do |format|
27
27
  format.xml {forwarding_groups.to_xml}
28
28
  format.json {forwarding_groups.to_json}
@@ -24,7 +24,7 @@ module CIMI::Collections
24
24
  operation :index, :with_capability => :hardware_profiles do
25
25
  description "List all machine configurations"
26
26
  control do
27
- machine_configs = MachineConfiguration.list(self).filter_by(params['$select'])
27
+ machine_configs = MachineConfiguration.list(self).select_by(params['$select'])
28
28
  respond_to do |format|
29
29
  format.xml { machine_configs.to_xml }
30
30
  format.json { machine_configs.to_json }
@@ -24,7 +24,7 @@ module CIMI::Collections
24
24
  operation :index, :with_capability => :images do
25
25
  description "List all machine configurations"
26
26
  control do
27
- machine_images = MachineImage.list(self).filter_by(params['$select'])
27
+ machine_images = MachineImage.list(self).select_by(params['$select'])
28
28
  respond_to do |format|
29
29
  format.xml { machine_images.to_xml }
30
30
  format.json { machine_images.to_json }
@@ -23,7 +23,7 @@ module CIMI::Collections
23
23
  operation :index do
24
24
  description "List all machine templates"
25
25
  control do
26
- machine_templates = CIMI::Model::MachineTemplate.list(self).filter_by(params['$select'])
26
+ machine_templates = CIMI::Model::MachineTemplate.list(self).select_by(params['$select'])
27
27
  respond_to do |format|
28
28
  format.xml { machine_templates.to_xml }
29
29
  format.json { machine_templates.to_json }
@@ -24,7 +24,7 @@ module CIMI::Collections
24
24
  operation :index, :with_capability => :instances do
25
25
  description "List all machines"
26
26
  control do
27
- machines = Machine.list(self).filter_by(params['$select'])
27
+ machines = Machine.list(self).select_by(params['$select']).filter_by(params['$filter'])
28
28
  respond_to do |format|
29
29
  format.xml { machines.to_xml }
30
30
  format.json { machines.to_json }
@@ -85,7 +85,7 @@ module CIMI::Collections
85
85
  end
86
86
 
87
87
  action :restart, :with_capability => :reboot_instance do
88
- description "Start specific machine."
88
+ description "Restart specific machine."
89
89
  param :id, :string, :required
90
90
  control do
91
91
  machine = Machine.find(params[:id], self)
@@ -23,7 +23,7 @@ module CIMI::Collections
23
23
  operation :index, :with_capability => :network_configurations do
24
24
  description 'List all NetworkConfigurations'
25
25
  control do
26
- network_configurations = NetworkConfiguration.list(self).filter_by(params['$select'])
26
+ network_configurations = NetworkConfiguration.list(self).select_by(params['$select'])
27
27
  respond_to do |format|
28
28
  format.xml { network_configurations.to_xml }
29
29
  format.json { network_configurations.to_json }
@@ -23,7 +23,7 @@ module CIMI::Collections
23
23
  operation :index, :with_capability => :network_port_configurations do
24
24
  description 'List all NetworkPortConfigurations in the NetworkPortConfigurationCollection'
25
25
  control do
26
- net_port_configs = NetworkPortConfiguration.list(self).filter_by(params['$select'])
26
+ net_port_configs = NetworkPortConfiguration.list(self).select_by(params['$select'])
27
27
  respond_to do |format|
28
28
  format.xml {net_port_configs.to_xml}
29
29
  format.json {net_port_configs.to_json}
@@ -25,7 +25,7 @@ module CIMI::Collections
25
25
  operation :index, :with_capability => :network_port_templates do
26
26
  description 'List all NetworkPortTemplates in the NetworkPortTemplateCollection'
27
27
  control do
28
- network_port_templates = NetworkPortTemplate.list(self).filter_by(params['$select'])
28
+ network_port_templates = NetworkPortTemplate.list(self).select_by(params['$select'])
29
29
  respond_to do |format|
30
30
  format.xml {network_port_templates.to_xml}
31
31
  format.json {network_port_templates.to_json}
@@ -25,7 +25,7 @@ module CIMI::Collections
25
25
  operation :index, :with_capability => :network_ports do
26
26
  description 'List all NetworkPorts in the NetworkPortCollection'
27
27
  control do
28
- network_ports = NetworkPort.list(self).filter_by(params['$select'])
28
+ network_ports = NetworkPort.list(self).select_by(params['$select'])
29
29
  respond_to do |format|
30
30
  format.xml {network_ports.to_xml}
31
31
  format.json {network_ports.to_json}
@@ -23,7 +23,7 @@ module CIMI::Collections
23
23
  operation :index, :with_capability => :network_templates do
24
24
  description 'List all Network Templates in the NetworkTemplateCollection'
25
25
  control do
26
- network_templates = NetworkTemplate.list(self).filter_by(params['$select'])
26
+ network_templates = NetworkTemplate.list(self).select_by(params['$select'])
27
27
  respond_to do |format|
28
28
  format.xml {network_templates.to_xml}
29
29
  format.json {network_templates.to_json}
@@ -24,7 +24,7 @@ module CIMI::Collections
24
24
  operation :index, :with_capability => :networks do
25
25
  description "List all Networks"
26
26
  control do
27
- networks = Network.list(self).filter_by(params['$select'])
27
+ networks = Network.list(self).select_by(params['$select'])
28
28
  respond_to do |format|
29
29
  format.xml { networks.to_xml }
30
30
  format.json { networks.to_json }
@@ -23,7 +23,7 @@ module CIMI::Collections
23
23
  operation :index, :with_capability => :storage_volumes do
24
24
  description "Get list all VolumeConfigurations"
25
25
  control do
26
- volume_configuration = VolumeConfiguration.list(self).filter_by(params['$select'])
26
+ volume_configuration = VolumeConfiguration.list(self).select_by(params['$select'])
27
27
  respond_to do |format|
28
28
  format.xml { volume_configuration.to_xml }
29
29
  format.json { volume_configuration.to_json }
@@ -24,7 +24,7 @@ module CIMI::Collections
24
24
  operation :index, :with_capability => :storage_snapshots do
25
25
  description "List all volumes images"
26
26
  control do
27
- volume_images = VolumeImage.list(self).filter_by(params['$select'])
27
+ volume_images = VolumeImage.list(self).select_by(params['$select'])
28
28
  respond_to do |format|
29
29
  format.xml { volume_images.to_xml }
30
30
  format.json { volume_images.to_json }
@@ -23,7 +23,7 @@ module CIMI::Collections
23
23
  operation :index, :with_capability => :storage_volumes do
24
24
  description "Retrieve the Volume Template Collection"
25
25
  control do
26
- volume_template = VolumeTemplate.list(self).filter_by(params['$select'])
26
+ volume_template = VolumeTemplate.list(self).select_by(params['$select'])
27
27
  respond_to do |format|
28
28
  format.xml { volume_template.to_xml }
29
29
  format.json { volume_template.to_json }
@@ -23,7 +23,7 @@ module CIMI::Collections
23
23
  operation :index, :with_capability => :storage_volumes do
24
24
  description "List all volumes"
25
25
  control do
26
- volumes = Volume.list(self).filter_by(params['$select'])
26
+ volumes = Volume.list(self).select_by(params['$select'])
27
27
  respond_to do |format|
28
28
  format.xml { volumes.to_xml }
29
29
  format.json { volumes.to_json }
@@ -1,3 +1,18 @@
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
+
1
16
  module Deltacloud
2
17
  module Helpers
3
18
 
@@ -18,25 +33,6 @@ module Deltacloud
18
33
  return false
19
34
  end
20
35
 
21
- def load_attributes_for(model)
22
- return {} if test_environment?
23
- entity = get_entity(model)
24
- entity.nil? ? {} : entity.to_hash
25
- end
26
-
27
- def delete_attributes_for(model)
28
- return if test_environment?
29
- entity = get_entity(model)
30
- !entity.nil? && entity.destroy
31
- end
32
-
33
- def get_entity(model)
34
- current_db.entities_dataset.first(
35
- :be_kind => model.to_entity,
36
- :be_id => model.id
37
- )
38
- end
39
-
40
36
  def current_provider
41
37
  Thread.current[:provider] || ENV['API_PROVIDER'] || 'default'
42
38
  end
@@ -46,49 +42,8 @@ module Deltacloud
46
42
  #
47
43
 
48
44
  def current_db
49
- Deltacloud::Database::Provider.find_or_create(:driver => driver_symbol.to_s, :url => current_provider)
50
- end
51
-
52
- def store_attributes_for(model, attrs={})
53
- return if test_environment? or model.nil? or attrs.empty?
54
- return if model.id.nil?
55
-
56
- unless entity = get_entity(model)
57
- entity = Deltacloud::Database::Entity.new(
58
- :provider_id => current_db.id,
59
- :be_id => model.id,
60
- :be_kind => model.to_entity
61
- )
62
- end
63
-
64
- entity.description = extract_attribute_value('description', attrs) if attrs.has_key? 'description'
65
- entity.name = extract_attribute_value('name', attrs) if attrs.has_key? 'name'
66
-
67
- if attrs.has_key? 'properties'
68
- entity.ent_properties = extract_attribute_value('properties', attrs).to_json
69
- elsif attrs.has_key? 'property'
70
- entity.ent_properties = extract_attribute_value('property', attrs).to_json
71
- end
72
-
73
- entity.exists? ? entity.save_changes : entity.save
74
-
75
- entity
45
+ Deltacloud::Database::Provider.lookup
76
46
  end
77
-
78
- # In XML serialization the values stored in attrs are arrays, dues to
79
- # XmlSimple. This method will help extract values from them
80
- #
81
- def extract_attribute_value(name, attrs={})
82
- return unless attrs[name]
83
- if name == 'property'
84
- attrs[name].is_a?(Array) ?
85
- attrs[name].inject({}) { |r, v| r[v['key']] = v['content']; r} :
86
- attrs[name]
87
- else
88
- attrs[name].is_a?(Array) ? attrs[name].first : attrs[name]
89
- end
90
- end
91
-
92
47
  end
93
48
  end
94
49
 
@@ -0,0 +1,41 @@
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
17
+ module Helpers
18
+ module FilterResourceMethods
19
+
20
+ def filter_by(filter_opts)
21
+ return self if filter_opts.nil?
22
+ return self unless kind_of? CIMI::Model::Collection
23
+ attribute, value = parse_filter_opts(filter_opts)
24
+ if attribute =~ /\!$/
25
+ attribute.chomp!('!')
26
+ self.entries.delete_if { |entry| entry[attribute.to_sym] == value }
27
+ else
28
+ self.entries.delete_if { |entry| entry[attribute.to_sym] != value }
29
+ end
30
+ self
31
+ end
32
+
33
+ def parse_filter_opts(opts)
34
+ attribute, value = opts.split('=')
35
+ value.gsub!(/\A("|')|("|')\Z/, '')
36
+ [attribute, value]
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,62 @@
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
17
+ module Helpers
18
+ module SelectResourceMethods
19
+
20
+ def select_by(filter_opts)
21
+ return self if filter_opts.nil?
22
+ return self unless kind_of? CIMI::Model::Collection
23
+ if filter_opts.include? ','
24
+ return select_attributes(filter_opts.split(',').map{ |a| a.intern })
25
+ end
26
+ case filter_opts
27
+ when /^([\w\_]+)$/ then select_attributes([$1.intern])
28
+ when /^([\w\_]+)\[(\d+\-\d+)\]$/ then select_by_arr_range($1.intern, $2)
29
+ when /^([\w\_]+)\[(\d+)\]$/ then select_by_arr_index($1.intern, $2)
30
+ else self
31
+ end
32
+ end
33
+
34
+ def select_by_arr_index(attr, filter)
35
+ return self unless self.respond_to?(attr)
36
+ self.class.new(attr => [self.send(attr)[filter.to_i]])
37
+ end
38
+
39
+ def select_by_arr_range(attr, filter)
40
+ return self unless self.respond_to?(attr)
41
+ filter = filter.split('-').inject { |s,e| s.to_i..e.to_i }
42
+ self.class.new(attr => self.send(attr)[filter])
43
+ end
44
+
45
+ end
46
+
47
+ module SelectBaseMethods
48
+ def select_attributes(attr_list)
49
+ attrs = attr_list.inject({}) do |result, attr|
50
+ attr = attr.to_s.underscore
51
+ result[attr.to_sym] = self.send(attr) if self.respond_to?(attr)
52
+ result
53
+ end
54
+ self.class.new(attrs.merge(
55
+ :select_attr_list => attr_list,
56
+ :base_id => self.send(:id)
57
+ ))
58
+ end
59
+ end
60
+
61
+ end
62
+ end