deltacloud-core 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/deltacloud-core.gemspec +4 -7
- data/lib/cimi/collections/address_templates.rb +4 -42
- data/lib/cimi/collections/addresses.rb +5 -43
- data/lib/cimi/collections/base.rb +11 -3
- data/lib/cimi/collections/cloud_entry_point.rb +1 -1
- data/lib/cimi/collections/credentials.rb +4 -43
- data/lib/cimi/collections/forwarding_group_templates.rb +2 -20
- data/lib/cimi/collections/forwarding_groups.rb +2 -21
- data/lib/cimi/collections/machine_configurations.rb +2 -20
- data/lib/cimi/collections/machine_images.rb +4 -42
- data/lib/cimi/collections/machine_templates.rb +4 -42
- data/lib/cimi/collections/machines.rb +14 -64
- data/lib/cimi/collections/network_configurations.rb +2 -20
- data/lib/cimi/collections/network_port_configurations.rb +2 -21
- data/lib/cimi/collections/network_port_templates.rb +2 -23
- data/lib/cimi/collections/network_ports.rb +6 -46
- data/lib/cimi/collections/network_templates.rb +2 -21
- data/lib/cimi/collections/networks.rb +4 -40
- data/lib/cimi/collections/resource_metadata.rb +2 -21
- data/lib/cimi/collections/system_templates.rb +4 -45
- data/lib/cimi/collections/systems.rb +65 -82
- data/lib/cimi/collections/volume_configurations.rb +4 -45
- data/lib/cimi/collections/volume_images.rb +4 -42
- data/lib/cimi/collections/volume_templates.rb +5 -44
- data/lib/cimi/collections/volumes.rb +4 -48
- data/lib/cimi/helpers.rb +1 -0
- data/lib/cimi/helpers/cimi_helper.rb +1 -1
- data/lib/cimi/helpers/cimi_rabbit_helper.rb +113 -0
- data/lib/cimi/helpers/database_helper.rb +1 -2
- data/lib/cimi/models.rb +12 -11
- data/lib/cimi/models/action.rb +0 -4
- data/lib/cimi/models/address.rb +0 -38
- data/lib/cimi/models/address_create.rb +0 -31
- data/lib/cimi/models/address_template.rb +0 -47
- data/lib/cimi/models/address_template_create.rb +0 -16
- data/lib/cimi/models/base.rb +2 -74
- data/lib/cimi/models/cloud_entry_point.rb +2 -30
- data/lib/cimi/models/collection.rb +8 -25
- data/lib/cimi/models/credential.rb +0 -34
- data/lib/cimi/models/credential_create.rb +0 -26
- data/lib/cimi/models/credential_template.rb +0 -2
- data/lib/cimi/models/disk.rb +0 -56
- data/lib/cimi/models/forwarding_group.rb +0 -8
- data/lib/cimi/models/forwarding_group_template.rb +0 -8
- data/lib/cimi/models/machine.rb +4 -129
- data/lib/cimi/models/machine_configuration.rb +0 -31
- data/lib/cimi/models/machine_create.rb +1 -29
- data/lib/cimi/models/machine_image.rb +0 -28
- data/lib/cimi/models/machine_image_create.rb +0 -19
- data/lib/cimi/models/machine_template.rb +5 -39
- data/lib/cimi/models/machine_template_create.rb +0 -12
- data/lib/cimi/models/machine_volume.rb +0 -65
- data/lib/cimi/models/network.rb +0 -32
- data/lib/cimi/models/network_configuration.rb +0 -15
- data/lib/cimi/models/network_create.rb +0 -23
- data/lib/cimi/models/network_port.rb +0 -73
- data/lib/cimi/models/network_port_configuration.rb +0 -8
- data/lib/cimi/models/network_port_template.rb +0 -8
- data/lib/cimi/models/network_template.rb +2 -12
- data/lib/cimi/models/resource.rb +0 -6
- data/lib/cimi/models/resource_metadata.rb +1 -95
- data/lib/cimi/models/schema.rb +28 -32
- data/lib/cimi/models/system.rb +15 -39
- data/lib/cimi/models/system_address.rb +26 -0
- data/lib/cimi/models/system_create.rb +20 -0
- data/lib/cimi/models/system_credential.rb +26 -0
- data/lib/cimi/models/system_forwarding_group.rb +26 -0
- data/lib/cimi/models/system_machine.rb +26 -0
- data/lib/cimi/models/system_network.rb +26 -0
- data/lib/cimi/models/system_network_port.rb +26 -0
- data/lib/cimi/models/system_system.rb +26 -0
- data/lib/cimi/models/system_template.rb +15 -31
- data/lib/cimi/models/system_volume.rb +26 -0
- data/lib/cimi/models/volume.rb +0 -59
- data/lib/cimi/models/volume_configuration.rb +1 -64
- data/lib/cimi/models/volume_configuration_create.rb +22 -0
- data/lib/cimi/models/volume_create.rb +0 -38
- data/lib/cimi/models/volume_image.rb +0 -30
- data/lib/cimi/models/volume_image_create.rb +0 -25
- data/lib/cimi/models/volume_template.rb +2 -43
- data/lib/cimi/models/volume_template_create.rb +0 -12
- data/lib/cimi/service.rb +82 -0
- data/lib/cimi/service/action.rb +21 -0
- data/lib/cimi/service/address.rb +56 -0
- data/lib/cimi/service/address_create.rb +45 -0
- data/lib/cimi/service/address_template.rb +71 -0
- data/lib/cimi/service/address_template_create.rb +34 -0
- data/lib/cimi/service/base.rb +266 -0
- data/lib/cimi/service/cloud_entry_point.rb +53 -0
- data/lib/cimi/service/credential.rb +52 -0
- data/lib/cimi/service/credential_create.rb +38 -0
- data/lib/cimi/service/credential_template.rb +20 -0
- data/lib/cimi/service/disk.rb +75 -0
- data/lib/cimi/service/forwarding_group.rb +26 -0
- data/lib/cimi/service/forwarding_group_template.rb +26 -0
- data/lib/cimi/service/machine.rb +154 -0
- data/lib/cimi/service/machine_configuration.rb +54 -0
- data/lib/cimi/service/machine_create.rb +49 -0
- data/lib/cimi/service/machine_image.rb +47 -0
- data/lib/cimi/service/machine_image_create.rb +35 -0
- data/lib/cimi/service/machine_template.rb +61 -0
- data/lib/cimi/service/machine_template_create.rb +29 -0
- data/lib/cimi/service/machine_volume.rb +74 -0
- data/lib/cimi/service/network.rb +51 -0
- data/lib/cimi/service/network_configuration.rb +36 -0
- data/lib/cimi/service/network_create.rb +39 -0
- data/lib/cimi/service/network_port.rb +97 -0
- data/lib/cimi/service/network_port_configuration.rb +26 -0
- data/lib/cimi/service/network_port_template.rb +26 -0
- data/lib/cimi/service/network_template.rb +28 -0
- data/lib/cimi/service/resource_metadata.rb +44 -0
- data/lib/cimi/service/system.rb +45 -0
- data/lib/cimi/service/system_address.rb +34 -0
- data/lib/cimi/service/system_create.rb +39 -0
- data/lib/cimi/service/system_credential.rb +34 -0
- data/lib/cimi/service/system_forwarding_group.rb +34 -0
- data/lib/cimi/service/system_machine.rb +34 -0
- data/lib/cimi/service/system_network.rb +34 -0
- data/lib/cimi/service/system_network_port.rb +34 -0
- data/lib/cimi/service/system_system.rb +34 -0
- data/lib/cimi/service/system_template.rb +32 -0
- data/lib/cimi/service/system_volume.rb +34 -0
- data/lib/cimi/service/volume.rb +81 -0
- data/lib/cimi/service/volume_configuration.rb +92 -0
- data/lib/cimi/service/volume_configuration_create.rb +29 -0
- data/lib/cimi/service/volume_create.rb +47 -0
- data/lib/cimi/service/volume_image.rb +44 -0
- data/lib/cimi/service/volume_image_create.rb +42 -0
- data/lib/cimi/service/volume_template.rb +61 -0
- data/lib/cimi/service/volume_template_create.rb +29 -0
- data/lib/db/entity.rb +16 -1
- data/lib/deltacloud/collections/addresses.rb +2 -2
- data/lib/deltacloud/collections/buckets.rb +16 -18
- data/lib/deltacloud/collections/drivers.rb +4 -4
- data/lib/deltacloud/collections/firewalls.rb +5 -5
- data/lib/deltacloud/collections/images.rb +3 -3
- data/lib/deltacloud/collections/instance_states.rb +4 -4
- data/lib/deltacloud/collections/instances.rb +22 -13
- data/lib/deltacloud/collections/keys.rb +2 -2
- data/lib/deltacloud/collections/load_balancers.rb +16 -13
- data/lib/deltacloud/collections/storage_snapshots.rb +3 -3
- data/lib/deltacloud/collections/storage_volumes.rb +5 -5
- data/lib/deltacloud/core_ext/ordered_hash.rb +0 -4
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +8 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +4 -3
- data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +266 -19
- data/lib/deltacloud/drivers/google/google_driver.rb +6 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +2 -2
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +166 -54
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +2 -0
- data/lib/deltacloud/helpers/blob_stream_helper.rb +0 -2
- data/lib/deltacloud/helpers/deltacloud_helper.rb +22 -22
- data/lib/deltacloud/helpers/driver_helper.rb +4 -7
- data/lib/deltacloud/helpers/rabbit_helper.rb +5 -0
- data/lib/deltacloud/server.rb +4 -4
- data/lib/deltacloud/version.rb +1 -1
- data/lib/deltacloud_rack.rb +6 -1
- data/lib/ec2/server.rb +6 -1
- data/tests/cimi/collections/common.rb +33 -0
- data/tests/cimi/collections/machines_test.rb +19 -0
- data/tests/cimi/collections/system_templates_test.rb +47 -0
- data/tests/cimi/collections/volumes_test.rb +42 -0
- data/tests/cimi/db/database_helper_test.rb +7 -4
- data/tests/deltacloud/drivers_test.rb +1 -1
- data/tests/drivers/ec2/common.rb +4 -1
- data/tests/drivers/fgcp/common.rb +1 -2
- data/tests/drivers/gogrid/common.rb +1 -2
- data/tests/drivers/google/common.rb +1 -1
- data/tests/drivers/models/address_test.rb +2 -2
- data/tests/drivers/models/base_test.rb +2 -2
- data/tests/drivers/models/blob_test.rb +2 -2
- data/tests/drivers/models/instance_address_test.rb +8 -8
- data/tests/drivers/models/instance_profile_test.rb +2 -2
- data/tests/drivers/models/keys_test.rb +4 -4
- data/tests/drivers/models/metrics_test.rb +3 -3
- data/tests/drivers/openstack/common.rb +1 -2
- data/views/addresses/_address.html.haml +3 -3
- data/views/addresses/associate.html.haml +3 -3
- data/views/addresses/index.html.haml +2 -2
- data/views/addresses/index.xml.haml +2 -2
- data/views/addresses/show.html.haml +7 -7
- data/views/addresses/show.xml.haml +9 -9
- data/views/api/show.html.haml +2 -2
- data/views/api/show.xml.haml +1 -1
- data/views/blobs/new.html.haml +1 -1
- data/views/blobs/show.html.haml +8 -8
- data/views/blobs/show.xml.haml +7 -7
- data/views/buckets/index.html.haml +1 -1
- data/views/buckets/index.xml.haml +2 -2
- data/views/buckets/show.html.haml +7 -7
- data/views/buckets/show.xml.haml +6 -6
- data/views/drivers/index.html.haml +1 -1
- data/views/drivers/index.xml.haml +1 -1
- data/views/drivers/show.html.haml +6 -6
- data/views/drivers/show.xml.haml +5 -5
- data/views/error.html.haml +2 -2
- data/views/errors/backend_capability_failure.xml.haml +3 -3
- data/views/errors/common.html.haml +7 -7
- data/views/errors/common.xml.haml +5 -5
- data/views/firewalls/index.html.haml +1 -1
- data/views/firewalls/index.xml.haml +1 -1
- data/views/firewalls/new_rule.html.haml +1 -1
- data/views/firewalls/show.html.haml +8 -8
- data/views/firewalls/show.xml.haml +9 -9
- data/views/hardware_profiles/index.html.haml +1 -1
- data/views/hardware_profiles/index.xml.haml +2 -2
- data/views/hardware_profiles/show.html.haml +3 -3
- data/views/hardware_profiles/show.xml.haml +4 -4
- data/views/images/index.html.haml +1 -1
- data/views/images/index.xml.haml +2 -2
- data/views/images/new.html.haml +2 -2
- data/views/images/show.html.haml +14 -14
- data/views/images/show.xml.haml +14 -14
- data/views/instance_states/show.html.haml +1 -1
- data/views/instance_states/show.png.erb +2 -2
- data/views/instance_states/show.xml.haml +1 -1
- data/views/instances/index.html.haml +1 -1
- data/views/instances/index.xml.haml +2 -2
- data/views/instances/new.html.haml +22 -14
- data/views/instances/run.html.haml +2 -2
- data/views/instances/run.xml.haml +3 -3
- data/views/instances/run_command.html.haml +4 -4
- data/views/instances/show.html.haml +27 -27
- data/views/instances/show.xml.haml +37 -37
- data/views/keys/index.html.haml +1 -1
- data/views/keys/index.xml.haml +2 -2
- data/views/keys/show.html.haml +10 -10
- data/views/keys/show.xml.haml +12 -12
- data/views/load_balancers/index.html.haml +1 -1
- data/views/load_balancers/index.xml.haml +2 -2
- data/views/load_balancers/new.html.haml +1 -8
- data/views/load_balancers/show.html.haml +10 -10
- data/views/load_balancers/show.xml.haml +9 -9
- data/views/metrics/index.html.haml +1 -1
- data/views/metrics/index.xml.haml +2 -2
- data/views/metrics/show.html.haml +2 -2
- data/views/metrics/show.xml.haml +3 -3
- data/views/realms/index.html.haml +1 -1
- data/views/realms/index.xml.haml +2 -2
- data/views/realms/show.html.haml +6 -6
- data/views/realms/show.xml.haml +5 -5
- data/views/storage_snapshots/index.html.haml +1 -1
- data/views/storage_snapshots/index.xml.haml +2 -2
- data/views/storage_snapshots/show.html.haml +6 -6
- data/views/storage_snapshots/show.xml.haml +4 -4
- data/views/storage_volumes/attach.html.haml +2 -2
- data/views/storage_volumes/index.html.haml +1 -1
- data/views/storage_volumes/index.xml.haml +2 -2
- data/views/storage_volumes/show.html.haml +19 -19
- data/views/storage_volumes/show.xml.haml +21 -21
- metadata +77 -65
- data/views/cimi/cloudEntryPoint/index.html.haml +0 -5
- data/views/cimi/cloudEntryPoint/index.xml.haml +0 -9
- data/views/cimi/collection/index.html.haml +0 -45
- data/views/cimi/collection/response.xml.haml +0 -3
- data/views/cimi/error.html.haml +0 -31
- data/views/cimi/errors/400.xml.haml +0 -3
- data/views/cimi/errors/401.xml.haml +0 -2
- data/views/cimi/errors/403.xml.haml +0 -2
- data/views/cimi/errors/404.xml.haml +0 -2
- data/views/cimi/errors/405.xml.haml +0 -5
- data/views/cimi/errors/500.xml.haml +0 -6
- data/views/cimi/errors/502.xml.haml +0 -7
- data/views/cimi/layout.html.haml +0 -32
- data/views/cimi/machine_configurations/show.html.haml +0 -159
- data/views/cimi/machine_configurations/show.xml.haml +0 -27
- data/views/cimi/machine_images/show.html.haml +0 -79
- data/views/cimi/machine_images/show.xml.haml +0 -17
- data/views/cimi/machines/show.html.haml +0 -177
- data/views/cimi/machines/show.xml.haml +0 -28
- data/views/cimi/volumes/show.html.haml +0 -68
- data/views/cimi/volumes/show.xml.haml +0 -17
- data/views/docs/collection.html.haml +0 -26
- data/views/docs/collection.xml.haml +0 -14
- data/views/docs/index.html.haml +0 -11
- data/views/docs/index.xml.haml +0 -5
- data/views/docs/operation.html.haml +0 -33
- data/views/docs/operation.xml.haml +0 -10
- data/views/root/index.html.haml +0 -4
@@ -0,0 +1,34 @@
|
|
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::Service::AddressTemplateCreate < CIMI::Service::Base
|
17
|
+
|
18
|
+
def create
|
19
|
+
new_template = context.current_db.add_address_template(
|
20
|
+
:name => name,
|
21
|
+
:description => description,
|
22
|
+
:hostname => hostname,
|
23
|
+
:ip => ip,
|
24
|
+
:allocation => allocation,
|
25
|
+
:default_gateway => default_gateway,
|
26
|
+
:dns => dns,
|
27
|
+
:protocol => protocol,
|
28
|
+
:mask => mask,
|
29
|
+
:ent_properties => property.to_json
|
30
|
+
)
|
31
|
+
CIMI::Service::AddressTemplate.from_db(new_template, context)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,266 @@
|
|
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
|
+
require 'xmlsimple'
|
17
|
+
|
18
|
+
require_relative '../helpers/database_helper'
|
19
|
+
|
20
|
+
# Service objects implement the server functionality of CIMI resources; in
|
21
|
+
# particular, these objects are responsible for interacting with the
|
22
|
+
# current driver. They use the CIMI::Model objects for (de)serialization
|
23
|
+
module CIMI::Service
|
24
|
+
|
25
|
+
class Base
|
26
|
+
|
27
|
+
# Extend the base model with database methods
|
28
|
+
extend Deltacloud::Helpers::Database
|
29
|
+
|
30
|
+
attr_reader :model, :context
|
31
|
+
|
32
|
+
class << self
|
33
|
+
def model_class
|
34
|
+
CIMI::Model.const_get(name.split('::').last)
|
35
|
+
end
|
36
|
+
|
37
|
+
def model_name
|
38
|
+
name.split('::').last.underscore.to_sym
|
39
|
+
end
|
40
|
+
|
41
|
+
def collection_name
|
42
|
+
name.split('::').last.underscore.pluralize.to_sym
|
43
|
+
end
|
44
|
+
|
45
|
+
def inherited(subclass)
|
46
|
+
# Decorate all the attributes of the model class
|
47
|
+
schema = subclass.model_class.schema
|
48
|
+
schema.attribute_names.each do |name|
|
49
|
+
define_method(name) { self[name] }
|
50
|
+
define_method(:"#{name}=") { |newval| self[name] = newval }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse(context)
|
55
|
+
req = context.request
|
56
|
+
model = model_class.parse(req.body, req.content_type)
|
57
|
+
new(context, :model => model)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def initialize(context, opts)
|
63
|
+
if opts[:values]
|
64
|
+
@model = model_class.new(opts[:values])
|
65
|
+
elsif opts[:model]
|
66
|
+
@model = opts[:model]
|
67
|
+
else
|
68
|
+
@model = model_class.new({})
|
69
|
+
end
|
70
|
+
@context = context
|
71
|
+
retrieve_entity
|
72
|
+
end
|
73
|
+
|
74
|
+
def model_class
|
75
|
+
self.class.model_class
|
76
|
+
end
|
77
|
+
|
78
|
+
# Decorate some model methods
|
79
|
+
def []=(a, v)
|
80
|
+
v = (@model[a] = v)
|
81
|
+
retrieve_entity if a == :id
|
82
|
+
v
|
83
|
+
end
|
84
|
+
|
85
|
+
def [](a)
|
86
|
+
@model[a]
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_xml
|
90
|
+
@model.to_xml
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_json
|
94
|
+
@model.to_json
|
95
|
+
end
|
96
|
+
|
97
|
+
def select_attributes(attr_list)
|
98
|
+
@model.select_attributes(attr_list)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Lookup a reference and return the corresponding model
|
102
|
+
def resolve(ref)
|
103
|
+
self.class.resolve(ref, context)
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.resolve(ref, ctx)
|
107
|
+
model = nil
|
108
|
+
if ref.href?
|
109
|
+
name = ref.class.superclass.name.split('::').last
|
110
|
+
service_class = CIMI::Service::const_get(name)
|
111
|
+
id = ref.href.split('/').last
|
112
|
+
model = service_class.find(id, ctx)
|
113
|
+
else
|
114
|
+
# FIXME: if ref.href? we need to overwrite
|
115
|
+
# attributes in model with ones from ref as long as they are present
|
116
|
+
model = ref
|
117
|
+
end
|
118
|
+
model
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.list(ctx)
|
122
|
+
id = ctx.send("#{collection_name}_url")
|
123
|
+
entries = find(:all, ctx)
|
124
|
+
params = {}
|
125
|
+
params[:desc] = "#{self.name.split("::").last} Collection for the #{ctx.driver.name.capitalize} driver"
|
126
|
+
params[:add_url] = create_url(ctx)
|
127
|
+
model_class.list(id, entries, params).select_by(ctx.params['$select']).filter_by(ctx.params['$filter'])
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.create_url(ctx)
|
131
|
+
cimi_create = "create_#{model_name}_url"
|
132
|
+
dcloud_create = ctx.deltacloud_create_method_for(model_name)
|
133
|
+
if(ctx.respond_to?(cimi_create) &&
|
134
|
+
ctx.driver.respond_to?(dcloud_create)) || provides?(model_name)
|
135
|
+
ctx.send(cimi_create)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# Resource metadata
|
141
|
+
#
|
142
|
+
METADATA_TYPES = [ 'text', 'URI', 'string', 'boolean' ]
|
143
|
+
|
144
|
+
# A hash of the attributes that need to be mentioned in the given
|
145
|
+
# context
|
146
|
+
def self.resource_attributes(context)
|
147
|
+
metadata.keys.map do |k|
|
148
|
+
a = model_class.schema.attributes.find { |a| a.name == k }
|
149
|
+
raise "No attribute named #{k} defined" unless a
|
150
|
+
constr = metadata[k][:constraints].call(context)
|
151
|
+
{
|
152
|
+
:name => a.name,
|
153
|
+
:namespace => "http://deltacloud.org/cimi/#{model_name}/#{a.name}",
|
154
|
+
:type => metadata[k][:type],
|
155
|
+
:required => a.required? ? 'true' : 'false',
|
156
|
+
:constraints => constr.map { |v| { :value => v } }
|
157
|
+
}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.resource_capabilities(context)
|
162
|
+
cimi_object = model_name.to_s.pluralize.to_sym
|
163
|
+
driver_class = context.driver.class
|
164
|
+
(driver_class.features[cimi_object] || []).map do |cur|
|
165
|
+
feat = CIMI::FakeCollection.feature(cur)
|
166
|
+
values = driver_class.constraints[cimi_object][feat.name][:values] || []
|
167
|
+
{ :name => feat.name.to_s.camelize,
|
168
|
+
:uri => CMWG_NAMESPACE+"/capability/#{cimi_object.to_s.camelize.singularize}/#{feat.name.to_s.camelize}",
|
169
|
+
:description => feat.description,
|
170
|
+
:value => values.join(",")
|
171
|
+
}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Define the metadata for an attribute; +opts+ must be a Hash that can
|
176
|
+
# contain the following entries:
|
177
|
+
# :type : one of METADATA_TYPES
|
178
|
+
# :constraints : a proc that is passed the current context and
|
179
|
+
# must return a list of values
|
180
|
+
def self.metadata(attr_name = nil, opts = nil)
|
181
|
+
@metadata ||= {}
|
182
|
+
return @metadata if attr_name.nil? && opts.nil?
|
183
|
+
|
184
|
+
opts[:type] ||= 'text'
|
185
|
+
opts[:type] = opts[:type].to_s
|
186
|
+
opts[:constraints] ||= lambda { |_| [] }
|
187
|
+
unless METADATA_TYPES.include?(opts[:type])
|
188
|
+
raise "Metadata type must be one of #{METADATA_TYPES.join(",")}"
|
189
|
+
end
|
190
|
+
metadata[attr_name] = opts
|
191
|
+
end
|
192
|
+
|
193
|
+
#
|
194
|
+
# Database interactions
|
195
|
+
#
|
196
|
+
|
197
|
+
# Save the common attributes name, description, and properties to the
|
198
|
+
# database
|
199
|
+
def save
|
200
|
+
if @entity
|
201
|
+
before_save
|
202
|
+
@entity.save
|
203
|
+
end
|
204
|
+
self
|
205
|
+
end
|
206
|
+
|
207
|
+
# Destroy the database attributes for this model
|
208
|
+
def destroy
|
209
|
+
@entity.destroy
|
210
|
+
self
|
211
|
+
end
|
212
|
+
|
213
|
+
# FIXME: Kludge around the fact that we do not have proper *Create
|
214
|
+
# objects that deserialize properties by themselves
|
215
|
+
def extract_properties!(data)
|
216
|
+
h = {}
|
217
|
+
if data['property']
|
218
|
+
# Data came from XML
|
219
|
+
h = data['property'].inject({}) do |r,v|
|
220
|
+
r[v['key']] = v['content']
|
221
|
+
r
|
222
|
+
end
|
223
|
+
elsif data['properties']
|
224
|
+
h = data['properties']
|
225
|
+
end
|
226
|
+
property ||= {}
|
227
|
+
property.merge!(h)
|
228
|
+
end
|
229
|
+
|
230
|
+
def ref_id(ref_url)
|
231
|
+
ref_url.split('/').last if ref_url
|
232
|
+
end
|
233
|
+
|
234
|
+
protected
|
235
|
+
|
236
|
+
def attributes_to_copy
|
237
|
+
[:name, :description]
|
238
|
+
end
|
239
|
+
|
240
|
+
def before_save
|
241
|
+
attributes_to_copy.each { |a| @entity[a] = @model[a] }
|
242
|
+
@entity.properties = @model.property
|
243
|
+
end
|
244
|
+
|
245
|
+
def after_retrieve
|
246
|
+
attributes_to_copy.each { |a| @model[a] = @entity[a] }
|
247
|
+
@model.property ||= {}
|
248
|
+
@model.property.merge!(@entity.properties)
|
249
|
+
end
|
250
|
+
|
251
|
+
private
|
252
|
+
|
253
|
+
# Load an existing database entity for this object, or create a new one
|
254
|
+
def retrieve_entity
|
255
|
+
if self.id
|
256
|
+
@entity = Deltacloud::Database::Entity::retrieve(@model)
|
257
|
+
if @entity.exists?
|
258
|
+
after_retrieve
|
259
|
+
end
|
260
|
+
else
|
261
|
+
@entity = nil
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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::Service::CloudEntryPoint < CIMI::Service::Base
|
17
|
+
|
18
|
+
metadata :driver, :type => 'text'
|
19
|
+
metadata :provider, :type => 'text'
|
20
|
+
|
21
|
+
def self.create(context)
|
22
|
+
self.new(context, :values => entities(context).merge({
|
23
|
+
:name => context.driver.name,
|
24
|
+
:description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
|
25
|
+
:driver => context.driver.name,
|
26
|
+
:provider => context.current_provider,
|
27
|
+
:id => context.cloudEntryPoint_url,
|
28
|
+
:base_uri => context.base_uri + "/",
|
29
|
+
:created => Time.now.xmlschema
|
30
|
+
}))
|
31
|
+
end
|
32
|
+
|
33
|
+
# Return an Hash of the CIMI root entities used in CloudEntryPoint
|
34
|
+
def self.entities(context)
|
35
|
+
CIMI::Collections.modules(:cimi).inject({}) do |supported_entities, m|
|
36
|
+
m.collections.each do |c|
|
37
|
+
if c.operation(:index).nil?
|
38
|
+
warn "#{c} does not have :index operation."
|
39
|
+
next
|
40
|
+
end
|
41
|
+
index_operation_capability = c.operation(:index).required_capability
|
42
|
+
next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability)
|
43
|
+
supported_entities[c.collection_name.to_s] = { :href => context.send(:"#{c.collection_name}_url") }
|
44
|
+
end
|
45
|
+
supported_entities
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def entities
|
50
|
+
@attribute_values.clone.delete_if { |key, value| !value.respond_to? :href }
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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::Service::Credential < CIMI::Service::Base
|
17
|
+
|
18
|
+
def self.find(id, context)
|
19
|
+
if id == :all
|
20
|
+
return [] unless context.driver.respond_to?(:keys)
|
21
|
+
keys = context.driver.keys(context.credentials)
|
22
|
+
keys.map { |key| from_key(key, context) }
|
23
|
+
else
|
24
|
+
key = context.driver.key(context.credentials, :id => id)
|
25
|
+
from_key(key, context)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.create_from_xml(body, context)
|
30
|
+
credential = Credential.from_xml(body)
|
31
|
+
key = context.driver.create_key(context.credentials, :key_name => credential.name)
|
32
|
+
from_key(key, context)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.delete!(id, context)
|
36
|
+
context.driver.destroy_key(context.credentials, :id => id)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.from_key(key, context)
|
42
|
+
self.new(context, :values => {
|
43
|
+
:name => key.id,
|
44
|
+
:username => key.username,
|
45
|
+
:password => key.is_password? ? key.password : key.fingerprint,
|
46
|
+
:key => key.is_key? ? key.pem_rsa_key : nil,
|
47
|
+
:id => context.credential_url(key.id),
|
48
|
+
:created => Time.now.xmlschema
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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::Service::CredentialCreate < CIMI::Service::Base
|
17
|
+
|
18
|
+
def create
|
19
|
+
unless context.driver.respond_to? :create_key
|
20
|
+
raise Deltacloud::Exceptions.exception_from_status(
|
21
|
+
501,
|
22
|
+
"Creating Credential is not supported by the current driver"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
template = resolve(credential_template)
|
27
|
+
|
28
|
+
key = context.driver.create_key(context.credentials, :key_name => name)
|
29
|
+
|
30
|
+
result = CIMI::Service::Credential.from_key(key, context)
|
31
|
+
result.name = name if name
|
32
|
+
result.description = description if description
|
33
|
+
result.property = property if property
|
34
|
+
result.save
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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::Service::CredentialTemplate < CIMI::Service::Base
|
17
|
+
|
18
|
+
# FIXME: TBD
|
19
|
+
|
20
|
+
end
|