deltacloud-core 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/LICENSE +23 -0
  2. data/NOTICE +3 -0
  3. data/Rakefile +32 -20
  4. data/bin/deltacloudd +1 -1
  5. data/config.ru +25 -32
  6. data/deltacloud-core.gemspec +1 -1
  7. data/lib/cimi/collections.rb +4 -1
  8. data/lib/cimi/collections/address_templates.rb +2 -2
  9. data/lib/cimi/collections/addresses.rb +1 -1
  10. data/lib/cimi/collections/base.rb +64 -0
  11. data/lib/cimi/collections/{machine_admins.rb → credentials.rb} +12 -12
  12. data/lib/cimi/collections/{vsp_templates.rb → forwarding_group_templates.rb} +12 -16
  13. data/lib/cimi/collections/{vsp_configurations.rb → forwarding_groups.rb} +12 -13
  14. data/lib/cimi/collections/machine_configurations.rb +2 -2
  15. data/lib/cimi/collections/machine_images.rb +1 -1
  16. data/lib/cimi/collections/machines.rb +8 -2
  17. data/lib/cimi/collections/network_configurations.rb +2 -2
  18. data/lib/cimi/collections/{routing_groups.rb → network_port_configurations.rb} +12 -12
  19. data/lib/cimi/collections/{routing_group_templates.rb → network_port_templates.rb} +15 -12
  20. data/lib/cimi/collections/{vsps.rb → network_ports.rb} +33 -32
  21. data/lib/cimi/collections/network_templates.rb +2 -2
  22. data/lib/cimi/collections/networks.rb +17 -2
  23. data/lib/cimi/collections/{entity_metadata.rb → resource_metadata.rb} +10 -10
  24. data/lib/cimi/collections/volume_configurations.rb +1 -1
  25. data/lib/cimi/collections/volume_images.rb +1 -1
  26. data/lib/cimi/collections/volumes.rb +1 -2
  27. data/lib/cimi/dependencies.rb +1 -1
  28. data/lib/cimi/helpers.rb +3 -84
  29. data/lib/cimi/helpers/cimi_helper.rb +15 -14
  30. data/lib/cimi/models.rb +20 -36
  31. data/lib/cimi/models/address.rb +32 -4
  32. data/lib/cimi/models/address_template.rb +2 -2
  33. data/lib/cimi/models/base.rb +24 -5
  34. data/lib/cimi/models/cloud_entry_point.rb +4 -9
  35. data/lib/cimi/models/collection.rb +101 -0
  36. data/lib/cimi/models/{machine_admin.rb → credential.rb} +6 -4
  37. data/lib/cimi/models/disk_collection.rb +1 -2
  38. data/lib/cimi/models/{routing_group_template.rb → forwarding_group.rb} +5 -3
  39. data/lib/cimi/models/{routing_group.rb → forwarding_group_template.rb} +5 -3
  40. data/lib/cimi/models/machine.rb +9 -7
  41. data/lib/cimi/models/machine_configuration.rb +2 -0
  42. data/lib/cimi/models/machine_image.rb +2 -0
  43. data/lib/cimi/models/machine_template.rb +3 -1
  44. data/lib/cimi/models/machine_volume_collection.rb +1 -1
  45. data/lib/cimi/models/network.rb +2 -0
  46. data/lib/cimi/models/network_configuration.rb +4 -8
  47. data/lib/cimi/models/{vsp.rb → network_port.rb} +7 -11
  48. data/lib/cimi/models/{network_configuration_collection.rb → network_port_collection.rb} +25 -8
  49. data/lib/cimi/models/{vsp_configuration.rb → network_port_configuration.rb} +6 -10
  50. data/lib/cimi/models/{network_collection.rb → network_port_configuration_collection.rb} +9 -9
  51. data/lib/cimi/models/{vsp_template.rb → network_port_template.rb} +6 -4
  52. data/lib/cimi/models/{network_template_collection.rb → network_port_template_collection.rb} +10 -8
  53. data/lib/cimi/models/network_template.rb +3 -1
  54. data/lib/cimi/models/{entity_metadata.rb → resource_metadata.rb} +16 -15
  55. data/lib/cimi/models/schema.rb +23 -12
  56. data/lib/cimi/models/volume.rb +2 -0
  57. data/lib/cimi/models/volume_configuration.rb +2 -0
  58. data/lib/cimi/models/volume_image.rb +2 -0
  59. data/lib/cimi/models/volume_template.rb +2 -0
  60. data/lib/cimi/server.rb +10 -6
  61. data/lib/deltacloud/collections.rb +7 -2
  62. data/lib/deltacloud/collections/addresses.rb +3 -1
  63. data/lib/deltacloud/collections/base.rb +64 -0
  64. data/lib/deltacloud/collections/buckets.rb +14 -4
  65. data/lib/deltacloud/collections/drivers.rb +1 -1
  66. data/lib/deltacloud/collections/firewalls.rb +1 -1
  67. data/lib/deltacloud/collections/instances.rb +5 -1
  68. data/lib/deltacloud/collections/keys.rb +1 -1
  69. data/lib/deltacloud/collections/load_balancers.rb +2 -0
  70. data/lib/deltacloud/collections/storage_volumes.rb +3 -5
  71. data/lib/deltacloud/core_ext.rb +1 -0
  72. data/lib/deltacloud/core_ext/hash.rb +8 -0
  73. data/lib/deltacloud/core_ext/ordered_hash.rb +222 -0
  74. data/lib/deltacloud/core_ext/string.rb +9 -0
  75. data/lib/deltacloud/drivers/aruba/aruba_driver.rb +0 -9
  76. data/lib/deltacloud/drivers/base_driver.rb +22 -4
  77. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +0 -4
  78. data/lib/deltacloud/drivers/exceptions.rb +30 -13
  79. data/lib/deltacloud/drivers/features.rb +7 -0
  80. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1 -9
  81. data/lib/deltacloud/drivers/google/google_driver.rb +13 -0
  82. data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.1.yml +3 -0
  83. data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.2.yml +3 -0
  84. data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.3.yml +3 -0
  85. data/lib/deltacloud/drivers/mock/data/addresses/192.168.0.4.yml +3 -0
  86. data/lib/deltacloud/drivers/mock/mock_driver.rb +65 -1
  87. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +55 -32
  88. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +18 -6
  89. data/lib/deltacloud/helpers.rb +0 -75
  90. data/lib/deltacloud/helpers/deltacloud_helper.rb +66 -28
  91. data/lib/deltacloud/helpers/driver_helper.rb +7 -0
  92. data/lib/deltacloud/helpers/rabbit_helper.rb +51 -0
  93. data/lib/deltacloud/server.rb +12 -14
  94. data/lib/deltacloud/version.rb +1 -1
  95. data/lib/deltacloud_rack.rb +26 -2
  96. data/lib/ec2/query_parser.rb +18 -3
  97. data/lib/sinatra/rack_accept.rb +7 -2
  98. data/lib/sinatra/rack_matrix_params.rb +14 -14
  99. data/public/javascripts/cmwgapp.js +2 -2
  100. data/tests/cimi/collections/cloud_entry_point_test.rb +3 -3
  101. data/tests/cimi/collections/machine_images_test.rb +2 -2
  102. data/tests/cimi/collections/machines_test.rb +1 -1
  103. data/tests/cimi/collections/url_helper_test.rb +31 -0
  104. data/tests/cimi/spec/cimi/model/{machine_admin_spec.rb → credential_spec.rb} +4 -4
  105. data/tests/deltacloud/base_collection_test.rb +0 -5
  106. data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
  107. data/tests/deltacloud/collections/drivers_collection_test.rb +1 -1
  108. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +1 -1
  109. data/tests/deltacloud/collections/images_collection_test.rb +1 -1
  110. data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
  111. data/tests/deltacloud/collections/instances_collection_test.rb +1 -1
  112. data/tests/deltacloud/collections/keys_collection_test.rb +1 -4
  113. data/tests/deltacloud/deltacloud_helper_test.rb +0 -9
  114. data/tests/deltacloud/server_test.rb +1 -1
  115. data/tests/drivers/base/base_driver_test.rb +30 -0
  116. data/tests/drivers/base/common.rb +14 -0
  117. data/tests/drivers/base/exceptions_test.rb +64 -0
  118. data/tests/drivers/ec2/buckets_test.rb +45 -0
  119. data/tests/drivers/ec2/keys_test.rb +1 -1
  120. data/tests/drivers/google/buckets_test.rb +2 -2
  121. data/tests/drivers/google/common.rb +3 -3
  122. data/tests/test_helper.rb +28 -0
  123. data/views/api/show.html.haml +2 -2
  124. data/views/api/show.xml.haml +1 -1
  125. data/views/buckets/index.html.haml +1 -1
  126. data/views/cimi/cloudEntryPoint/index.xml.haml +1 -1
  127. data/views/cimi/collection/index.html.haml +3 -3
  128. data/views/cimi/collection/response.xml.haml +1 -1
  129. data/views/cimi/error.html.haml +1 -1
  130. data/views/cimi/errors/500.xml.haml +1 -1
  131. data/views/cimi/layout.html.haml +1 -1
  132. data/views/cimi/machine_configurations/show.html.haml +2 -2
  133. data/views/cimi/machine_configurations/show.xml.haml +1 -1
  134. data/views/cimi/machine_images/show.html.haml +2 -2
  135. data/views/cimi/machine_images/show.xml.haml +1 -1
  136. data/views/cimi/machines/show.html.haml +2 -2
  137. data/views/cimi/machines/show.xml.haml +1 -1
  138. data/views/cimi/volumes/show.html.haml +2 -2
  139. data/views/cimi/volumes/show.xml.haml +1 -1
  140. data/views/docs/collection.html.haml +1 -1
  141. data/views/docs/collection.xml.haml +2 -2
  142. data/views/docs/index.html.haml +1 -1
  143. data/views/docs/index.xml.haml +1 -1
  144. data/views/docs/operation.xml.haml +1 -1
  145. data/views/error.html.haml +1 -1
  146. data/views/errors/500.html.haml +7 -4
  147. data/views/firewalls/index.html.haml +1 -1
  148. data/views/firewalls/show.html.haml +1 -1
  149. data/views/images/show.html.haml +2 -2
  150. data/views/index.html.haml +9 -0
  151. data/views/instance_states/show.html.haml +1 -1
  152. data/views/instances/run_command.html.haml +1 -1
  153. data/views/instances/show.html.haml +2 -2
  154. data/views/keys/index.html.haml +1 -1
  155. data/views/layout.html.haml +1 -1
  156. data/views/load_balancers/index.html.haml +1 -1
  157. data/views/load_balancers/show.html.haml +3 -3
  158. data/views/storage_snapshots/show.html.haml +1 -1
  159. data/views/storage_volumes/attach.html.haml +1 -1
  160. data/views/storage_volumes/index.html.haml +1 -1
  161. data/views/storage_volumes/show.html.haml +4 -4
  162. metadata +40 -43
  163. data/lib/cimi/models/address_collection.rb +0 -34
  164. data/lib/cimi/models/address_template_collection.rb +0 -34
  165. data/lib/cimi/models/entity_metadata_collection.rb +0 -31
  166. data/lib/cimi/models/machine_admin_collection.rb +0 -34
  167. data/lib/cimi/models/machine_collection.rb +0 -37
  168. data/lib/cimi/models/machine_configuration_collection.rb +0 -36
  169. data/lib/cimi/models/machine_image_collection.rb +0 -36
  170. data/lib/cimi/models/machine_template_collection.rb +0 -36
  171. data/lib/cimi/models/routing_group_collection.rb +0 -34
  172. data/lib/cimi/models/routing_group_template_collection.rb +0 -35
  173. data/lib/cimi/models/volume_collection.rb +0 -36
  174. data/lib/cimi/models/volume_configuration_collection.rb +0 -36
  175. data/lib/cimi/models/volume_image_collection.rb +0 -36
  176. data/lib/cimi/models/volume_template_collection.rb +0 -36
  177. data/lib/cimi/models/vsp_collection.rb +0 -34
  178. data/lib/cimi/models/vsp_configuration_collection.rb +0 -34
  179. data/lib/cimi/models/vsp_template_collection.rb +0 -34
  180. data/lib/deltacloud/helpers/url_helper.rb +0 -115
