deltacloud-core 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/Rakefile +40 -28
  2. data/bin/deltacloud-db-upgrade +24 -0
  3. data/bin/deltacloudd +20 -9
  4. data/config.ru +12 -53
  5. data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
  6. data/deltacloud-core.gemspec +11 -5
  7. data/lib/cimi/collections.rb +4 -31
  8. data/lib/cimi/collections/address_templates.rb +2 -5
  9. data/lib/cimi/collections/addresses.rb +2 -5
  10. data/lib/cimi/collections/base.rb +18 -6
  11. data/lib/cimi/collections/credentials.rb +2 -5
  12. data/lib/cimi/collections/machine_images.rb +2 -1
  13. data/lib/cimi/collections/machine_templates.rb +2 -5
  14. data/lib/cimi/collections/machines.rb +6 -9
  15. data/lib/cimi/collections/network_ports.rb +3 -3
  16. data/lib/cimi/collections/networks.rb +5 -8
  17. data/lib/cimi/collections/system_templates.rb +72 -0
  18. data/lib/cimi/collections/systems.rb +194 -0
  19. data/lib/cimi/collections/volume_configurations.rb +1 -1
  20. data/lib/cimi/collections/volume_images.rb +2 -1
  21. data/lib/cimi/collections/volume_templates.rb +3 -2
  22. data/lib/cimi/collections/volumes.rb +2 -2
  23. data/lib/cimi/dependencies.rb +0 -2
  24. data/lib/cimi/helpers/cimi_helper.rb +12 -57
  25. data/lib/cimi/helpers/database_helper.rb +0 -4
  26. data/lib/cimi/models.rb +25 -14
  27. data/lib/cimi/models/address.rb +4 -31
  28. data/lib/cimi/models/address_create.rb +51 -0
  29. data/lib/cimi/models/address_template.rb +8 -52
  30. data/lib/cimi/models/address_template_create.rb +44 -0
  31. data/lib/cimi/models/base.rb +44 -6
  32. data/lib/cimi/models/cloud_entry_point.rb +1 -1
  33. data/lib/cimi/models/credential.rb +1 -1
  34. data/lib/cimi/models/credential_create.rb +46 -0
  35. data/lib/cimi/models/credential_template.rb +24 -0
  36. data/lib/cimi/models/machine.rb +1 -71
  37. data/lib/cimi/models/machine_configuration.rb +3 -3
  38. data/lib/cimi/models/machine_create.rb +49 -0
  39. data/lib/cimi/models/machine_image.rb +2 -25
  40. data/lib/cimi/models/machine_image_create.rb +41 -0
  41. data/lib/cimi/models/machine_template.rb +14 -34
  42. data/lib/cimi/models/machine_template_create.rb +33 -0
  43. data/lib/cimi/models/network.rb +0 -38
  44. data/lib/cimi/models/network_create.rb +43 -0
  45. data/lib/cimi/models/network_port.rb +17 -17
  46. data/lib/cimi/models/network_template.rb +2 -3
  47. data/lib/cimi/models/resource.rb +22 -3
  48. data/lib/cimi/models/schema.rb +94 -8
  49. data/lib/cimi/models/system.rb +67 -0
  50. data/lib/cimi/models/system_template.rb +63 -0
  51. data/lib/cimi/models/volume.rb +2 -42
  52. data/lib/cimi/models/volume_configuration.rb +4 -4
  53. data/lib/cimi/models/volume_create.rb +58 -0
  54. data/lib/cimi/models/volume_image.rb +8 -17
  55. data/lib/cimi/models/volume_image_create.rb +47 -0
  56. data/lib/cimi/models/volume_template.rb +6 -19
  57. data/lib/cimi/models/volume_template_create.rb +33 -0
  58. data/lib/db.rb +14 -22
  59. data/lib/db/volume_template.rb +1 -1
  60. data/lib/deltacloud/api.rb +6 -5
  61. data/lib/deltacloud/collections.rb +4 -27
  62. data/lib/deltacloud/collections/base.rb +4 -0
  63. data/lib/deltacloud/collections/images.rb +1 -1
  64. data/lib/deltacloud/collections/instances.rb +2 -2
  65. data/lib/deltacloud/core_ext/array.rb +1 -0
  66. data/lib/deltacloud/core_ext/integer.rb +13 -9
  67. data/lib/deltacloud/core_ext/string.rb +45 -28
  68. data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
  69. data/lib/deltacloud/drivers/base_driver.rb +45 -16
  70. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
  71. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
  72. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
  73. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
  74. data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
  75. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
  76. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
  77. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
  78. data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
  79. data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
  80. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
  81. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
  82. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
  83. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
  84. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
  85. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
  86. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
  87. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
  88. data/lib/deltacloud/helpers/collection_helper.rb +106 -0
  89. data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
  90. data/lib/deltacloud/models/address.rb +19 -17
  91. data/lib/deltacloud/models/base_model.rb +29 -26
  92. data/lib/deltacloud/models/blob.rb +22 -20
  93. data/lib/deltacloud/models/bucket.rb +21 -16
  94. data/lib/deltacloud/models/firewall.rb +18 -16
  95. data/lib/deltacloud/models/firewall_rule.rb +22 -20
  96. data/lib/deltacloud/models/image.rb +29 -28
  97. data/lib/deltacloud/models/instance.rb +92 -94
  98. data/lib/deltacloud/models/instance_address.rb +42 -40
  99. data/lib/deltacloud/models/instance_profile.rb +28 -26
  100. data/lib/deltacloud/models/key.rb +47 -45
  101. data/lib/deltacloud/models/load_balancer.rb +32 -31
  102. data/lib/deltacloud/models/metric.rb +76 -29
  103. data/lib/deltacloud/models/provider.rb +15 -13
  104. data/lib/deltacloud/models/realm.rb +15 -21
  105. data/lib/deltacloud/models/storage_snapshot.rb +23 -19
  106. data/lib/deltacloud/models/storage_volume.rb +35 -34
  107. data/lib/deltacloud/version.rb +1 -1
  108. data/lib/deltacloud_rack.rb +22 -0
  109. data/lib/initialize.rb +28 -0
  110. data/lib/initializers/database_initialize.rb +76 -0
  111. data/lib/initializers/frontend_initialize.rb +42 -0
  112. data/lib/initializers/mock_initialize.rb +33 -0
  113. data/lib/sinatra/rack_logger.rb +35 -24
  114. data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
  115. data/tests/cimi/collections/machine_images_test.rb +2 -2
  116. data/tests/cimi/collections/machine_templates_test.rb +75 -0
  117. data/tests/cimi/collections/machines_test.rb +2 -2
  118. data/tests/cimi/collections/system_templates_test.rb +41 -0
  119. data/tests/cimi/collections/systems_test.rb +50 -0
  120. data/tests/cimi/db/database_helper_test.rb +17 -25
  121. data/tests/cimi/db/db_helper.rb +1 -12
  122. data/tests/cimi/db/entity_test.rb +7 -8
  123. data/tests/cimi/model/machine_create_spec.rb +44 -0
  124. data/tests/cimi/model/machine_template_spec.rb +29 -0
  125. data/tests/cimi/model/resource_spec.rb +40 -0
  126. data/tests/cimi/model/schema_spec.rb +37 -0
  127. data/tests/cimi/spec_helper.rb +3 -0
  128. data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
  129. data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
  130. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
  131. data/tests/deltacloud/collections/images_collection_test.rb +2 -2
  132. data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
  133. data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
  134. data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
  135. data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
  136. data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
  137. data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
  138. data/tests/deltacloud/collections_test.rb +5 -5
  139. data/tests/deltacloud/common.rb +2 -13
  140. data/tests/deltacloud/launcher_test.rb +3 -3
  141. data/tests/deltacloud/rack_test.rb +2 -2
  142. data/tests/deltacloud/server_test.rb +1 -1
  143. data/tests/drivers/base/base_driver_test.rb +5 -5
  144. data/tests/drivers/base/common.rb +2 -12
  145. data/tests/drivers/ec2/buckets_test.rb +1 -1
  146. data/tests/drivers/ec2/images_test.rb +2 -2
  147. data/tests/drivers/ec2/instance_test.rb +6 -6
  148. data/tests/drivers/ec2/keys_test.rb +3 -3
  149. data/tests/drivers/ec2/realms_test.rb +2 -2
  150. data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
  151. data/tests/drivers/fgcp/common.rb +32 -0
  152. data/tests/drivers/fgcp/firewall_test.rb +70 -0
  153. data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
  154. data/tests/drivers/fgcp/images_test.rb +46 -0
  155. data/tests/drivers/fgcp/provider_test.rb +27 -0
  156. data/tests/drivers/fgcp/realms_test.rb +53 -0
  157. data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
  158. data/tests/drivers/gogrid/images_test.rb +2 -2
  159. data/tests/drivers/gogrid/instances_test.rb +2 -2
  160. data/tests/drivers/gogrid/realms_test.rb +2 -2
  161. data/tests/drivers/mock/images_test.rb +4 -4
  162. data/tests/drivers/mock/instances_test.rb +9 -9
  163. data/tests/drivers/mock/keys_test.rb +3 -3
  164. data/tests/drivers/mock/realms_test.rb +2 -2
  165. data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
  166. data/tests/drivers/mock/storage_volumes_test.rb +4 -4
  167. data/tests/drivers/models/instance_test.rb +2 -2
  168. data/tests/drivers/openstack/images_test.rb +2 -2
  169. data/tests/drivers/openstack/instances_test.rb +2 -3
  170. data/tests/drivers/openstack/keys_test.rb +1 -1
  171. data/tests/drivers/openstack/realms_test.rb +2 -11
  172. data/tests/drivers/rhevm/common.rb +33 -12
  173. data/tests/drivers/rhevm/images_test.rb +20 -12
  174. data/tests/drivers/rhevm/instance_test.rb +62 -46
  175. data/tests/drivers/rhevm/provider_test.rb +12 -6
  176. data/tests/drivers/rhevm/realms_test.rb +15 -9
  177. data/tests/ec2/query_parser_test.rb +1 -1
  178. data/tests/test_helper.rb +68 -12
  179. data/views/addresses/show.html.haml +1 -1
  180. data/views/buckets/show.html.haml +1 -1
  181. data/views/errors/{500.html.haml → common.html.haml} +0 -0
  182. data/views/errors/common.xml.haml +17 -0
  183. data/views/firewalls/index.xml.haml +2 -2
  184. data/views/firewalls/new.html.haml +2 -2
  185. data/views/images/show.html.haml +1 -1
  186. data/views/instances/run_command.html.haml +1 -1
  187. data/views/instances/show.html.haml +3 -3
  188. data/views/keys/index.html.haml +1 -0
  189. data/views/keys/show.html.haml +8 -4
  190. data/views/keys/show.xml.haml +3 -2
  191. data/views/load_balancers/new.html.haml +1 -1
  192. data/views/load_balancers/show.html.haml +2 -2
  193. data/views/metrics/show.html.haml +1 -1
  194. data/views/realms/index.html.haml +0 -2
  195. data/views/realms/show.html.haml +0 -4
  196. data/views/realms/show.xml.haml +0 -3
  197. data/views/storage_snapshots/index.html.haml +1 -1
  198. data/views/storage_snapshots/new.html.haml +1 -1
  199. data/views/storage_volumes/new.html.haml +2 -2
  200. data/views/storage_volumes/show.html.haml +3 -3
  201. metadata +90 -41
  202. data/views/errors/400.html.haml +0 -41
  203. data/views/errors/400.xml.haml +0 -3
  204. data/views/errors/401.html.haml +0 -26
  205. data/views/errors/401.xml.haml +0 -3
  206. data/views/errors/403.html.haml +0 -42
  207. data/views/errors/403.xml.haml +0 -9
  208. data/views/errors/404.html.haml +0 -28
  209. data/views/errors/404.xml.haml +0 -3
  210. data/views/errors/405.html.haml +0 -29
  211. data/views/errors/405.xml.haml +0 -5
  212. data/views/errors/409.html.haml +0 -47
  213. data/views/errors/409.xml.haml +0 -11
  214. data/views/errors/500.xml.haml +0 -13
  215. data/views/errors/501.html.haml +0 -44
  216. data/views/errors/501.xml.haml +0 -1
  217. data/views/errors/502.html.haml +0 -44
  218. data/views/errors/502.xml.haml +0 -1
  219. data/views/errors/504.html.haml +0 -43
  220. data/views/errors/504.xml.haml +0 -1
