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.
- data/Rakefile +40 -28
- data/bin/deltacloud-db-upgrade +24 -0
- data/bin/deltacloudd +20 -9
- data/config.ru +12 -53
- data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
- data/deltacloud-core.gemspec +11 -5
- data/lib/cimi/collections.rb +4 -31
- data/lib/cimi/collections/address_templates.rb +2 -5
- data/lib/cimi/collections/addresses.rb +2 -5
- data/lib/cimi/collections/base.rb +18 -6
- data/lib/cimi/collections/credentials.rb +2 -5
- data/lib/cimi/collections/machine_images.rb +2 -1
- data/lib/cimi/collections/machine_templates.rb +2 -5
- data/lib/cimi/collections/machines.rb +6 -9
- data/lib/cimi/collections/network_ports.rb +3 -3
- data/lib/cimi/collections/networks.rb +5 -8
- data/lib/cimi/collections/system_templates.rb +72 -0
- data/lib/cimi/collections/systems.rb +194 -0
- data/lib/cimi/collections/volume_configurations.rb +1 -1
- data/lib/cimi/collections/volume_images.rb +2 -1
- data/lib/cimi/collections/volume_templates.rb +3 -2
- data/lib/cimi/collections/volumes.rb +2 -2
- data/lib/cimi/dependencies.rb +0 -2
- data/lib/cimi/helpers/cimi_helper.rb +12 -57
- data/lib/cimi/helpers/database_helper.rb +0 -4
- data/lib/cimi/models.rb +25 -14
- data/lib/cimi/models/address.rb +4 -31
- data/lib/cimi/models/address_create.rb +51 -0
- data/lib/cimi/models/address_template.rb +8 -52
- data/lib/cimi/models/address_template_create.rb +44 -0
- data/lib/cimi/models/base.rb +44 -6
- data/lib/cimi/models/cloud_entry_point.rb +1 -1
- data/lib/cimi/models/credential.rb +1 -1
- data/lib/cimi/models/credential_create.rb +46 -0
- data/lib/cimi/models/credential_template.rb +24 -0
- data/lib/cimi/models/machine.rb +1 -71
- data/lib/cimi/models/machine_configuration.rb +3 -3
- data/lib/cimi/models/machine_create.rb +49 -0
- data/lib/cimi/models/machine_image.rb +2 -25
- data/lib/cimi/models/machine_image_create.rb +41 -0
- data/lib/cimi/models/machine_template.rb +14 -34
- data/lib/cimi/models/machine_template_create.rb +33 -0
- data/lib/cimi/models/network.rb +0 -38
- data/lib/cimi/models/network_create.rb +43 -0
- data/lib/cimi/models/network_port.rb +17 -17
- data/lib/cimi/models/network_template.rb +2 -3
- data/lib/cimi/models/resource.rb +22 -3
- data/lib/cimi/models/schema.rb +94 -8
- data/lib/cimi/models/system.rb +67 -0
- data/lib/cimi/models/system_template.rb +63 -0
- data/lib/cimi/models/volume.rb +2 -42
- data/lib/cimi/models/volume_configuration.rb +4 -4
- data/lib/cimi/models/volume_create.rb +58 -0
- data/lib/cimi/models/volume_image.rb +8 -17
- data/lib/cimi/models/volume_image_create.rb +47 -0
- data/lib/cimi/models/volume_template.rb +6 -19
- data/lib/cimi/models/volume_template_create.rb +33 -0
- data/lib/db.rb +14 -22
- data/lib/db/volume_template.rb +1 -1
- data/lib/deltacloud/api.rb +6 -5
- data/lib/deltacloud/collections.rb +4 -27
- data/lib/deltacloud/collections/base.rb +4 -0
- data/lib/deltacloud/collections/images.rb +1 -1
- data/lib/deltacloud/collections/instances.rb +2 -2
- data/lib/deltacloud/core_ext/array.rb +1 -0
- data/lib/deltacloud/core_ext/integer.rb +13 -9
- data/lib/deltacloud/core_ext/string.rb +45 -28
- data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
- data/lib/deltacloud/drivers/base_driver.rb +45 -16
- data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
- data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
- data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
- data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
- data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
- data/lib/deltacloud/helpers/collection_helper.rb +106 -0
- data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
- data/lib/deltacloud/models/address.rb +19 -17
- data/lib/deltacloud/models/base_model.rb +29 -26
- data/lib/deltacloud/models/blob.rb +22 -20
- data/lib/deltacloud/models/bucket.rb +21 -16
- data/lib/deltacloud/models/firewall.rb +18 -16
- data/lib/deltacloud/models/firewall_rule.rb +22 -20
- data/lib/deltacloud/models/image.rb +29 -28
- data/lib/deltacloud/models/instance.rb +92 -94
- data/lib/deltacloud/models/instance_address.rb +42 -40
- data/lib/deltacloud/models/instance_profile.rb +28 -26
- data/lib/deltacloud/models/key.rb +47 -45
- data/lib/deltacloud/models/load_balancer.rb +32 -31
- data/lib/deltacloud/models/metric.rb +76 -29
- data/lib/deltacloud/models/provider.rb +15 -13
- data/lib/deltacloud/models/realm.rb +15 -21
- data/lib/deltacloud/models/storage_snapshot.rb +23 -19
- data/lib/deltacloud/models/storage_volume.rb +35 -34
- data/lib/deltacloud/version.rb +1 -1
- data/lib/deltacloud_rack.rb +22 -0
- data/lib/initialize.rb +28 -0
- data/lib/initializers/database_initialize.rb +76 -0
- data/lib/initializers/frontend_initialize.rb +42 -0
- data/lib/initializers/mock_initialize.rb +33 -0
- data/lib/sinatra/rack_logger.rb +35 -24
- data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
- data/tests/cimi/collections/machine_images_test.rb +2 -2
- data/tests/cimi/collections/machine_templates_test.rb +75 -0
- data/tests/cimi/collections/machines_test.rb +2 -2
- data/tests/cimi/collections/system_templates_test.rb +41 -0
- data/tests/cimi/collections/systems_test.rb +50 -0
- data/tests/cimi/db/database_helper_test.rb +17 -25
- data/tests/cimi/db/db_helper.rb +1 -12
- data/tests/cimi/db/entity_test.rb +7 -8
- data/tests/cimi/model/machine_create_spec.rb +44 -0
- data/tests/cimi/model/machine_template_spec.rb +29 -0
- data/tests/cimi/model/resource_spec.rb +40 -0
- data/tests/cimi/model/schema_spec.rb +37 -0
- data/tests/cimi/spec_helper.rb +3 -0
- data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
- data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
- data/tests/deltacloud/collections/images_collection_test.rb +2 -2
- data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
- data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
- data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
- data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
- data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
- data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
- data/tests/deltacloud/collections_test.rb +5 -5
- data/tests/deltacloud/common.rb +2 -13
- data/tests/deltacloud/launcher_test.rb +3 -3
- data/tests/deltacloud/rack_test.rb +2 -2
- data/tests/deltacloud/server_test.rb +1 -1
- data/tests/drivers/base/base_driver_test.rb +5 -5
- data/tests/drivers/base/common.rb +2 -12
- data/tests/drivers/ec2/buckets_test.rb +1 -1
- data/tests/drivers/ec2/images_test.rb +2 -2
- data/tests/drivers/ec2/instance_test.rb +6 -6
- data/tests/drivers/ec2/keys_test.rb +3 -3
- data/tests/drivers/ec2/realms_test.rb +2 -2
- data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
- data/tests/drivers/fgcp/common.rb +32 -0
- data/tests/drivers/fgcp/firewall_test.rb +70 -0
- data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
- data/tests/drivers/fgcp/images_test.rb +46 -0
- data/tests/drivers/fgcp/provider_test.rb +27 -0
- data/tests/drivers/fgcp/realms_test.rb +53 -0
- data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
- data/tests/drivers/gogrid/images_test.rb +2 -2
- data/tests/drivers/gogrid/instances_test.rb +2 -2
- data/tests/drivers/gogrid/realms_test.rb +2 -2
- data/tests/drivers/mock/images_test.rb +4 -4
- data/tests/drivers/mock/instances_test.rb +9 -9
- data/tests/drivers/mock/keys_test.rb +3 -3
- data/tests/drivers/mock/realms_test.rb +2 -2
- data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
- data/tests/drivers/mock/storage_volumes_test.rb +4 -4
- data/tests/drivers/models/instance_test.rb +2 -2
- data/tests/drivers/openstack/images_test.rb +2 -2
- data/tests/drivers/openstack/instances_test.rb +2 -3
- data/tests/drivers/openstack/keys_test.rb +1 -1
- data/tests/drivers/openstack/realms_test.rb +2 -11
- data/tests/drivers/rhevm/common.rb +33 -12
- data/tests/drivers/rhevm/images_test.rb +20 -12
- data/tests/drivers/rhevm/instance_test.rb +62 -46
- data/tests/drivers/rhevm/provider_test.rb +12 -6
- data/tests/drivers/rhevm/realms_test.rb +15 -9
- data/tests/ec2/query_parser_test.rb +1 -1
- data/tests/test_helper.rb +68 -12
- data/views/addresses/show.html.haml +1 -1
- data/views/buckets/show.html.haml +1 -1
- data/views/errors/{500.html.haml → common.html.haml} +0 -0
- data/views/errors/common.xml.haml +17 -0
- data/views/firewalls/index.xml.haml +2 -2
- data/views/firewalls/new.html.haml +2 -2
- data/views/images/show.html.haml +1 -1
- data/views/instances/run_command.html.haml +1 -1
- data/views/instances/show.html.haml +3 -3
- data/views/keys/index.html.haml +1 -0
- data/views/keys/show.html.haml +8 -4
- data/views/keys/show.xml.haml +3 -2
- data/views/load_balancers/new.html.haml +1 -1
- data/views/load_balancers/show.html.haml +2 -2
- data/views/metrics/show.html.haml +1 -1
- data/views/realms/index.html.haml +0 -2
- data/views/realms/show.html.haml +0 -4
- data/views/realms/show.xml.haml +0 -3
- data/views/storage_snapshots/index.html.haml +1 -1
- data/views/storage_snapshots/new.html.haml +1 -1
- data/views/storage_volumes/new.html.haml +2 -2
- data/views/storage_volumes/show.html.haml +3 -3
- metadata +90 -41
- data/views/errors/400.html.haml +0 -41
- data/views/errors/400.xml.haml +0 -3
- data/views/errors/401.html.haml +0 -26
- data/views/errors/401.xml.haml +0 -3
- data/views/errors/403.html.haml +0 -42
- data/views/errors/403.xml.haml +0 -9
- data/views/errors/404.html.haml +0 -28
- data/views/errors/404.xml.haml +0 -3
- data/views/errors/405.html.haml +0 -29
- data/views/errors/405.xml.haml +0 -5
- data/views/errors/409.html.haml +0 -47
- data/views/errors/409.xml.haml +0 -11
- data/views/errors/500.xml.haml +0 -13
- data/views/errors/501.html.haml +0 -44
- data/views/errors/501.xml.haml +0 -1
- data/views/errors/502.html.haml +0 -44
- data/views/errors/502.xml.haml +0 -1
- data/views/errors/504.html.haml +0 -43
- data/views/errors/504.xml.haml +0 -1
data/lib/cimi/models/volume.rb
CHANGED
@@ -51,24 +51,6 @@ class CIMI::Model::Volume < CIMI::Model::Base
|
|
51
51
|
|
52
52
|
def self.all(context); find(:all, context); end
|
53
53
|
|
54
|
-
def self.create(request_body, context, type)
|
55
|
-
#json = JSON.parse(json_in)
|
56
|
-
input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(request_body)
|
57
|
-
if input["volumeTemplate"]["href"] #template by reference
|
58
|
-
#FIXME - don't have volumeTemplates yet - datamapper volume_config =
|
59
|
-
else #template by value
|
60
|
-
volume_image_id = (input["volumeTemplate"].has_key?("volumeImage") ?
|
61
|
-
input["volumeTemplate"]["volumeImage"]["href"].split("/").last : nil)
|
62
|
-
if input["volumeTemplate"]["volumeConfig"]["href"] #with config by reference
|
63
|
-
volume_config_id = input["volumeTemplate"]["volumeConfig"]["href"].split("/").last
|
64
|
-
create_volume({:volume_config_id=>volume_config_id, :volume_image_id=>volume_image_id}, input, context)
|
65
|
-
else #with config by value
|
66
|
-
capacity = input["volumeTemplate"]["volumeConfig"]["capacity"]
|
67
|
-
create_volume({:capacity=>capacity, :volume_image_id=>volume_image_id}, input, context)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
54
|
def self.delete!(id, context)
|
73
55
|
context.driver.destroy_storage_volume(context.credentials, {:id=>id} )
|
74
56
|
new(:id => id).destroy
|
@@ -77,35 +59,13 @@ class CIMI::Model::Volume < CIMI::Model::Base
|
|
77
59
|
def self.find_to_attach_from_json(json_in, context)
|
78
60
|
json = JSON.parse(json_in)
|
79
61
|
json["volumes"].map{|v| {:volume=>self.find(v["volume"]["href"].split("/volumes/").last, context),
|
80
|
-
:
|
62
|
+
:initial_location=>v["initialLocation"] }}
|
81
63
|
end
|
82
64
|
|
83
65
|
def self.find_to_attach_from_xml(xml_in, context)
|
84
66
|
xml = XmlSimple.xml_in(xml_in)
|
85
67
|
xml["volume"].map{|v| {:volume => self.find(v["href"].split("/volumes/").last, context),
|
86
|
-
:
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def self.create_volume(params, data, context)
|
92
|
-
if params[:volume_config_id]
|
93
|
-
volume_config = CIMI::Model::VolumeConfiguration.find(params[:volume_config_id], context)
|
94
|
-
opts = {:capacity=>context.from_kibibyte(volume_config.capacity, "GB"),
|
95
|
-
:snapshot_id=>params[:volume_image_id],
|
96
|
-
:name=>data["name"]}
|
97
|
-
elsif params[:capacity]
|
98
|
-
opts = {:capacity=>context.from_kibibyte(params[:capacity], "GB"),
|
99
|
-
:snapshot_id=>params[:volume_image_id],
|
100
|
-
:name=>data["name"]}
|
101
|
-
end
|
102
|
-
storage_volume = context.driver.create_storage_volume(context.credentials, opts)
|
103
|
-
result = from_storage_volume(storage_volume, context)
|
104
|
-
result.name = data['name'] if data['name']
|
105
|
-
result.description = data['description']
|
106
|
-
result.extract_properties!(data)
|
107
|
-
result.save
|
108
|
-
result
|
68
|
+
:initial_location=>v["initialLocation"] }}
|
109
69
|
end
|
110
70
|
|
111
71
|
def self.from_storage_volume(volume, context)
|
@@ -17,9 +17,9 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
|
|
17
17
|
|
18
18
|
acts_as_root_entity :as => "volumeConfigs"
|
19
19
|
|
20
|
+
href :type
|
20
21
|
text :format
|
21
|
-
|
22
|
-
text :capacity
|
22
|
+
text :capacity, :required => true
|
23
23
|
|
24
24
|
array :operations do
|
25
25
|
scalar :rel, :href
|
@@ -32,7 +32,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
|
|
32
32
|
:description => json['description'],
|
33
33
|
:format => json['format'],
|
34
34
|
:capacity => json['capacity'],
|
35
|
-
:ent_properties => json['properties']
|
35
|
+
:ent_properties => (json['properties'] || {}).to_json
|
36
36
|
)
|
37
37
|
from_db(new_config, context)
|
38
38
|
end
|
@@ -45,7 +45,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
|
|
45
45
|
:description => xml['description'].first,
|
46
46
|
:format => xml['format'].first,
|
47
47
|
:capacity => xml['capacity'].first,
|
48
|
-
:ent_properties =>
|
48
|
+
:ent_properties => JSON::dump((xml['property'] || {}).inject({}){ |r, p| r[p['key']]=p['content']; r })
|
49
49
|
)
|
50
50
|
from_db(new_config, context)
|
51
51
|
end
|
@@ -0,0 +1,58 @@
|
|
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::VolumeCreate < CIMI::Model::Base
|
17
|
+
|
18
|
+
ref :volume_template, :required => true
|
19
|
+
|
20
|
+
def create(context)
|
21
|
+
validate!
|
22
|
+
|
23
|
+
if volume_template.href?
|
24
|
+
template = volume_template.find(context)
|
25
|
+
else
|
26
|
+
template = CIMI::Model::VolumeTemplate.from_xml(volume_template.to_xml)
|
27
|
+
end
|
28
|
+
|
29
|
+
volume_image = template.volume_image.href? ?
|
30
|
+
template.volume_image.find(context) : template.volume_image
|
31
|
+
|
32
|
+
volume_config = template.volume_config.href? ?
|
33
|
+
template.volume_config.find(context) : template.volume_config
|
34
|
+
|
35
|
+
params = {
|
36
|
+
:name => name,
|
37
|
+
:capacity => volume_config.capacity,
|
38
|
+
:snapshot_id => ref_id(volume_image.id),
|
39
|
+
}
|
40
|
+
|
41
|
+
unless context.driver.respond_to? :create_storage_volume
|
42
|
+
raise Deltacloud::Exceptions.exception_from_status(
|
43
|
+
501,
|
44
|
+
"Creating Volume is not supported by the current driver"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
volume = context.driver.create_storage_volume(context.credentials, params)
|
49
|
+
|
50
|
+
result = CIMI::Model::Volume.from_storage_volume(volume, context)
|
51
|
+
result.name = name if result.name.nil?
|
52
|
+
result.description = description if description
|
53
|
+
result.property = property if property
|
54
|
+
result.save
|
55
|
+
result
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -20,6 +20,7 @@ class CIMI::Model::VolumeImage < CIMI::Model::Base
|
|
20
20
|
href :image_location
|
21
21
|
text :image_data
|
22
22
|
text :bootable
|
23
|
+
|
23
24
|
array :operations do
|
24
25
|
scalar :rel, :href
|
25
26
|
end
|
@@ -38,29 +39,19 @@ class CIMI::Model::VolumeImage < CIMI::Model::Base
|
|
38
39
|
|
39
40
|
def self.all(context); find(:all, context); end
|
40
41
|
|
41
|
-
def self.create(request_body, context)
|
42
|
-
type = context.grab_content_type(context.request.content_type, request_body)
|
43
|
-
input = (type == :xml)? XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(request_body.read)
|
44
|
-
params = {:volume_id => context.href_id(input["imageLocation"]["href"], :volumes), :name=>input["name"], :description=>input["description"]}
|
45
|
-
vol_image = context.driver.create_storage_snapshot(context.credentials, params)
|
46
|
-
from_storage_snapshot(vol_image, context)
|
47
|
-
end
|
48
|
-
|
49
42
|
def self.delete!(vol_image_id, context)
|
50
43
|
context.driver.destroy_storage_snapshot(context.credentials, {:id=>vol_image_id})
|
51
44
|
end
|
52
45
|
|
53
|
-
private
|
54
|
-
|
55
46
|
def self.from_storage_snapshot(snapshot, context)
|
56
47
|
self.new( {
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
48
|
+
:name => snapshot.name,
|
49
|
+
:description => snapshot.description,
|
50
|
+
:created => snapshot.created.nil? ? nil : Time.parse(snapshot.created).xmlschema,
|
51
|
+
:id => context.volume_image_url(snapshot.id),
|
52
|
+
:image_location => {:href=>context.volume_url(snapshot.storage_volume_id)},
|
53
|
+
:bootable => "false" #FIXME
|
54
|
+
} )
|
64
55
|
end
|
65
56
|
|
66
57
|
end
|
@@ -0,0 +1,47 @@
|
|
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::VolumeImageCreate < CIMI::Model::Base
|
17
|
+
|
18
|
+
href :image_location
|
19
|
+
text :image_data
|
20
|
+
text :bootable, :required => true
|
21
|
+
|
22
|
+
def create(context)
|
23
|
+
validate!
|
24
|
+
|
25
|
+
params = {
|
26
|
+
:volume_id => context.href_id(image_location.href, :volumes),
|
27
|
+
:name => name,
|
28
|
+
:description => description
|
29
|
+
}
|
30
|
+
|
31
|
+
unless context.driver.respond_to? :create_storage_snapshot
|
32
|
+
raise Deltacloud::Exceptions.exception_from_status(
|
33
|
+
501,
|
34
|
+
'Creating VolumeImage is not supported by the current driver'
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
new_snapshot = context.driver.create_storage_snapshot(context.credentials, params)
|
39
|
+
result = CIMI::Model::VolumeImage.from_storage_snapshot(new_snapshot, context)
|
40
|
+
result.name= name unless new_snapshot.name
|
41
|
+
result.description = description unless new_snapshot.description
|
42
|
+
result.property = property if property
|
43
|
+
result.save
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -17,8 +17,8 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
|
|
17
17
|
|
18
18
|
acts_as_root_entity
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
ref :volume_config, :required => true
|
21
|
+
ref :volume_image, :required => true
|
22
22
|
|
23
23
|
array :meter_templates do
|
24
24
|
end
|
@@ -47,26 +47,10 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.create(body, context, type)
|
51
|
-
input = (type == :xml)? XmlSimple.xml_in(body, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(body)
|
52
|
-
input['property'] ||= []
|
53
|
-
vol_image = input['volumeImage']['href'] if input['volumeImage']
|
54
|
-
new_template = current_db.add_volume_template(
|
55
|
-
:name => input['name'],
|
56
|
-
:description => input['description'],
|
57
|
-
:volume_config => input['volumeConfig']['href'],
|
58
|
-
:volume_image => vol_image,
|
59
|
-
:ent_properties => input['property'] ? JSON::dump(input['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
|
60
|
-
)
|
61
|
-
from_db(new_template, context)
|
62
|
-
end
|
63
|
-
|
64
50
|
def self.delete!(id, context)
|
65
51
|
current_db.volume_templates.first(:id => id).destroy
|
66
52
|
end
|
67
53
|
|
68
|
-
private
|
69
|
-
|
70
54
|
def self.from_db(model, context)
|
71
55
|
self.new(
|
72
56
|
:id => context.volume_template_url(model.id),
|
@@ -76,7 +60,10 @@ private
|
|
76
60
|
:volume_image => {:href => model.volume_image},
|
77
61
|
:property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
|
78
62
|
:operations => [
|
79
|
-
{
|
63
|
+
{
|
64
|
+
:href => context.destroy_volume_template_url(model.id),
|
65
|
+
:rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
|
66
|
+
}
|
80
67
|
]
|
81
68
|
)
|
82
69
|
end
|
@@ -0,0 +1,33 @@
|
|
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::VolumeTemplateCreate < CIMI::Model::Base
|
17
|
+
|
18
|
+
ref :volume_config, :required => true
|
19
|
+
ref :volume_image, :required => true
|
20
|
+
|
21
|
+
def create(context)
|
22
|
+
validate!
|
23
|
+
new_template = self.class.current_db.add_volume_template(
|
24
|
+
:name => name,
|
25
|
+
:description => description,
|
26
|
+
:volume_config => volume_config.href,
|
27
|
+
:volume_image => volume_image.href,
|
28
|
+
:ent_properties => property.to_json
|
29
|
+
)
|
30
|
+
CIMI::Model::VolumeTemplate.from_db(new_template, context)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/db.rb
CHANGED
@@ -15,31 +15,23 @@
|
|
15
15
|
|
16
16
|
module Deltacloud
|
17
17
|
|
18
|
-
def self.
|
19
|
-
ENV['
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
if RUBY_PLATFORM == 'java'
|
29
|
-
DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
|
30
|
-
'jdbc:sqlite:'+File.join('/', 'var', 'tmp', "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
|
31
|
-
else
|
32
|
-
DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
|
33
|
-
'sqlite://'+File.join('/', 'var', 'tmp', "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
|
18
|
+
def self.connect(location)
|
19
|
+
if ENV['API_VERBOSE']
|
20
|
+
if Deltacloud.respond_to? :config
|
21
|
+
logger = Deltacloud.config[:cimi].logger
|
22
|
+
else
|
23
|
+
logger = ::Logger.new($stdout)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@db = Sequel.connect(location, :logger => logger)
|
34
27
|
end
|
35
28
|
|
36
|
-
def self.database
|
37
|
-
|
38
|
-
@db ||= Sequel.connect(DATABASE_LOCATION, opts)
|
29
|
+
def self.database
|
30
|
+
@db
|
39
31
|
end
|
40
32
|
|
41
|
-
def self.initialize_database
|
42
|
-
db =
|
33
|
+
def self.initialize_database(location)
|
34
|
+
db = connect(location)
|
43
35
|
|
44
36
|
db.create_table?(:providers) {
|
45
37
|
primary_key :id
|
@@ -92,6 +84,6 @@ module Deltacloud
|
|
92
84
|
column :volume_config, :string
|
93
85
|
column :volume_image, :string
|
94
86
|
}
|
87
|
+
db
|
95
88
|
end
|
96
|
-
|
97
89
|
end
|
data/lib/db/volume_template.rb
CHANGED
data/lib/deltacloud/api.rb
CHANGED
@@ -39,7 +39,7 @@ module TestPoller
|
|
39
39
|
opts[:retries] ||= 10
|
40
40
|
opts[:time_between_retry] ||= 10
|
41
41
|
opts[:timeout] ||= 60
|
42
|
-
opts[:method] ||= self.class.name.downcase.to_sym
|
42
|
+
opts[:method] ||= self.class.name.split('::').last.downcase.to_sym
|
43
43
|
opts[:retries].downto(0) do |r|
|
44
44
|
result = begin
|
45
45
|
timeout(opts[:timeout]) do
|
@@ -62,12 +62,13 @@ module TestPoller
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
class Instance; include TestPoller; end
|
66
|
-
class Image; include TestPoller; end
|
67
|
-
class StorageSnapshot; include TestPoller; end
|
68
|
-
|
69
65
|
module Deltacloud
|
70
66
|
|
67
|
+
class Instance; include TestPoller; end
|
68
|
+
class Image; include TestPoller; end
|
69
|
+
class StorageSnapshot; include TestPoller; end
|
70
|
+
|
71
|
+
|
71
72
|
def self.drivers
|
72
73
|
Drivers.driver_config
|
73
74
|
end
|
@@ -15,41 +15,18 @@
|
|
15
15
|
# under the License.
|
16
16
|
|
17
17
|
require_relative './collections/base'
|
18
|
+
require_relative './helpers/collection_helper'
|
18
19
|
|
19
20
|
module Deltacloud
|
20
21
|
|
21
|
-
def self.collection_names
|
22
|
-
@collections.map { |c| c.collection_name }
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.collections
|
26
|
-
@collections ||= []
|
27
|
-
end
|
28
|
-
|
29
22
|
module Collections
|
23
|
+
extend Deltacloud::CollectionHelper
|
30
24
|
|
31
|
-
|
32
|
-
Deltacloud.collections.find { |c| c.collection_name == name }
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.deltacloud_modules
|
36
|
-
@deltacloud_modules ||= []
|
37
|
-
end
|
38
|
-
|
39
|
-
Dir[File.join(File::dirname(__FILE__), "collections", "*.rb")].each do |collection|
|
40
|
-
base_collection_name = File.basename(collection).gsub('.rb', '')
|
41
|
-
next if base_collection_name == 'base'
|
42
|
-
require collection
|
43
|
-
deltacloud_module_class = Deltacloud::Collections.const_get(base_collection_name.camelize)
|
44
|
-
deltacloud_modules << deltacloud_module_class
|
45
|
-
deltacloud_module_class.collections.each do |c|
|
46
|
-
Deltacloud.collections << c
|
47
|
-
end unless deltacloud_module_class.collections.nil?
|
48
|
-
end
|
25
|
+
load_collections_for :deltacloud, :from => File.join(File.dirname(__FILE__), 'collections')
|
49
26
|
|
50
27
|
def self.included(klass)
|
51
28
|
klass.class_eval do
|
52
|
-
Deltacloud::Collections.
|
29
|
+
Deltacloud::Collections.modules(:deltacloud).each do |collection_class|
|
53
30
|
use collection_class
|
54
31
|
end
|
55
32
|
end
|