@@ -24,7 +24,7 @@ module CIMI::Collections
24
24
  description "Get list all VolumeConfigurations"
25
25
  param :CIMISelect, :string, :optional
26
26
  control do
27
- volume_configuration = VolumeConfigurationCollection.default(self).filter_by(params[:CIMISelect])
27
+ volume_configuration = VolumeConfiguration.list(self).filter_by(params[:CIMISelect])
28
28
  respond_to do |format|
29
29
  format.xml { volume_configuration.to_xml }
30
30
  format.json { volume_configuration.to_json }
@@ -25,7 +25,7 @@ module CIMI::Collections
25
25
  description "List all volumes images"
26
26
  param :CIMISelect, :string, :optional
27
27
  control do
28
- volume_images = VolumeImageCollection.default(self).filter_by(params[:CIMISelect])
28
+ volume_images = VolumeImage.list(self).filter_by(params[:CIMISelect])
29
29
  respond_to do |format|
30
30
  format.xml { volume_images.to_xml }
31
31
  format.json { volume_images.to_json }
@@ -24,7 +24,7 @@ module CIMI::Collections
24
24
  description "List all volumes"
25
25
  param :CIMISelect, :string, :optional
26
26
  control do
27
- volumes = VolumeCollection.default(self).filter_by(params[:CIMISelect])
27
+ volumes = Volume.list(self).filter_by(params[:CIMISelect])
28
28
  respond_to do |format|