@@ -49,8 +49,8 @@ module CIMI::Collections
49
49
  operation :create, :with_capability => :create_storage_volume do
50
50
  description "Create a new Volume."
51
51
  control do
52
- content_type = grab_content_type(request.content_type, request.body)
53
- new_volume = Volume.create(request.body.read, self, content_type)
52
+ vol = CIMI::Model::VolumeCreate.parse(request.body, request.content_type)
53
+ new_volume = vol.create(self)
54
54
  headers_for_create new_volume
55
55
  respond_to do |format|
56
56
  format.json { new_volume.to_json }
@@ -58,5 +58,3 @@ require 'sinatra/rack_date'
58
58
  require 'sinatra/rack_matrix_params'
59
59
  require 'sinatra/rack_syslog'
60
60
  require 'sinatra/sinatra_verbose'
61
-
62
- CMWG_NAMESPACE = "http://schemas.dmtf.org/cimi/1"
@@ -16,6 +16,18 @@
16
16
  module CIMI
17
17
  module Helper
18
18
 
19
+ def current_content_type
20
+ case request.content_type
21
+ when 'application/json' then :json
22
+ when 'text/xml', 'application/xml' then :xml
23
+ else
24
+ raise Deltacloud::Exceptions.exception_from_status(
25
+ 406,
26
+ translate_error_code(406)[:message]
27
+ )
28
+ end
29
+ end
30
+
19
31
  def expand?(collection)
