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
@@ -51,7 +51,7 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
|
|
51
51
|
|
52
52
|
# Return an Hash of the CIMI root entities used in CloudEntryPoint
|
53
53
|
def self.entities(context)
|
54
|
-
CIMI::Collections.
|
54
|
+
CIMI::Collections.modules(:cimi).inject({}) do |supported_entities, m|
|
55
55
|
m.collections.each do |c|
|
56
56
|
index_operation_capability = c.operation(:index).required_capability
|
57
57
|
next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability)
|
@@ -0,0 +1,46 @@
|
|
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::CredentialCreate < CIMI::Model::Base
|
17
|
+
|
18
|
+
ref :credential_template, :required => true
|
19
|
+
|
20
|
+
def create(context)
|
21
|
+
validate!
|
22
|
+
|
23
|
+
unless context.driver.respond_to? :create_key
|
24
|
+
raise Deltacloud::Exceptions.exception_from_status(
|
25
|
+
501,
|
26
|
+
"Creating Credential is not supported by the current driver"
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
if credential_template.href?
|
31
|
+
template = credential_template.find(ctx)
|
32
|
+
else
|
33
|
+
template = credential_template
|
34
|
+
end
|
35
|
+
|
36
|
+
key = context.driver.create_key(context.credentials, :key_name => name)
|
37
|
+
|
38
|
+
result = CIMI::Model::Credential.from_key(key, context)
|
39
|
+
result.name = name if name
|
40
|
+
result.description = description if description
|
41
|
+
result.property = property if property
|
42
|
+
result.save
|
43
|
+
result
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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::CredentialTemplate < CIMI::Model::Base
|
17
|
+
|
18
|
+
text :username, :required => true
|
19
|
+
text :password, :required => true
|
20
|
+
text :key, :required => true
|
21
|
+
|
22
|
+
# TODO: tbd
|
23
|
+
|
24
|
+
end
|
data/lib/cimi/models/machine.rb
CHANGED
@@ -50,75 +50,6 @@ class CIMI::Model::Machine < CIMI::Model::Base
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def self.create_from_json(body, context)
|
54
|
-
json = JSON.parse(body)
|
55
|
-
additional_params={}
|
56
|
-
machine_template = json['machineTemplate']
|
57
|
-
if !machine_template['href'].nil?
|
58
|
-
template = current_db.machine_templates.first(:id => machine_template['href'].split('/').last)
|
59
|
-
raise 'Could not find the MachineTemplate' if template.nil?
|
60
|
-
hardware_profile_id = template.machine_config.split('/').last
|
61
|
-
image_id = template.machine_image.split('/').last
|
62
|
-
else
|
63
|
-
hardware_profile_id = machine_template['machineConfig']["href"].split('/').last
|
64
|
-
image_id = machine_template['machineImage']["href"].split('/').last
|
65
|
-
if machine_template.has_key? 'credential'
|
66
|
-
additional_params[:keyname] = machine_template['credential']["href"].split('/').last
|
67
|
-
end
|
68
|
-
end
|
69
|
-
if machine_template.has_key? "initialState"
|
70
|
-
additional_params[:initial_state] = machine_template["initialState"].strip
|
71
|
-
end
|
72
|
-
additional_params[:name] = json['name'] if json['name']
|
73
|
-
additional_params[:realm_id] = json['realm'] if json['realm']
|
74
|
-
instance = context.driver.create_instance(context.credentials, image_id, {
|
75
|
-
:hwp_id => hardware_profile_id
|
76
|
-
}.merge(additional_params))
|
77
|
-
|
78
|
-
# Store attributes that are not supported by the backend cloud to local
|
79
|
-
# database:
|
80
|
-
machine = from_instance(instance, context)
|
81
|
-
machine.name = json['name'] || machine.name
|
82
|
-
machine.description = json['description']
|
83
|
-
machine.extract_properties!(json)
|
84
|
-
machine.save
|
85
|
-
machine
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.create_from_xml(body, context)
|
89
|
-
xml = XmlSimple.xml_in(body)
|
90
|
-
additional_params = {}
|
91
|
-
if xml['machineTemplate'][0]['href']
|
92
|
-
template = current_db.machine_templates_dataset.first(:id => xml['machineTemplate'][0]['href'].split('/').last)
|
93
|
-
hardware_profile_id = template.machine_config.split('/').last
|
94
|
-
image_id = template.machine_image.split('/').last
|
95
|
-
else
|
96
|
-
machine_template = xml['machineTemplate'][0]
|
97
|
-
hardware_profile_id = machine_template['machineConfig'].first["href"].split('/').last
|
98
|
-
image_id = machine_template['machineImage'].first["href"].split('/').last
|
99
|
-
if machine_template.has_key? 'credential'
|
100
|
-
additional_params[:keyname] = machine_template['credential'][0]["href"].split('/').last
|
101
|
-
end
|
102
|
-
end
|
103
|
-
if xml["machineTemplate"][0].has_key? "initialState"
|
104
|
-
additional_params[:initial_state] = xml["machineTemplate"][0]["initialState"].first.strip
|
105
|
-
end
|
106
|
-
additional_params[:name] = xml['name'][0] if xml['name']
|
107
|
-
additional_params[:realm_id] = xml['realm'][0] if xml['realm']
|
108
|
-
instance = context.driver.create_instance(context.credentials, image_id, {
|
109
|
-
:hwp_id => hardware_profile_id
|
110
|
-
}.merge(additional_params))
|
111
|
-
|
112
|
-
# Store attributes that are not supported by the backend cloud to local
|
113
|
-
# database:
|
114
|
-
machine = from_instance(instance, context)
|
115
|
-
machine.name = xml['name'] || machine.name
|
116
|
-
machine.description = xml['description']
|
117
|
-
machine.extract_properties!(xml)
|
118
|
-
machine.save
|
119
|
-
machine
|
120
|
-
end
|
121
|
-
|
122
53
|
def perform(action, context, &block)
|
123
54
|
begin
|
124
55
|
if context.driver.send(:"#{action.name}_instance", context.credentials, self.id.split("/").last)
|
@@ -150,7 +81,6 @@ class CIMI::Model::Machine < CIMI::Model::Base
|
|
150
81
|
CIMI::Model::MachineVolume.collection_for_instance(context.params[:id], context)
|
151
82
|
end
|
152
83
|
|
153
|
-
private
|
154
84
|
def self.from_instance(instance, context)
|
155
85
|
cpu = memory = (instance.instance_profile.id == "opaque")? "n/a" : nil
|
156
86
|
machine_conf = CIMI::Model::MachineConfiguration.find(instance.instance_profile.name, context)
|
@@ -230,7 +160,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
|
|
230
160
|
def self.convert_storage_volumes(instance, context)
|
231
161
|
instance.storage_volumes ||= [] #deal with nilpointers
|
232
162
|
instance.storage_volumes.map{|vol| {:href=>context.volume_url(vol.keys.first),
|
233
|
-
:
|
163
|
+
:initial_location=>vol.values.first} }
|
234
164
|
end
|
235
165
|
|
236
166
|
end
|
@@ -17,13 +17,13 @@ class CIMI::Model::MachineConfiguration < CIMI::Model::Base
|
|
17
17
|
|
18
18
|
acts_as_root_entity :as => "machineConfigs"
|
19
19
|
|
20
|
-
text :cpu
|
21
|
-
text :memory
|
20
|
+
text :cpu, :required => true
|
21
|
+
text :memory, :required => true
|
22
22
|
|
23
23
|
array :disks do
|
24
24
|
text :capacity
|
25
25
|
text :format
|
26
|
-
text :
|
26
|
+
text :initial_location
|
27
27
|
end
|
28
28
|
|
29
29
|
array :operations do
|
@@ -0,0 +1,49 @@
|
|
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::MachineCreate < CIMI::Model::Base
|
17
|
+
ref :machine_template
|
18
|
+
text :realm
|
19
|
+
|
20
|
+
def create(ctx)
|
21
|
+
params = {}
|
22
|
+
if machine_template.href
|
23
|
+
template = machine_template.find(ctx)
|
24
|
+
params[:hwp_id] = template.machine_config.ref_id(ctx)
|
25
|
+
params[:initial_state] = template.initial_state
|
26
|
+
image_id = template.machine_image.ref_id(ctx)
|
27
|
+
else
|
28
|
+
# FIXME: What if either of these href's isn't there ? What if the user
|
29
|
+
# tries to override some aspect of the machine_config/machine_image ?
|
30
|
+
params[:hwp_id] = machine_template.machine_config.href.split('/').last
|
31
|
+
params[:initial_state] = machine_template.initial_state
|
32
|
+
image_id = machine_template.machine_image.href.split('/').last
|
33
|
+
if machine_template.credential.href
|
34
|
+
params[:keyname] = machine_template.credential.href.split('/').last
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
params[:name] = name if name
|
39
|
+
params[:realm_id] = realm if realm
|
40
|
+
instance = ctx.driver.create_instance(ctx.credentials, image_id, params)
|
41
|
+
|
42
|
+
result = CIMI::Model::Machine::from_instance(instance, ctx)
|
43
|
+
result.name = name if name
|
44
|
+
result.description = description if description
|
45
|
+
result.property = property if property
|
46
|
+
result.save
|
47
|
+
result
|
48
|
+
end
|
49
|
+
end
|
@@ -44,34 +44,11 @@ class CIMI::Model::MachineImage < CIMI::Model::Base
|
|
44
44
|
:description => image.description,
|
45
45
|
:state => image.state || 'UNKNOWN',
|
46
46
|
:type => "IMAGE",
|
47
|
-
:created => image.creation_time.nil? ?
|
47
|
+
:created => image.creation_time.nil? ?
|
48
|
+
Time.now.xmlschema : Time.parse(image.creation_time.to_s).xmlschema
|
48
49
|
)
|
49
50
|
end
|
50
51
|
|
51
|
-
def self.create(request_body, context)
|
52
|
-
# The 'imageLocation' attribute is mandatory in CIMI, however in Deltacloud
|
53
|
-
# there is no way how to figure out from what Machine the MachineImage was
|
54
|
-
# created from. For that we need to store this attribute in properties.
|
55
|
-
#
|
56
|
-
if context.grab_content_type(context.request.content_type, request_body) == :xml
|
57
|
-
input = XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2})
|
58
|
-
raise 'imageLocation attribute is mandatory' unless input['imageLocation']
|
59
|
-
input['property'] ||= {}
|
60
|
-
else
|
61
|
-
input = JSON.parse(request_body.read)
|
62
|
-
raise 'imageLocation attribute is mandatory' unless input['imageLocation']
|
63
|
-
input['properties'] ||= []
|
64
|
-
end
|
65
|
-
params = {:id => context.href_id(input["imageLocation"], :machines), :name=>input["name"], :description=>input["description"]}
|
66
|
-
image = context.driver.create_image(context.credentials, params)
|
67
|
-
result = from_image(image, context)
|
68
|
-
result.name = input['name'] if input['name']
|
69
|
-
result.description = input['description'] if input['description']
|
70
|
-
result.extract_properties!(input)
|
71
|
-
result.save
|
72
|
-
result
|
73
|
-
end
|
74
|
-
|
75
52
|
def self.delete!(image_id, context)
|
76
53
|
context.driver.destroy_image(context.credentials, image_id)
|
77
54
|
new(:id => image_id).destroy
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
class CIMI::Model::MachineImageCreate < CIMI::Model::Base
|
17
|
+
|
18
|
+
text :type, :required => true
|
19
|
+
text :image_location, :required => true
|
20
|
+
href :related_image
|
21
|
+
|
22
|
+
def create(context)
|
23
|
+
validate!
|
24
|
+
|
25
|
+
params = {
|
26
|
+
:id => context.href_id(image_location, :machines),
|
27
|
+
:name => name,
|
28
|
+
:description => description
|
29
|
+
}
|
30
|
+
|
31
|
+
img = context.driver.create_image(context.credentials, params)
|
32
|
+
|
33
|
+
result = CIMI::Model::MachineImage.from_image(img, context)
|
34
|
+
result.name = name if name
|
35
|
+
result.description = description if description
|
36
|
+
result.property = property if property
|
37
|
+
result.save
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -17,18 +17,20 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
|
|
17
17
|
|
18
18
|
acts_as_root_entity
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
text :initial_state
|
21
|
+
ref :machine_config
|
22
|
+
ref :machine_image
|
23
|
+
ref :credential
|
24
|
+
|
25
|
+
resource_attr :realm, :required => false,
|
26
|
+
:constraints => lambda { |c| c.driver.realms(c.credentials).map { |r| r.id }}
|
23
27
|
|
24
28
|
array :volumes do
|
25
|
-
scalar :href
|
26
|
-
scalar :protocol
|
27
|
-
scalar :attachment_point
|
29
|
+
scalar :href, :initial_location
|
28
30
|
end
|
29
31
|
|
30
32
|
array :volume_templates do
|
31
|
-
scalar :href, :
|
33
|
+
scalar :href, :initial_location
|
32
34
|
end
|
33
35
|
|
34
36
|
array :network_interfaces do
|
@@ -52,36 +54,10 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
def create_from_json(body, context)
|
56
|
-
json = JSON.parse(body)
|
57
|
-
new_template = current_db.add_machine_template(
|
58
|
-
:name => json['name'],
|
59
|
-
:description => json['description'],
|
60
|
-
:machine_config => json['machineConfig']['href'],
|
61
|
-
:machine_image => json['machineImage']['href'],
|
62
|
-
:ent_properties => json['properties'] ? json['properties'].to_json : {}
|
63
|
-
)
|
64
|
-
from_db(new_template, context)
|
65
|
-
end
|
66
|
-
|
67
|
-
def create_from_xml(body, context)
|
68
|
-
xml = XmlSimple.xml_in(body)
|
69
|
-
new_template = current_db.add_machine_template(
|
70
|
-
:name => xml['name'].first,
|
71
|
-
:description => xml['description'].first,
|
72
|
-
:machine_config => xml['machineConfig'].first['href'],
|
73
|
-
:machine_image => xml['machineImage'].first['href'],
|
74
|
-
:ent_properties => xml['property'] ? JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
|
75
|
-
)
|
76
|
-
from_db(new_template, context)
|
77
|
-
end
|
78
|
-
|
79
57
|
def delete!(id, context)
|
80
58
|
current_db.machine_templates.first(:id => id).destroy
|
81
59
|
end
|
82
60
|
|
83
|
-
private
|
84
|
-
|
85
61
|
def from_db(model, context)
|
86
62
|
self.new(
|
87
63
|
:id => context.machine_template_url(model.id),
|
@@ -89,10 +65,14 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
|
|
89
65
|
:description => model.description,
|
90
66
|
:machine_config => { :href => model.machine_config },
|
91
67
|
:machine_image => { :href => model.machine_image },
|
68
|
+
:realm => model.realm,
|
92
69
|
:property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
|
93
70
|
:created => Time.parse(model.created_at.to_s).xmlschema,
|
94
71
|
:operations => [
|
95
|
-
{
|
72
|
+
{
|
73
|
+
:href => context.destroy_machine_template_url(model.id),
|
74
|
+
:rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
|
75
|
+
}
|
96
76
|
]
|
97
77
|
)
|
98
78
|
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::MachineTemplateCreate < CIMI::Model::Base
|
17
|
+
|
18
|
+
href :machine_config, :required => true
|
19
|
+
href :machine_image, :required => true
|
20
|
+
|
21
|
+
def create(context)
|
22
|
+
validate!
|
23
|
+
new_template = self.class.current_db.add_machine_template(
|
24
|
+
:name => name,
|
25
|
+
:description => description,
|
26
|
+
:machine_config => machine_config.href,
|
27
|
+
:machine_image => machine_image.href,
|
28
|
+
:ent_properties => property.to_json
|
29
|
+
)
|
30
|
+
CIMI::Model::MachineTemplate.from_db(new_template, context)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/cimi/models/network.rb
CHANGED
@@ -52,25 +52,6 @@ class CIMI::Model::Network < CIMI::Model::Base
|
|
52
52
|
networks
|
53
53
|
end
|
54
54
|
|
55
|
-
def self.create(request_body, context, type)
|
56
|
-
input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(request_body)
|
57
|
-
if input["networkTemplate"]["href"] #template by reference
|
58
|
-
network_config, routing_group = get_by_reference(input, context)
|
59
|
-
else
|
60
|
-
if input["networkTemplate"]["networkConfig"]["href"] # configuration by reference
|
61
|
-
network_config = CIMI::Model::NetworkConfiguration.find(context.href_id(input["networkTemplate"]["networkConfig"]["href"],
|
62
|
-
:network_configurations), context)
|
63
|
-
else #configuration by value
|
64
|
-
network_config = get_by_value(request_body, type)
|
65
|
-
end
|
66
|
-
routing_group = CIMI::Model::RoutingGroup.find(context.href_id(input["networkTemplate"]["routingGroup"]["href"],
|
67
|
-
:routing_groups), context)
|
68
|
-
end
|
69
|
-
params = {:network_config => network_config, :routing_group => routing_group, :name=>input["name"],
|
70
|
-
:description=>input["description"], :env=>context}
|
71
|
-
raise CIMI::Model::BadRequest.new("Bad request - missing required parameters. Client sent: #{request_body} which produced #{params.inspect}") if params.has_value?(nil)
|
72
|
-
context.driver.create_network(context.credentials, params)
|
73
|
-
end
|
74
55
|
|
75
56
|
def self.delete!(id, context)
|
76
57
|
context.driver.delete_network(context.credentials, id)
|
@@ -88,23 +69,4 @@ class CIMI::Model::Network < CIMI::Model::Base
|
|
88
69
|
end
|
89
70
|
end
|
90
71
|
|
91
|
-
private
|
92
|
-
|
93
|
-
def self.get_by_reference(input, context)
|
94
|
-
network_template = CIMI::Model::NetworkTemplate.find(context.href_id(input["networkTemplate"]["href"], :network_templates), context)
|
95
|
-
network_config = CIMI::Model::NetworkConfiguration.find(context.href_id(network_template.network_config.href, :network_configurations), context)
|
96
|
-
routing_group = CIMI::Model::RoutingGroup.find(context.href_id(network_template.routing_group.href, :routing_groups), context)
|
97
|
-
return network_config, routing_group
|
98
|
-
end
|
99
|
-
|
100
|
-
def self.get_by_value(request_body, type)
|
101
|
-
if type == :xml
|
102
|
-
xml_arrays = XmlSimple.xml_in(request_body, {"NormaliseSpace"=>2})
|
103
|
-
network_config = CIMI::Model::NetworkConfiguration.from_xml(XmlSimple.xml_out(xml_arrays["networkTemplate"][0]["networkConfig"][0]))
|
104
|
-
else
|
105
|
-
json = JSON.parse(request_body)
|
106
|
-
network_config = CIMI::Model::NetworkConfiguration.from_json(JSON.generate(json["networkTemplate"]["networkConfig"]))
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
72
|
end
|