29
29
  format.xml { volumes.to_xml }
30
30
  format.json { volumes.to_json }
@@ -67,7 +67,6 @@ module CIMI::Collections
67
67
 
68
68
  operation :destroy do
69
69
  description "Delete a specified Volume"
70
- param :id, :string, :required
71
70
  control do
72
71
  Volume.delete!(params[:id], self)
73
72
  no_content_with_status(200)
@@ -60,4 +60,4 @@ require 'sinatra/rack_matrix_params'
60
60
  require 'sinatra/rack_syslog'
61
61
  require 'sinatra/sinatra_verbose'
62
62
 
63
- CMWG_NAMESPACE = "http://www.dmtf.org/cimi"
63
+ CMWG_NAMESPACE = "http://schemas.dmtf.org/cimi/1"
@@ -13,104 +13,23 @@
13
13
  # License for the specific language governing permissions and limitations
14
14
  # under the License.
15
15
 
16
- module Deltacloud; end
17
- module CIMI; end
18
-
19
16
  require_relative '../deltacloud/drivers/features'
20
17
 
21
- # Declare namespace for CIMI models
22
- #
23
-
24
18
  module CIMI
25
19
  module Model; end
26
-
27
20
  class FakeCollection
28
21
  extend Sinatra::Rabbit::Features