20
32
  params['$expand'] == '*' ||
21
33
  (params['$expand'] || '').split(',').include?(collection.to_s)
@@ -59,39 +71,6 @@ module CIMI
59
71
  end
60
72
  end
61
73
 
62
- def grab_content_type(request_content_type, request_body)
63
- case request_content_type
64
- when /xml$/ then :xml
65
- when /json$/ then :json
66
- else raise CIMI::Model::UnsupportedMediaType.new("Unsupported content type - only xml and json supported by CIMI")
67
- #guess_content_type(request_body)
68
- end
69
- end
70
-
71
- #not being used - was called from above grab_content_type
72
- #decided to reject anything not xml || json
73
- def guess_content_type(request_body)
74
- xml = json = false
75
- body = request_body.read
76
- request_body.rewind
77
- begin
78
- XmlSimple.xml_in(body)
79
- xml = true
80
- rescue Exception
81
- xml = false
82
- end
83
- begin
84
- JSON.parse(body)
85
- json = true
86
- rescue Exception
87
- json = false
88
- end
89
- if (json == xml) #both true or both false
90
- raise CIMI::Model::BadRequest.new("Couldn't guess content type of: #{body}")
91
- end
92
- type = (xml)? :xml : :json
93
- end
94
-
95
74
  def deltacloud_create_method_for(cimi_entity)
