deltacloud-core 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +10 -2
- data/bin/deltacloudd +10 -10
- data/config.ru +2 -1
- data/config/drivers/digitalocean.yaml +3 -0
- data/deltacloud-core.gemspec +13 -6
- data/lib/cimi/collections.rb +1 -1
- data/lib/cimi/collections/address_templates.rb +27 -3
- data/lib/cimi/collections/addresses.rb +1 -1
- data/lib/cimi/collections/base.rb +1 -0
- data/lib/cimi/collections/cloud_entry_point.rb +4 -0
- data/lib/cimi/collections/credentials.rb +2 -2
- data/lib/cimi/collections/machine_images.rb +20 -0
- data/lib/cimi/collections/machine_templates.rb +72 -0
- data/lib/cimi/collections/machines.rb +50 -41
- data/lib/cimi/collections/network_ports.rb +3 -3
- data/lib/cimi/collections/networks.rb +4 -4
- data/lib/cimi/collections/resource_metadata.rb +1 -1
- data/lib/cimi/collections/volume_configurations.rb +25 -0
- data/lib/cimi/collections/volume_images.rb +21 -1
- data/lib/cimi/collections/volume_templates.rb +69 -0
- data/lib/cimi/collections/volumes.rb +5 -10
- data/lib/cimi/dependencies.rb +0 -1
- data/lib/cimi/helpers.rb +4 -1
- data/lib/cimi/helpers/cimi_helper.rb +62 -0
- data/lib/cimi/helpers/database_helper.rb +95 -0
- data/lib/cimi/models.rb +15 -1
- data/lib/cimi/models/address.rb +10 -5
- data/lib/cimi/models/address_template.rb +67 -3
- data/lib/cimi/models/base.rb +8 -5
- data/lib/cimi/models/cloud_entry_point.rb +6 -1
- data/lib/cimi/models/collection.rb +9 -4
- data/lib/cimi/models/disk.rb +6 -1
- data/lib/cimi/models/errors.rb +8 -0
- data/lib/cimi/models/machine.rb +68 -42
- data/lib/cimi/models/machine_configuration.rb +2 -2
- data/lib/cimi/models/machine_image.rb +41 -6
- data/lib/cimi/models/machine_template.rb +58 -0
- data/lib/cimi/models/machine_volume.rb +51 -3
- data/lib/cimi/models/resource_metadata.rb +88 -25
- data/lib/cimi/models/schema.rb +19 -5
- data/lib/cimi/models/volume.rb +66 -30
- data/lib/cimi/models/volume_configuration.rb +53 -21
- data/lib/cimi/models/volume_image.rb +24 -9
- data/lib/cimi/models/volume_template.rb +61 -0
- data/lib/cimi/server.rb +0 -6
- data/lib/db.rb +82 -0
- data/lib/db/address_template.rb +15 -0
- data/lib/db/entity.rb +22 -0
- data/lib/db/machine_template.rb +10 -0
- data/lib/db/provider.rb +13 -0
- data/lib/db/volume_configuration.rb +10 -0
- data/lib/db/volume_template.rb +10 -0
- data/lib/deltacloud/collections/addresses.rb +1 -1
- data/lib/deltacloud/collections/base.rb +12 -1
- data/lib/deltacloud/collections/buckets.rb +41 -8
- data/lib/deltacloud/collections/drivers.rb +1 -1
- data/lib/deltacloud/collections/firewalls.rb +2 -2
- data/lib/deltacloud/collections/images.rb +1 -1
- data/lib/deltacloud/collections/instances.rb +7 -1
- data/lib/deltacloud/collections/keys.rb +1 -1
- data/lib/deltacloud/collections/load_balancers.rb +4 -4
- data/lib/deltacloud/collections/storage_snapshots.rb +5 -1
- data/lib/deltacloud/collections/storage_volumes.rb +7 -3
- data/lib/deltacloud/drivers/base_driver.rb +10 -9
- data/lib/deltacloud/drivers/cimi_features.rb +42 -0
- data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +307 -0
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +40 -14
- data/lib/deltacloud/drivers/exceptions.rb +8 -0
- data/lib/deltacloud/drivers/features.rb +19 -2
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +11 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +83 -11
- data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +1 -1
- data/lib/deltacloud/drivers/mock/mock_client.rb +2 -4
- data/lib/deltacloud/drivers/mock/mock_driver.rb +29 -0
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +153 -36
- data/lib/deltacloud/drivers/rackspace/anti_cache_monkey_patch.rb +20 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +1 -0
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +30 -12
- data/lib/deltacloud/drivers/sbc/sbc_client.rb +0 -1
- data/lib/deltacloud/drivers/sbc/sbc_driver.rb +5 -1
- data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +1 -1
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +19 -9
- data/lib/deltacloud/helpers/blob_stream_helper.rb +42 -3
- data/lib/deltacloud/helpers/deltacloud_helper.rb +31 -14
- data/lib/deltacloud/models/address.rb +9 -0
- data/lib/deltacloud/models/base_model.rb +4 -0
- data/lib/deltacloud/models/blob.rb +12 -0
- data/lib/deltacloud/models/bucket.rb +9 -0
- data/lib/deltacloud/models/firewall.rb +13 -1
- data/lib/deltacloud/models/firewall_rule.rb +14 -0
- data/lib/deltacloud/models/hardware_profile.rb +14 -0
- data/lib/deltacloud/models/image.rb +15 -0
- data/lib/deltacloud/models/instance.rb +40 -1
- data/lib/deltacloud/models/instance_address.rb +9 -0
- data/lib/deltacloud/models/key.rb +15 -0
- data/lib/deltacloud/models/load_balancer.rb +20 -0
- data/lib/deltacloud/models/metric.rb +15 -0
- data/lib/deltacloud/models/provider.rb +8 -0
- data/lib/deltacloud/models/realm.rb +9 -0
- data/lib/deltacloud/models/state_machine.rb +8 -0
- data/lib/deltacloud/models/storage_snapshot.rb +11 -0
- data/lib/deltacloud/models/storage_volume.rb +24 -0
- data/lib/deltacloud/server.rb +1 -3
- data/lib/deltacloud/version.rb +2 -1
- data/lib/deltacloud_rack.rb +1 -1
- data/tests/cimi/db/database_helper_test.rb +190 -0
- data/tests/cimi/db/db_helper.rb +30 -0
- data/tests/cimi/db/schema_test.rb +94 -0
- data/tests/cimi/model/collection_spec.rb +0 -1
- data/tests/cimi/model/machine_spec.rb +17 -0
- data/tests/cimi/spec_helper.rb +3 -2
- data/tests/deltacloud/collections/buckets_collection_test.rb +3 -0
- data/tests/deltacloud/collections/drivers_collection_test.rb +10 -0
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +4 -0
- data/tests/deltacloud/collections/images_collection_test.rb +4 -0
- data/tests/deltacloud/collections/instances_collection_test.rb +14 -1
- data/tests/deltacloud/collections/keys_collection_test.rb +4 -0
- data/tests/deltacloud/collections/realms_collection_test.rb +47 -0
- data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +47 -0
- data/tests/deltacloud/collections/storage_volumes_collection_test.rb +47 -0
- data/tests/deltacloud/common.rb +15 -0
- data/tests/deltacloud/deltacloud_helper_test.rb +0 -4
- data/tests/deltacloud/launcher_test.rb +108 -0
- data/tests/drivers/ec2/buckets_test.rb +2 -1
- data/tests/drivers/mock/buckets_test.rb +27 -0
- data/tests/drivers/mock/instances_test.rb +6 -0
- data/tests/drivers/openstack/common.rb +1 -1
- data/tests/drivers/openstack/hardware_profiles_test.rb +2 -1
- data/tests/drivers/openstack/instances_test.rb +18 -17
- data/tests/drivers/rhevm/common.rb +1 -0
- data/tests/drivers/rhevm/images_test.rb +1 -1
- data/tests/drivers/rhevm/instance_test.rb +7 -7
- data/tests/helpers/rack/rack_matrix_params_test.rb +0 -2
- data/tests/test_helper.rb +2 -1
- data/views/errors/403.xml.haml +6 -0
- data/views/errors/409.html.haml +47 -0
- data/views/errors/409.xml.haml +11 -0
- data/views/errors/502.html.haml +6 -5
- data/views/images/show.xml.haml +3 -2
- data/views/instances/new.html.haml +1 -1
- metadata +77 -30
@@ -47,7 +47,7 @@ module CIMI::Collections
|
|
47
47
|
operation :create, :with_capability => :create_network_port do
|
48
48
|
description "Create a new NetworkPort"
|
49
49
|
control do
|
50
|
-
if request.content_type.
|
50
|
+
if grab_content_type(request.content_type, request.body) == :json
|
51
51
|
network_port = CIMI::Model::NetworkPort.create(request.body.read, self, :json)
|
52
52
|
else
|
53
53
|
network_port = CIMI::Model::NetworkPort.create(request.body.read, self, :xml)
|
@@ -73,7 +73,7 @@ module CIMI::Collections
|
|
73
73
|
control do
|
74
74
|
network_port = NetworkPort.find(params[:id], self)
|
75
75
|
report_error(404) unless network_port
|
76
|
-
if request.content_type.
|
76
|
+
if grab_content_type(request.content_type, request.body) == :json
|
77
77
|
action = Action.from_json(request.body.read)
|
78
78
|
else
|
79
79
|
action = Action.from_xml(request.body.read)
|
@@ -91,7 +91,7 @@ module CIMI::Collections
|
|
91
91
|
control do
|
92
92
|
network_port = NetworkPort.find(params[:id], self)
|
93
93
|
report_error(404) unless network_port
|
94
|
-
if request.content_type.
|
94
|
+
if grab_content_type(request.content_type, request.body) == :json
|
95
95
|
action = Action.from_json(request.body.read)
|
96
96
|
else
|
97
97
|
action = Action.from_xml(request.body.read)
|
@@ -46,7 +46,7 @@ module CIMI::Collections
|
|
46
46
|
operation :create, :with_capability => :create_network do
|
47
47
|
description "Create a new Network"
|
48
48
|
control do
|
49
|
-
if request.content_type.
|
49
|
+
if grab_content_type(request.content_type, request.body) == :json
|
50
50
|
network = Network.create(request.body.read, self, :json)
|
51
51
|
else
|
52
52
|
network = Network.create(request.body.read, self, :xml)
|
@@ -72,7 +72,7 @@ module CIMI::Collections
|
|
72
72
|
control do
|
73
73
|
network = Network.find(params[:id], self)
|
74
74
|
report_error(404) unless network
|
75
|
-
if request.content_type.
|
75
|
+
if grab_content_type(request.content_type, request.body) == :json
|
76
76
|
action = Action.from_json(request.body.read)
|
77
77
|
else
|
78
78
|
action = Action.from_xml(request.body.read)
|
@@ -90,7 +90,7 @@ module CIMI::Collections
|
|
90
90
|
control do
|
91
91
|
network = Network.find(params[:id], self)
|
92
92
|
report_error(404) unless network
|
93
|
-
if request.content_type.
|
93
|
+
if grab_content_type(request.content_type, request.body) == :json
|
94
94
|
action = Action.from_json(request.body.read)
|
95
95
|
else
|
96
96
|
action = Action.from_xml(request.body.read)
|
@@ -108,7 +108,7 @@ module CIMI::Collections
|
|
108
108
|
control do
|
109
109
|
network = Network.find(params[:id], self)
|
110
110
|
report_error(404) unless network
|
111
|
-
if request.content_type.
|
111
|
+
if grab_content_type(request.content_type, request.body) == :json
|
112
112
|
action = Action.from_json(request.body.read)
|
113
113
|
else
|
114
114
|
action = Action.from_xml(request.body.read)
|
@@ -32,7 +32,7 @@ module CIMI::Collections
|
|
32
32
|
operation :show do
|
33
33
|
description "Get the resource metadata for a specific collection"
|
34
34
|
control do
|
35
|
-
resource_metadata = ResourceMetadata.find(params[:id], self)
|
35
|
+
resource_metadata = CIMI::Model::ResourceMetadata.find(params[:id], self)
|
36
36
|
respond_to do |format|
|
37
37
|
format.xml{resource_metadata.to_xml}
|
38
38
|
format.json{resource_metadata.to_json}
|
@@ -41,6 +41,31 @@ module CIMI::Collections
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
operation :create, :with_capability => :create_storage_volume do
|
46
|
+
description "Create new VolumeConfiguration"
|
47
|
+
control do
|
48
|
+
if grab_content_type(request.content_type, request.body) == :json
|
49
|
+
new_config = CIMI::Model::VolumeConfiguration.create_from_json(request.body.read, self)
|
50
|
+
else
|
51
|
+
new_config = CIMI::Model::VolumeConfiguration.create_from_xml(request.body.read, self)
|
52
|
+
end
|
53
|
+
headers_for_create new_config
|
54
|
+
respond_to do |format|
|
55
|
+
format.json { new_config.to_json }
|
56
|
+
format.xml { new_config.to_xml }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
operation :destroy, :with_capability => :destroy_storage_volume do
|
62
|
+
description "Delete a specified VolumeConfiguration"
|
63
|
+
control do
|
64
|
+
CIMI::Model::VolumeConfiguration.delete!(params[:id], self)
|
65
|
+
no_content_with_status(200)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
44
69
|
end
|
45
70
|
|
46
71
|
end
|
@@ -42,8 +42,28 @@ module CIMI::Collections
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
end
|
46
45
|
|
46
|
+
operation :create, :with_capability => :create_storage_snapshot do
|
47
|
+
description "Create a new volume image."
|
48
|
+
control do
|
49
|
+
volume_image = CIMI::Model::VolumeImage.create(request.body, self)
|
50
|
+
headers_for_create volume_image
|
51
|
+
respond_to do |format|
|
52
|
+
format.xml { volume_image.to_xml }
|
53
|
+
format.json { volume_image.to_json }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
operation :destroy, :with_capability => :destroy_storage_snapshot do
|
59
|
+
description "Delete a specified VolumeImage"
|
60
|
+
control do
|
61
|
+
CIMI::Model::VolumeImage.delete!(params[:id], self)
|
62
|
+
no_content_with_status 200
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
47
67
|
|
48
68
|
end
|
49
69
|
end
|
@@ -0,0 +1,69 @@
|
|
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::Collections
|
17
|
+
class VolumeTemplates < Base
|
18
|
+
|
19
|
+
set :capability, lambda { |m| driver.respond_to? m }
|
20
|
+
|
21
|
+
collection :volume_templates do
|
22
|
+
|
23
|
+
operation :index, :with_capability => :storage_volumes do
|
24
|
+
description "Retrieve the Volume Template Collection"
|
25
|
+
control do
|
26
|
+
volume_template = VolumeTemplate.list(self).filter_by(params['$select'])
|
27
|
+
respond_to do |format|
|
28
|
+
format.xml { volume_template.to_xml }
|
29
|
+
format.json { volume_template.to_json }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
operation :show, :with_capability => :storage_volume do
|
35
|
+
description "Get a specific VolumeTemplate"
|
36
|
+
control do
|
37
|
+
volume_template = VolumeTemplate.find(params[:id], self)
|
38
|
+
respond_to do |format|
|
39
|
+
format.xml { volume_template.to_xml }
|
40
|
+
format.json { volume_template.json }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
operation :create, :with_capability => :create_storage_volume do
|
46
|
+
description "Create new VolumeTemplate"
|
47
|
+
control do
|
48
|
+
content_type = grab_content_type(request.content_type, request.body)
|
49
|
+
new_template = CIMI::Model::VolumeTemplate.create(request.body.read, self, content_type)
|
50
|
+
headers_for_create new_template
|
51
|
+
respond_to do |format|
|
52
|
+
format.json { new_template.to_json }
|
53
|
+
format.xml { new_template.to_xml }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
operation :destroy, :with_capability => :destroy_storage_volume do
|
59
|
+
description "Delete a specified VolumeTemplate"
|
60
|
+
control do
|
61
|
+
CIMI::Model::VolumeTemplate.delete!(params[:id], self)
|
62
|
+
no_content_with_status(200)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -46,17 +46,12 @@ module CIMI::Collections
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
operation :create do
|
49
|
+
operation :create, :with_capability => :create_storage_volume do
|
50
50
|
description "Create a new Volume."
|
51
51
|
control do
|
52
|
-
content_type = (request.content_type.
|
53
|
-
|
54
|
-
|
55
|
-
when :json
|
56
|
-
new_volume = Volume.create_from_json(request.body.read, self)
|
57
|
-
when :xml
|
58
|
-
new_volume = Volume.create_from_xml(request.body.read, self)
|
59
|
-
end
|
52
|
+
content_type = grab_content_type(request.content_type, request.body)
|
53
|
+
new_volume = Volume.create(request.body.read, self, content_type)
|
54
|
+
headers_for_create new_volume
|
60
55
|
respond_to do |format|
|
61
56
|
format.json { new_volume.to_json }
|
62
57
|
format.xml { new_volume.to_xml }
|
@@ -64,7 +59,7 @@ module CIMI::Collections
|
|
64
59
|
end
|
65
60
|
end
|
66
61
|
|
67
|
-
operation :destroy do
|
62
|
+
operation :destroy, :with_capability => :destroy_storage_volume do
|
68
63
|
description "Delete a specified Volume"
|
69
64
|
control do
|
70
65
|
Volume.delete!(params[:id], self)
|
data/lib/cimi/dependencies.rb
CHANGED
data/lib/cimi/helpers.rb
CHANGED
@@ -14,12 +14,13 @@
|
|
14
14
|
# under the License.
|
15
15
|
|
16
16
|
require_relative '../deltacloud/drivers/features'
|
17
|
-
|
17
|
+
require_relative '../deltacloud/drivers/cimi_features'
|
18
18
|
module CIMI
|
19
19
|
module Model; end
|
20
20
|
class FakeCollection
|
21
21
|
extend Sinatra::Rabbit::Features
|
22
22
|
include Deltacloud::Features
|
23
|
+
include CIMI::Features
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -32,4 +33,6 @@ require_relative '../deltacloud/helpers/driver_helper'
|
|
32
33
|
require_relative '../deltacloud/helpers/auth_helper'
|
33
34
|
require_relative '../deltacloud/helpers/deltacloud_helper'
|
34
35
|
require_relative '../deltacloud/helpers/rabbit_helper'
|
36
|
+
|
35
37
|
require_relative './helpers/cimi_helper'
|
38
|
+
require_relative './helpers/database_helper'
|
@@ -26,12 +26,20 @@ module CIMI
|
|
26
26
|
status code
|
27
27
|
end
|
28
28
|
|
29
|
+
# Set status to 201 and a Location header
|
30
|
+
def headers_for_create(resource)
|
31
|
+
status 201
|
32
|
+
headers 'Location' => resource.id
|
33
|
+
end
|
34
|
+
|
29
35
|
def href_id(href, entity)
|
30
36
|
split_on = self.send(:"#{entity.to_s}_url")
|
31
37
|
href.split("#{split_on}/").last
|
32
38
|
end
|
33
39
|
|
34
40
|
def to_kibibyte(value, unit)
|
41
|
+
#value may be a string. convert to_f
|
42
|
+
value = value.to_f # not to_i because e.g. 0.5 GB
|
35
43
|
case unit
|
36
44
|
when "GB"
|
37
45
|
(value*1024*1024).to_i
|
@@ -42,6 +50,60 @@ module CIMI
|
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
53
|
+
#e.g. convert volume to GB for deltacloud driver
|
54
|
+
def from_kibibyte(value, unit="GB")
|
55
|
+
case unit
|
56
|
+
when "GB" then ((value.to_f)/1024/1024)
|
57
|
+
when "MB" then ((value.to_f)/1024)
|
58
|
+
else nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
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
|
+
def deltacloud_create_method_for(cimi_entity)
|
96
|
+
case cimi_entity
|
97
|
+
when "machine" then "create_instance"
|
98
|
+
when "machine_configuration" then "create_hardware_profile"
|
99
|
+
when "machine_image" then "create_image"
|
100
|
+
when "volume" then "create_storage_volume"
|
101
|
+
when "volume_image" then "create_storage_snapshot"
|
102
|
+
else "create_#{cimi_entity}"
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
45
107
|
end
|
46
108
|
end
|
47
109
|
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Deltacloud
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
require_relative '../../deltacloud/helpers/driver_helper.rb'
|
5
|
+
|
6
|
+
module Database
|
7
|
+
include Deltacloud::Helpers::Drivers
|
8
|
+
|
9
|
+
DATABASE_COLLECTIONS = [ "machine_template", "address_template",
|
10
|
+
"volume_configuration", "volume_template" ]
|
11
|
+
|
12
|
+
def test_environment?
|
13
|
+
Deltacloud.test_environment?
|
14
|
+
end
|
15
|
+
|
16
|
+
def provides?(entity)
|
17
|
+
return true if DATABASE_COLLECTIONS.include? entity
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
|
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
|
+
def current_provider
|
41
|
+
Thread.current[:provider] || ENV['API_PROVIDER'] || 'default'
|
42
|
+
end
|
43
|
+
|
44
|
+
# This method allows to store things into database based on current driver
|
45
|
+
# and provider.
|
46
|
+
#
|
47
|
+
|
48
|
+
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
|
76
|
+
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
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/lib/cimi/models.rb
CHANGED
@@ -18,6 +18,17 @@ module CIMI
|
|
18
18
|
end
|
19
19
|
|
20
20
|
require 'require_relative' if RUBY_VERSION < '1.9'
|
21
|
+
require_relative '../db'
|
22
|
+
|
23
|
+
unless Deltacloud.test_environment?
|
24
|
+
Deltacloud::initialize_database
|
25
|
+
require_relative './../db/provider'
|
26
|
+
require_relative './../db/entity'
|
27
|
+
require_relative './../db/machine_template'
|
28
|
+
require_relative './../db/address_template'
|
29
|
+
require_relative './../db/volume_configuration'
|
30
|
+
require_relative './../db/volume_template'
|
31
|
+
end
|
21
32
|
|
22
33
|
require_relative './models/schema'
|
23
34
|
require_relative './models/base'
|
@@ -27,8 +38,11 @@ require_relative './models/action'
|
|
27
38
|
require_relative './models/machine_volume'
|
28
39
|
require_relative './models/disk'
|
29
40
|
|
30
|
-
require_relative './models/cloud_entry_point'
|
31
41
|
require_relative './models/resource_metadata'
|
42
|
+
require_relative './models/cloud_entry_point'
|
43
|
+
|
44
|
+
CIMI::Model::ResourceMetadata.acts_as_root_entity
|
45
|
+
|
32
46
|
require_relative './models/volume'
|
33
47
|
require_relative './models/volume_template'
|
34
48
|
require_relative './models/volume_configuration'
|