29
22
  include Deltacloud::Features
30
23
  end
31
24
  end
32
25
 
26
+ # Declare namespace for CIMI models
27
+ #
28
+
33
29
  require_relative '../deltacloud/drivers'
34
30
  require_relative '../deltacloud/models'
35
31
  require_relative '../deltacloud/helpers/driver_helper'
36
32
  require_relative '../deltacloud/helpers/auth_helper'
37
- require_relative '../deltacloud/helpers/url_helper'
38
33
  require_relative '../deltacloud/helpers/deltacloud_helper'
39
34
  require_relative '../deltacloud/helpers/rabbit_helper'
40
35
  require_relative './helpers/cimi_helper'
41
- require_relative './models'
42
-
43
- module CIMI::Collections
44
- class Base < Sinatra::Base
45
-
46
- include Sinatra::Rabbit
47
- extend Deltacloud::Helpers::Drivers
48
- include Sinatra::Rabbit::Features
49
- include CIMI::Model
50
-
51
- helpers Deltacloud::Helpers::Drivers
52
- helpers Sinatra::AuthHelper
53
- helpers Sinatra::UrlForHelper
54
- helpers Rack::RespondTo::Helpers
55
- helpers Deltacloud::Helpers::Application
56
- helpers CIMIHelper
57
-
58
- register Rack::RespondTo
59
-
60
- enable :xhtml
61
- enable :dump_errors
62
- enable :show_errors
63
- disable :show_exceptions
64
-
65
- set :config, Deltacloud[:cimi]
66
- set :root_url, config.root_url
67
- set :root_path, config.root_url
68
- set :version, config.version
69
- set :root, File.join(File.dirname(__FILE__), '..', '..')
70
- set :views, root + '/views/cimi'
71
- set :public_folder, root + '/public'
72
-
73
- Sinatra::Rabbit.set :root_path, "#{config.root_url}/"
74
-
75
- error do
76
- report_error
77
- end
78
-
79
- error Deltacloud::ExceptionHandler::ValidationFailure do
80
- report_error
81
- end
82
-
83
- before do
84
- # Respond with 400, If we don't get a http Host header,
85
- halt 400, "Unable to find HTTP Host header" if @env['HTTP_HOST'] == nil
86
- end
87
-
88
- after do
89
- headers 'CIMI-Specification-Version' => Deltacloud[:cimi].version
90
- end
91
-
92
- def self.new_route_for(route, &block)
93
- get route_for('/' + route.to_s + '/new') do
94
- instance_eval(&block) if block_given?
95
- respond_to do |format|
96
- format.html do
97
- haml :"#{route}/new"
98
- end
99
- end
100
- end
101
- end
102
-
103
- def self.check_capability(opts={})
104
- Sinatra::Rabbit.set :check_capability, opts[:for]
105
- end
106
-
107
- def self.check_features(opts={})
108
- Sinatra::Rabbit.set :check_features, opts[:for]
109
- end
110
-
111
- def self.route_for(url)
112
- "#{settings.root_url}#{url}"
113
- end
114
-
115
- end
116
- end
@@ -13,36 +13,38 @@
13
13
  # License for the specific language governing permissions and limitations