96
75
  case cimi_entity
97
76
  when "machine" then "create_instance"
@@ -106,27 +85,3 @@ module CIMI
106
85
 
107
86
  end
108
87
  end
109
-
110
- class Array
111
- def to_xml_cimi_collection(_self)
112
- model_name = first.class.xml_tag_name
113
- XmlSimple.xml_out({
114
- "xmlns" => "http://schemas.dmtf.org/cimi/1",
115
- "uri" => [ _self.send(:"#{model_name.underscore.pluralize}_url") ],
116
- "name" => [ "default" ],
117
- "created" => [ Time.now.to_s ],
118
- model_name => map { |model| { 'href' => model.uri } }
119
- }, :root_name => "#{model_name}Collection")
120
- end
121
-
122
- def to_json_cimi_collection(_self)
123
- model_name = first.class.xml_tag_name
124
- {
125
- "uri" => _self.send(:"#{model_name.underscore.pluralize}_url"),
126
- "name" => "default",
127
- "created" => Time.now.to_s,
128
- model_name.pluralize.uncapitalize => map { |model| { 'href' => model.uri } }
129
- }.to_json
130
- end
131
-
132
- end
@@ -24,10 +24,6 @@ module Deltacloud
24
24
  DATABASE_COLLECTIONS = [ "machine_template", "address_template",
25
25
  "volume_configuration", "volume_template" ]
26
26
 
27
- def test_environment?
28
- Deltacloud.test_environment?
29
- end
30
-
31
27
  def provides?(entity)
32
28
  return true if DATABASE_COLLECTIONS.include? entity
33
29
  return false
@@ -36,17 +36,15 @@ module CIMI
36
36
  end
37
37
 
38
38
  require 'require_relative' if RUBY_VERSION < '1.9'
39
- require_relative '../db'
40
39
 
41
- unless Deltacloud.test_environment?
42
- Deltacloud::initialize_database
43
- require_relative './../db/provider'
44
- require_relative './../db/entity'
45
- require_relative './../db/machine_template'
46
- require_relative './../db/address_template'
47
- require_relative './../db/volume_configuration'
48
- require_relative './../db/volume_template'
49
- end
40
+ # Database entities
41
+ #
42
+ require_relative './../db/provider'
43
+ require_relative './../db/entity'
44
+ require_relative './../db/machine_template'
45
+ require_relative './../db/address_template'
46
+ require_relative './../db/volume_configuration'
47
+ require_relative './../db/volume_template'
50
48
 
51
49
  require_relative './models/schema'
52
50
  require_relative './models/resource'
@@ -62,22 +60,35 @@ require_relative './models/cloud_entry_point'
62
60
 
63
61
  CIMI::Model::ResourceMetadata.acts_as_root_entity
64
62
 
63
+ require_relative './models/credential'
64
+ require_relative './models/credential_template'
65
+ require_relative './models/credential_create'
65
66
  require_relative './models/volume'
66
- require_relative './models/volume_template'
67
67
  require_relative './models/volume_configuration'
68
68
  require_relative './models/volume_image'
69
+ require_relative './models/volume_template'
70
+ require_relative './models/volume_create'
71
+ require_relative './models/volume_image_create'
72
+ require_relative './models/volume_template_create'
69
73
  require_relative './models/machine'
70
- require_relative './models/machine_template'
71
74
  require_relative './models/machine_configuration'
72
75
  require_relative './models/machine_image'
73
- require_relative './models/credential'
76
+ require_relative './models/machine_image_create'
77
+ require_relative './models/machine_template'
78
+ require_relative './models/machine_template_create'
79
+ require_relative './models/machine_create'
74
80
  require_relative './models/network_port'
75
81
  require_relative './models/network'
76
- require_relative './models/network_template'
77
82
  require_relative './models/network_configuration'
78
83
  require_relative './models/network_port_template'