14
14
  # under the License.
15
15
 
16
- module CIMIHelper
16
+ module CIMI
17
+ module Helper
17
18
 
18
- def no_content_with_status(code=200)
19
- body ''
20
- status code
21
- end
19
+ def no_content_with_status(code=200)
20
+ body ''
21
+ status code
22
+ end
22
23
 
23
- def href_id(href, entity)
24
- split_on = self.send(:"#{entity.to_s}_url")
25
- href.split("#{split_on}/").last
26
- end
24
+ def href_id(href, entity)
25
+ split_on = self.send(:"#{entity.to_s}_url")
26
+ href.split("#{split_on}/").last
27
+ end
27
28
 
28
- def to_kibibyte(value, unit)
29
- case unit
29
+ def to_kibibyte(value, unit)
30
+ case unit
30
31
  when "GB"
31
32
  value*1024*1024
32
33
  when "MB"
33
34
  value*1024
34
35
  else
35
36
  nil # should probably be exploding something here...
37
+ end
36
38
  end
37
- end
38
39
 
40
+ end
39
41
  end
40
42
 
41
43
  class Array
42
44
  def to_xml_cimi_collection(_self)
43
45
  model_name = first.class.xml_tag_name
44
46
  XmlSimple.xml_out({
45
- "xmlns" => "http://www.dmtf.org/cimi",
47
+ "xmlns" => "http://schemas.dmtf.org/cimi/1",
46
48
  "uri" => [ _self.send(:"#{model_name.underscore.pluralize}_url") ],
47
49
  "name" => [ "default" ],
48
50
  "created" => [ Time.now.to_s ],
@@ -61,4 +63,3 @@ class Array
61
63
  end
62
64
 
63
65
  end
64
-
@@ -21,50 +21,34 @@ require 'require_relative' if RUBY_VERSION < '1.9'
21
21
 
22
22
  require_relative './models/schema'
23
23
  require_relative './models/base'
24
+ require_relative './models/collection'
24
25
  require_relative './models/errors'
25
- require_relative './models/entity_metadata'
26
- require_relative './models/entity_metadata_collection'
26
+ require_relative './models/action'
27
+ require_relative './models/disk'
28
+ require_relative './models/disk_collection'
29
+ require_relative './models/machine_volume'
30
+ require_relative './models/machine_volume_collection'
31
+
32
+ # Toplevel entities; order matters as it determines the order
33
+ # in which the entities appear in the CEP
27
34
  require_relative './models/cloud_entry_point'
35
+ require_relative './models/resource_metadata'
36
+ require_relative './models/machine'
28
37
  require_relative './models/machine_template'
29
- require_relative './models/machine_image'
30
38
  require_relative './models/machine_configuration'
31
- require_relative './models/action'
32
- require_relative './models/machine'
39
+ require_relative './models/machine_image'
40
+ require_relative './models/credential'
33
41
  require_relative './models/volume'
34
- require_relative './models/machine_admin'
42
+ require_relative './models/volume_template'
35
43
  require_relative './models/volume_configuration'
36
44
  require_relative './models/volume_image'
37
- require_relative './models/volume_template'
38
- require_relative './models/machine_template_collection'
39
- require_relative './models/machine_image_collection'
40
- require_relative './models/machine_configuration_collection'
41
- require_relative './models/machine_collection'
42
- require_relative './models/volume_collection'
43
- require_relative './models/machine_admin_collection'
44
- require_relative './models/volume_configuration_collection'
45
- require_relative './models/volume_image_collection'
46
- require_relative './models/volume_template_collection'
47
45
  require_relative './models/network'
48
- require_relative './models/network_collection'
49
- require_relative './models/network_configuration'
50
- require_relative './models/network_configuration_collection'
51
46
  require_relative './models/network_template'
52
- require_relative './models/network_template_collection'
53
- require_relative './models/routing_group'
54
- require_relative './models/routing_group_collection'
55
- require_relative './models/routing_group_template'
56
- require_relative './models/routing_group_template_collection'
57
- require_relative './models/vsp'
58
- require_relative './models/vsp_collection'
59
- require_relative './models/vsp_configuration'
60
- require_relative './models/vsp_configuration_collection'
61
- require_relative './models/vsp_template'
62
- require_relative './models/vsp_template_collection'
47
+ require_relative './models/network_configuration'
48
+ require_relative './models/network_port'
49
+ require_relative './models/network_port_template'
50
+ require_relative './models/network_port_configuration'
63
51
  require_relative './models/address'
64
- require_relative './models/address_collection'
65
52
  require_relative './models/address_template'
66
- require_relative './models/address_template_collection'
67
- require_relative './models/disk'
68
- require_relative './models/disk_collection'
69
- require_relative './models/machine_volume'
70
- require_relative './models/machine_volume_collection'
53
+ require_relative './models/forwarding_group'
54
+ require_relative './models/forwarding_group_template'
@@ -15,6 +15,8 @@
15
15
 
16
16
  class CIMI::Model::Address < CIMI::Model::Base
17
17
 
18
+ acts_as_root_entity
19
+
18
20
  text :ip
19
21
 
20
22
  text :hostname
@@ -25,8 +27,6 @@ class CIMI::Model::Address < CIMI::Model::Base
25
27
 
26
28
  text :dns
27
29
 
28
- text :mac_address
29
-
30
30
  text :protocol
31
31
 
32
32
  text :mask
@@ -41,9 +41,11 @@ class CIMI::Model::Address < CIMI::Model::Base
41
41
 
42
42
  def self.find(id, context)
43
43
  if id==:all
44
- context.driver.addresses(context.credentials, {:env=>context})
44
+ addresses = context.driver.addresses(context.credentials)
45
+ addresses.map{|addr| from_address(addr, context)}
45
46
  else
46
- context.driver.addresses(context.credentials, {:id=>id, :env=>context})
47
+ address = context.driver.address(context.credentials, {:id=>id})
48
+ from_address(address, context)
47
49
  end
48
50
  end
49
51
 
@@ -69,4 +71,30 @@ class CIMI::Model::Address < CIMI::Model::Base
69
71
  context.driver.delete_address(context.credentials, id)
70
72
  end
71
73
 
74
+ private
75
+
76
+ def self.from_address(address, context)
77
+ self.new(
78
+ :name => address.id,
79
+ :id => context.address_url(address.id),
80
+ :description => "Address #{address.id}",
81
+ :ip => address.id,
82
+ :allocation => "dynamic", #or "static"
83
+ :default_gateway => "unkown", #wtf
84
+ :dns => "unknown", #wtf
85
+ :protocol => protocol_from_address(address.id),
86
+ :mask => "unknown",
87
+ :resource => (address.instance_id) ? {:href=> context.machine_url(address.instance_id)} : nil,
88
+ :network => nil #unknown
89
+ #optional:
90
+ #:hostname =>
91
+ #:
92
+ )
93
+ end
94
+
95
+ def self.protocol_from_address(address)
96
+ addr = IPAddr.new(address)
97
+ addr.ipv4? ? "ipv4" : "ipv6"
98
+ end
99
+
72
100
  end
@@ -15,6 +15,8 @@
15
15
 
16
16
  class CIMI::Model::AddressTemplate < CIMI::Model::Base
17
17
 
18
+ acts_as_root_entity
19
+
18
20
  text :ip
19
21
 
20
22
  text :hostname
@@ -25,8 +27,6 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
25
27
 
26
28
  text :dns
27
29
 
28
- text :mac_address
29
-
30
30
  text :protocol
31
31
 
32
32
  text :mask
@@ -69,11 +69,16 @@ require 'json'
69
69
 
70
70
  module CIMI::Model
71
71
 
72
- def self.register_as_root_entity!(name)
72
+ def self.register_as_root_entity!(klass, opts = {})
73
73
  @root_entities ||= []
74
- @root_entities << name
74
+ @root_entities << klass
75
+ name = klass.name.split("::").last.pluralize
75
76
  unless CIMI::Model::CloudEntryPoint.href_defined?(name)
76
- CIMI::Model::CloudEntryPoint.send(:href, name.underscore)
77
+ params = {}
78
+ if opts[:as]
79
+ params[:xml_name] = params[:json_name] = opts[:as]
80
+ end
81
+ CIMI::Model::CloudEntryPoint.send(:href, name.underscore, params)
77
82
  end
78
83
  end
79
84
 
@@ -94,6 +99,20 @@ class CIMI::Model::Base
94
99
  # attribute, we also define a getter and a setter to access/change the
95
100
  # value for that attribute
96
101
  class << self
102
+
103
+ def <<(model)
104
+ clone_base_schema unless base_schema_cloned?
105
+ member_name = model.name.split("::").last
106
+ if ::Struct.const_defined?("CIMI_#{member_name}")
107
+ puts "Removing struct"
108
+ ::Struct.send(:remove_const, "CIMI_#{member_name}")
109
+ end
110
+ member_symbol = member_name.underscore.pluralize.to_sym
111
+ members = CIMI::Model::Schema::Array.new(member_symbol)
112
+ members.struct.schema.attributes = model.schema.attributes
113
+ base_schema.attributes << members
114
+ end
115
+
97
116
  def base_schema
98
117
  @schema ||= CIMI::Model::Schema.new
99
118
  end
@@ -192,7 +211,7 @@ class CIMI::Model::Base
192
211
 
193
212
  def self.to_xml(model)
194
213
  xml = @schema.to_xml(model)
195
- xml["xmlns"] = "http://www.dmtf.org/cimi"
214
+ xml["xmlns"] = "http://schemas.dmtf.org/cimi/1"
196
215
  XmlSimple.xml_out(xml, :root_name => xml_tag_name)
197
216
  end
198
217
 
@@ -211,7 +230,7 @@ class CIMI::Model::Base
211
230
 
212
231
  hash :property
213
232
 
214
- def self.act_as_root_entity(name=nil)
233
+ def self.acts_as_root_entity(name=nil)
215
234
  if name
216
235
  name = name.to_s.camelize.pluralize
217
236
  else
@@ -17,18 +17,13 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
17
17
 
18
18
  text :base_uri, :xml_name => "baseURI", :json_name => "baseURI"
19
19
 
20
- array :entity_metadata do
21
- scalar :href
22
- end
23
-
24
20
  def self.create(context)
25
21
  self.new(entities(context).merge({
26
22
  :name => context.driver.name,
27
23
  :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
28
24
  :id => context.cloudEntryPoint_url,
29
- :base_uri => context.root_url,
30
- :created => Time.now,
31
- :entity_metadata => CIMI::Model::EntityMetadata.all_uri(context)
25
+ :base_uri => context.base_uri,
26
+ :created => Time.now
32
27
  }))
33
28
  end
34
29
 
@@ -46,8 +41,8 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
46
41
 
47
42
  private
48
43
 
49
- def self.href_defined?(entity)
50
- true if schema.attribute_names.include? entity.underscore
44
+ def self.href_defined?(resource)
45
+ true if schema.attribute_names.include? resource.underscore
51
46
  end
52
47
 
53
48
  end