79
84
  require_relative './models/network_port_configuration'
80
85
  require_relative './models/address'
81
86
  require_relative './models/address_template'
87
+ require_relative './models/address_template_create'
88
+ require_relative './models/address_create'
82
89
  require_relative './models/forwarding_group'
83
90
  require_relative './models/forwarding_group_template'
91
+ require_relative './models/system_template'
92
+ require_relative './models/system'
93
+ require_relative './models/network_template'
94
+ require_relative './models/network_create'
@@ -49,30 +49,6 @@ class CIMI::Model::Address < CIMI::Model::Base
49
49
  end
50
50
  end
51
51
 
52
- def self.create(request_body, context, type)
53
- input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false, "NormaliseSpace"=>2}) : JSON.parse(request_body)
54
- if input['addressTemplate'] and input["addressTemplate"]["href"] #by reference
55
- address_template = CIMI::Model::AddressTemplate.find(context.href_id(input["addressTemplate"]["href"], :address_templates), context)
56
- else
57
- case type
58
- when :json
59
- address_template = CIMI::Model::AddressTemplate.from_json(JSON.generate(input["addressTemplate"]))
60
- when :xml
61
- xml = XmlSimple.xml_in(request_body, {"NormaliseSpace"=>2})
62
- address_template = CIMI::Model::AddressTemplate.from_xml(XmlSimple.xml_out(xml["addressTemplate"][0]))
63
- end
64
- end
65
- params = {:name=>input["name"], :description=>input["description"], :address_template=>address_template, :env=>context }
66
- raise CIMI::Model::BadRequest.new("Bad request - missing required parameters. Client sent: #{request_body} which produced #{params.inspect}") if params.has_value?(nil)
67
- address = context.driver.create_address(context.credentials, params)
68
- result = from_address(address, context)
69
- result.name = input['name'] if input['name']
70
- result.description = input['description'] if input['description']
71
- result.extract_properties!(input)
72
- result.save
73
- result
74
- end
75
-
76
52
  def self.delete!(id, context)
77
53
  context.driver.delete_address(context.credentials, id)
78
54
  new(:id => id).destroy
@@ -86,16 +62,13 @@ class CIMI::Model::Address < CIMI::Model::Base
86
62
  :id => context.address_url(address.id),
87
63
  :description => "Address #{address.id}",
88
64
  :ip => address.id,
89
- :allocation => "dynamic", #or "static"
90
- :default_gateway => "unknown", #wtf
91
- :dns => "unknown", #wtf
65
+ :allocation => "dynamic",
66
+ :default_gateway => "unknown",
67
+ :dns => "unknown",
92
68
  :protocol => protocol_from_address(address.id),
93
69
  :mask => "unknown",
94
70
  :resource => (address.instance_id) ? {:href=> context.machine_url(address.instance_id)} : nil,
95
- :network => nil #unknown
96
- #optional:
97
- #:hostname =>
98
- #:
71
+ :network => nil
99
72
  )
100
73
  end
101
74
 
@@ -0,0 +1,51 @@
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::AddressCreate < CIMI::Model::Base
17
+
18
+ ref :address_template, :required => true
19
+
20
+ def create(context)
21
+ validate!
22
+
23
+ if address_template.href?
24
+ template = address_template.find(context)
25
+ end
26
+
27
+ params = {
28
+ :name => name,
29
+ :description => description,
30
+ :address_template => template,
31
+ :env => context # FIXME: We should not pass the context to the driver (!)
32
+ }
33
+
34
+ unless context.driver.respond_to? :create_address
35
+ raise Deltacloud::Exceptions.exception_from_status(
36
+ 501,
37
+ "Creating Address is not supported by the current driver"
38
+ )
39
+ end
40
+
41
+ address = context.driver.create_address(context.credentials, params)
42
+
43
+ result = CIMI::Model::Address.from_address(address, context)
44
+ result.name = name if name
45
+ result.description = description if description
46
+ result.property = property if property
47
+ result.save
48
+ result
49
+ end
50
+
51
+ end
@@ -17,20 +17,8 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
17
17
 
18
18
  acts_as_root_entity
19
19
 
20
- text :ip
21
-
22
- text :hostname
23
-
24
- text :allocation
25
-
26
- text :default_gateway
27
-
28
- text :dns
29
-
30
- text :protocol
31
-
32
- text :mask
33
-
20
+ text :ip, :required => true
21
+ text :hostname, :allocation, :default_gateway, :dns, :protocol, :mask
34
22
  href :network
35
23
 
36
24
  array :operations do
@@ -45,8 +33,8 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
45
33
  current_db.address_templates.map { |t| from_db(t, context) }
46
34
  end
47
35
  else
48
- if context.driver.respond_to? :address_template
49
- context.driver.address_template(context.credentials, id, :env=>context)
36
+ if context.driver.respond_to? :address_templates
37
+ context.driver.address_templates(context.credentials, {:id=>id, :env=>context})
50
38
  else
51
39
  template = current_db.address_templates_dataset.first(:id => id)
52
40
  raise CIMI::Model::NotFound unless template
@@ -55,41 +43,6 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
55
43
  end
56
44
  end
57
45
 
58
- def self.create_from_json(body, context)
59
- json = JSON.parse(body)
60
- new_template = current_db.add_address_template(
61
- :name => json['name'],
62
- :description => json['description'],
63
- :hostname => json['hostname'],
64
- :ip => json['ip'],
65
- :allocation => json['allocation'],
66
- :default_gateway => json['default_gateway'],
67
- :dns => json['dns'],
68
- :protocol => json['protocol'],
69
- :mask => json['mask'],
70
- :ent_properties => json['properties'] ? json['properties'].to_json : {}
71
- )
72
- from_db(new_template, context)
73
- end
74
-
75
- def self.create_from_xml(body, context)
76
- xml = XmlSimple.xml_in(body)
77
- xml['property'] ||= []
78
- new_template = current_db.add_address_template(
79
- :name => xml['name'].first,
80
- :description => xml['description'].first,
81
- :ip => xml['ip'].first,
82
- :hostname => xml['hostname'].first,
83
- :allocation => xml['allocation'].first,
84
- :default_gateway => xml['default_gateway'].first,
85
- :dns => xml['dns'].first,
86
- :protocol => xml['protocol'].nil? ? nil : xml['protocol'].first,
87
- :mask => xml['mask'].first,
88
- :ent_properties => xml['property'] ? JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
89
- )
90
- from_db(new_template, context)
91
- end
92
-
93
46
  def self.delete!(id, context)
94
47
  current_db.address_templates.first(:id => id).destroy
95
48
  end
@@ -110,7 +63,10 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
110
63
  :mask => model.mask,
111
64
  :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
112
65
  :operations => [
113
- { :href => context.destroy_address_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
66
+ {
67
+ :href => context.destroy_address_template_url(model.id),
68
+ :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
69
+ }
114
70
  ]
115
71
  )
116
72
  end
@@ -0,0 +1,44 @@
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::AddressTemplateCreate < CIMI::Model::Base
17
+
18
+ text :ip, :required => true
19
+ text :hostname, :required => true
20
+ text :allocation, :required => true
21
+ text :default_gateway, :required => true
22
+ text :dns, :required => true
23
+ text :protocol, :required => true
24
+ text :mask, :required => true
25
+
26
+ href :network
27
+
28
+ def create(context)
29
+ validate!
30
+ new_template = context.current_db.add_address_template(
31
+ :name => name,
32
+ :description => description,
33
+ :hostname => hostname,
34
+ :ip => ip,
35
+ :allocation => allocation,
36
+ :default_gateway => default_gateway,
37
+ :dns => dns,
38
+ :protocol => protocol,
39
+ :mask => mask,
40
+ :ent_properties => property.to_json
41
+ )
42
+ CIMI::Model::AddressTemplate.from_db(new_template, context)
43
+ end
44
+ end
@@ -28,12 +28,22 @@ require_relative '../helpers/database_helper'
28
28
  #
29
29
  # class Machine < CIMI::Model::Base
30
30
  # text :status
31
- # href :meter
31
+ # collection :meters
32
32
  # array :volumes do
33
- # scalar :href, :attachment_point, :protocol
33
+ # scalar :href, :initial_location
34
34
  # end
35
+ # ref :latest_snapshot, CIMI::Model::MachineImage
35
36
  # end
36
37
  #
38
+ # class SystemTemplate < CIMI::Model::Base
39
+ # array component_descriptors do
40
+ # text :name
41
+ # ...
42
+ # end
43
+ # array :meter_templates, :ref => CIMI::Model::MeterTemplate
44
+ # end
45
+ #
46
+ #
37
47
  # The DSL automatically takes care of converting identifiers from their
38
48
  # underscored form to the camel-cased form used by CIMI. The above class
39
49
  # can be used in the following way:
@@ -42,7 +52,7 @@ require_relative '../helpers/database_helper'
42
52
  # if machine.status == "UP"
43
53
  # ...
44
54
  # end
45
- # sda = machine.volumes.find { |v| v.attachment_point == "/dev/sda" }
55
+ # sda = machine.volumes.find { |v| v.initial_location == "/dev/sda" }
46
56
  # handle_meter(machine.meter.href)
47
57
  #
48
58
  # The keywords for the DSL are
@@ -60,19 +70,43 @@ require_relative '../helpers/database_helper'
60
70
  # A shorthand for +struct name { scalar :href }+; in JSON, this is
61
71
  # represented as +{ name: { "href": string } }+, and in XML as +<name
62
72
  # href="..."/>+
73
+ # [ref(name, [klass])]
74
+ # A reference to another object, like the reference to the
75
+ # MachineConfiguration in a MachineTemplate. If +klass+ is not given,
76
+ # an attempt is made to infer the class of the target of the reference
77
+ # from +name+
63
78
  # [struct(name, opts, &block)]
64
79
  # A structured subobject; the block defines the schema of the
65
80
  # subobject. The +:content+ option can be used to specify the attribute
66
81
  # that should receive the content of the corresponding XML element
67
- # [array(name, opts, &block)]
68
- # An array of structured subobjects; the block defines the schema of
69
- # the subobjects.
82
+ # [array(name, opts, &block)] An array of structured subobjects; the
83
+ # block defines the schema of the subobjects. If the entries are
84
+ # references to other resources, instead of passing a block, pass the
85
+ # class of the target of the references with the +:ref+ option
70
86
  # [collection(name, opts)]
71
87
  # A collection of associated objects; use the +:class+ option to
72
88
  # specify the type of the collection entries
73
89
 
74
90
  module CIMI::Model
75
91
 
92
+ class ValidationError < StandardError
93
+
94
+ def initialize(attr_list, format)
95
+ @lst = attr_list
96
+ super("Required attributes not set: #{name}")
97
+ end
98
+
99
+ # Report the ValidationError as HTTP 400 - Bad Request
100
+ def code
101
+ 400
102
+ end
103
+
104
+ def name
105
+ @lst.join(',')
106
+ end
107
+
108
+ end
109
+
76
110
  class Base < Resource
77
111
 
78
112
  # Extend the base model with database methods
@@ -135,6 +169,10 @@ module CIMI::Model
135
169
  property.merge!(h)
136
170
  end
137
171
 
172
+ def ref_id(ref_url)
173
+ ref_url.split('/').last if ref_url
174
+ end
175
+
138
176
  private
139
177
 
140
178
  # Load an existing database entity for this object, or create a new one