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
@@ -22,69 +22,4 @@ class CIMI::Model::MachineVolume < CIMI::Model::Base
|
|
22
22
|
scalar :rel, :href
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.find(instance_id, context, id=:all)
|
26
|
-
if id == :all
|
27
|
-
volumes = context.driver.storage_volumes(context.credentials)
|
28
|
-
volumes.inject([]) do |attached, vol|
|
29
|
-
id = context.machine_url(instance_id)+"/volumes/#{vol.id}"
|
30
|
-
attached << self.new(
|
31
|
-
:id => id,
|
32
|
-
:name => vol.id,
|
33
|
-
:description => "MachineVolume #{vol.id} for Machine #{instance_id}",
|
34
|
-
:created => vol.created.nil? ? nil : Time.parse(vol.created).xmlschema,
|
35
|
-
:initial_location => vol.device,
|
36
|
-
:volume => {:href=>context.volume_url(vol.id)},
|
37
|
-
:operations => [{:href=>id, :rel => "delete" }]
|
38
|
-
) if vol.instance_id == instance_id
|
39
|
-
attached
|
40
|
-
end
|
41
|
-
else
|
42
|
-
vol = context.driver.storage_volume(context.credentials, {:id=>id})
|
43
|
-
id = context.machine_url(instance_id)+"/volumes/#{vol.id}"
|
44
|
-
raise CIMI::Model::NotFound unless vol.instance_id == instance_id
|
45
|
-
self.new(
|
46
|
-
:id => id,
|
47
|
-
:name => vol.id,
|
48
|
-
:description => "MachineVolume #{vol.id} for Machine #{instance_id}",
|
49
|
-
:created => vol.created.nil? ? nil : Time.parse(vol.created).xmlschema,
|
50
|
-
:initial_location => vol.device,
|
51
|
-
:volume => {:href=>context.volume_url(vol.id)},
|
52
|
-
:operations => [{:href=>id, :rel => "delete" }]
|
53
|
-
)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.find_to_attach_from_xml(xml_in, context)
|
58
|
-
xml = XmlSimple.xml_in(xml_in)
|
59
|
-
vol_id = xml["volume"].first["href"].split("/").last
|
60
|
-
location = xml["initialLocation"].first.strip
|
61
|
-
[vol_id, location]
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.find_to_attach_from_json(json_in, context)
|
65
|
-
json = JSON.parse(json_in)
|
66
|
-
vol_id = json["volume"]["href"].split("/").last
|
67
|
-
location = json["initialLocation"]
|
68
|
-
[vol_id, location]
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def self.collection_for_instance(instance_id, context)
|
73
|
-
machine_volumes = self.find(instance_id, context)
|
74
|
-
volumes_url = context.url("/machines/#{instance_id}/volumes")
|
75
|
-
unless CIMI::Model.const_defined?('MachineVolumeCollection')
|
76
|
-
collection_class = CIMI::Model::Collection.generate(self)
|
77
|
-
else
|
78
|
-
collection_class = CIMI::Model::MachineVolumeCollection
|
79
|
-
end
|
80
|
-
collection_class.new(
|
81
|
-
:id => volumes_url,
|
82
|
-
:name => 'default',
|
83
|
-
:count => machine_volumes.size,
|
84
|
-
:description => "Volume collection for Machine #{instance_id}",
|
85
|
-
:entries => machine_volumes,
|
86
|
-
:operations => [{ :href => volumes_url.singularize+"_attach", :rel => "add" }]
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
25
|
end
|
data/lib/cimi/models/network.rb
CHANGED
@@ -37,36 +37,4 @@ class CIMI::Model::Network < CIMI::Model::Base
|
|
37
37
|
scalar :rel, :href
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.find(id, context)
|
41
|
-
networks=[]
|
42
|
-
if id==:all
|
43
|
-
networks = context.driver.networks(context.credentials, {:env=>context})
|
44
|
-
else
|
45
|
-
networks = context.driver.networks(context.credentials, {:id=>id, :env=>context})
|
46
|
-
end
|
47
|
-
if context.expand? :networkPorts
|
48
|
-
networks.each do |network|
|
49
|
-
network.network_ports = CIMI::Model::NetworkPort.collection_for_network(network.id, context)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
networks
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
def self.delete!(id, context)
|
57
|
-
context.driver.delete_network(context.credentials, id)
|
58
|
-
end
|
59
|
-
|
60
|
-
def perform(action, context, &block)
|
61
|
-
begin
|
62
|
-
if context.driver.send(:"#{action.name}_network", context.credentials, self.name)
|
63
|
-
block.callback :success
|
64
|
-
else
|
65
|
-
raise "Operation #{action.name} failed to execute on the Network #{self.name} "
|
66
|
-
end
|
67
|
-
rescue => e
|
68
|
-
block.callback :failure, e.message
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
40
|
end
|
@@ -27,19 +27,4 @@ class CIMI::Model::NetworkConfiguration < CIMI::Model::Base
|
|
27
27
|
scalar :rel, :href
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.find(id, context)
|
31
|
-
network_configs = []
|
32
|
-
if id==:all
|
33
|
-
network_configs = context.driver.network_configurations(context.credentials, {:env=>context})
|
34
|
-
else
|
35
|
-
network_configs = context.driver.network_configurations(context.credentials, {:env=>context, :id=>id})
|
36
|
-
end
|
37
|
-
network_configs
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.create_from_xml(request_body, context)
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.create_from_json(request_body, context)
|
44
|
-
end
|
45
30
|
end
|
@@ -17,27 +17,4 @@ class CIMI::Model::NetworkCreate < CIMI::Model::Base
|
|
17
17
|
|
18
18
|
ref :network_template, :required => true
|
19
19
|
|
20
|
-
def create(context)
|
21
|
-
validate!
|
22
|
-
if network_template.href?
|
23
|
-
template = network_template.find(context)
|
24
|
-
network_config = template.network_config.find(context)
|
25
|
-
forwarding_group = template.forwarding_group.find(context)
|
26
|
-
else
|
27
|
-
network_config = CIMI::Model::NetworkConfiguration.find(context.href_id(network_template.network_config.href, :network_configurations), context)
|
28
|
-
forwarding_group = CIMI::Model::ForwardingGroup.find(context.href_id(network_template.forwarding_group.href, :forwarding_groups), context)
|
29
|
-
end
|
30
|
-
params = {
|
31
|
-
:network_config => network_config,
|
32
|
-
:forwarding_group => forwarding_group,
|
33
|
-
:name => name,
|
34
|
-
:description => description,
|
35
|
-
:env => context # FIXME: We should not pass the context to the driver (!)
|
36
|
-
}
|
37
|
-
network = context.driver.create_network(context.credentials, params)
|
38
|
-
network.property = property if property
|
39
|
-
network.save
|
40
|
-
network
|
41
|
-
end
|
42
|
-
|
43
20
|
end
|
@@ -33,77 +33,4 @@ class CIMI::Model::NetworkPort < CIMI::Model::Base
|
|
33
33
|
scalar :rel, :href
|
34
34
|
end
|
35
35
|
|
36
|
-
def self.find(id, context)
|
37
|
-
if id==:all
|
38
|
-
context.driver.network_ports(context.credentials, {:env=>context})
|
39
|
-
else
|
40
|
-
context.driver.network_ports(context.credentials, {:id=>id, :env=>context})
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.create(request_body, context, type)
|
45
|
-
input = (type == :xml)? XmlSimple.xml_in(request_body, {"ForceArray"=>false, "NormaliseSpace"=>2}) : JSON.parse(request_body)
|
46
|
-
if input["networkPortTemplate"]["href"] #template by reference
|
47
|
-
network_port_config, network = get_by_reference(input, context)
|
48
|
-
else
|
49
|
-
if input["networkPortTemplate"]["networkPortConfig"]["href"] # configuration by reference
|
50
|
-
network_port_config = CIMI::Model::NetworkPortConfiguration.find(context.href_id(input["networkPortTemplate"]["networkPortConfig"]["href"],:network_port_configurations), context)
|
51
|
-
else #configuration by value
|
52
|
-
network_port_config = get_by_value(request_body, type)
|
53
|
-
end
|
54
|
-
network = CIMI::Model::Network.find(context.href_id(input["networkPortTemplate"]["network"]["href"], :networks), context)
|
55
|
-
end
|
56
|
-
params = {:network_port_config => network_port_config, :network => network, :name=>input["name"], :description=>input["description"], :env=>context}
|
57
|
-
raise CIMI::Model::BadRequest.new("Bad request - missing required parameters. Client sent: #{request_body} which produced #{params.inspect}") if params.has_value?(nil)
|
58
|
-
context.driver.create_network_port(context.credentials, params)
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.delete!(id, context)
|
62
|
-
context.driver.delete_network_port(context.credentials, id)
|
63
|
-
end
|
64
|
-
|
65
|
-
def perform(action, context, &block)
|
66
|
-
begin
|
67
|
-
if context.driver.send(:"#{action.name}_network_port", context.credentials, self.name)
|
68
|
-
block.callback :success
|
69
|
-
else
|
70
|
-
raise "Operation #{action.name} failed to execute on the NetworkPort #{self.name} "
|
71
|
-
end
|
72
|
-
rescue => e
|
73
|
-
block.callback :failure, e.message
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.collection_for_network(network_id, context)
|
78
|
-
net_url = context.network_url(network_id)
|
79
|
-
network_ports = CIMI::Model::NetworkPort.all(context)
|
80
|
-
ports_collection = network_ports.inject([]){|res, current| res << current if current.network.href == net_url ; res}
|
81
|
-
CIMI::Model::NetworkPortCollection.new(
|
82
|
-
:id => net_url+"/network_ports",
|
83
|
-
:name => 'default',
|
84
|
-
:created => Time.now,
|
85
|
-
:description => "#{context.driver.name.capitalize} NetworkPortCollection",
|
86
|
-
:count => ports_collection.size,
|
87
|
-
:network_ports => ports_collection
|
88
|
-
)
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
def self.get_by_reference(input, context)
|
94
|
-
network_port_template = CIMI::Model::NetworkPortTemplate.find(context.href_id(input["networkPortTemplate"]["href"], :network_port_templates), context)
|
95
|
-
network_port_config = CIMI::Model::NetworkPortConfiguration.find(context.href_id(network_port_template.network_port_config.href, :network_port_configurations), context)
|
96
|
-
network = CIMI::Model::Network.find(context.href_id(network_port_template.network.href, :networks), context)
|
97
|
-
return network_port_config, network
|
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_port_config = CIMI::Model::NetworkPortConfiguration.from_xml(XmlSimple.xml_out(xml_arrays["networkPortTemplate"][0]["networkPortConfig"][0]))
|
104
|
-
else
|
105
|
-
json = JSON.parse(request_body)
|
106
|
-
network_port_config = CIMI::Model::NetworkPortConfiguration.from_json(JSON.generate(json["networkPortTemplate"]["networkPortConfig"]))
|
107
|
-
end
|
108
|
-
end
|
109
36
|
end
|
@@ -25,12 +25,4 @@ class CIMI::Model::NetworkPortConfiguration < CIMI::Model::Base
|
|
25
25
|
scalar :rel, :href
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.find(id, context)
|
29
|
-
if id==:all
|
30
|
-
context.driver.network_port_configurations(context.credentials, {:env=>context})
|
31
|
-
else
|
32
|
-
context.driver.network_port_configurations(context.credentials, {:env=>context, :id=>id})
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
28
|
end
|
@@ -25,12 +25,4 @@ class CIMI::Model::NetworkPortTemplate < CIMI::Model::Base
|
|
25
25
|
scalar :rel, :href
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.find(id, context)
|
29
|
-
if id==:all
|
30
|
-
context.driver.network_port_templates(context.credentials, {:env=>context})
|
31
|
-
else
|
32
|
-
context.driver.network_port_templates(context.credentials, {:env=>context, :id=>id})
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
28
|
end
|
@@ -17,21 +17,11 @@ class CIMI::Model::NetworkTemplate < CIMI::Model::Base
|
|
17
17
|
|
18
18
|
acts_as_root_entity
|
19
19
|
|
20
|
-
ref :network_config, :
|
21
|
-
ref :forwarding_group, :
|
20
|
+
ref :network_config, :class => CIMI::Model::NetworkConfiguration
|
21
|
+
ref :forwarding_group, :class => CIMI::Model::ForwardingGroup
|
22
22
|
|
23
23
|
array :operations do
|
24
24
|
scalar :rel, :href
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.find(id, context)
|
28
|
-
network_templates = []
|
29
|
-
if id==:all
|
30
|
-
network_templates = context.driver.network_templates(context.credentials, {:env=>context})
|
31
|
-
else
|
32
|
-
network_templates = context.driver.network_templates(context.credentials, {:env=>context, :id=>id})
|
33
|
-
end
|
34
|
-
network_templates
|
35
|
-
end
|
36
|
-
|
37
27
|
end
|
data/lib/cimi/models/resource.rb
CHANGED
@@ -89,12 +89,6 @@ module CIMI
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
# Return Array of links to current CIMI object
|
93
|
-
#
|
94
|
-
def all_uri(context)
|
95
|
-
self.all(context).map { |e| { :href => e.id } }
|
96
|
-
end
|
97
|
-
|
98
92
|
# Construct a new object from the XML representation +xml+
|
99
93
|
def from_xml(text)
|
100
94
|
xml = XmlSimple.xml_in(text, :force_content => true)
|
@@ -16,6 +16,7 @@
|
|
16
16
|
|
17
17
|
class CIMI::Model::ResourceMetadata < CIMI::Model::Base
|
18
18
|
|
19
|
+
# FIXME: Is this property really needed? (Base model include 'name'
|
19
20
|
text :name
|
20
21
|
|
21
22
|
text :type_uri
|
@@ -50,99 +51,4 @@ class CIMI::Model::ResourceMetadata < CIMI::Model::Base
|
|
50
51
|
array :operations do
|
51
52
|
scalar :rel, :href
|
52
53
|
end
|
53
|
-
|
54
|
-
def self.find(id, context)
|
55
|
-
if id == :all
|
56
|
-
resource_metadata = []
|
57
|
-
CIMI::Model.root_entities.each do |resource_class|
|
58
|
-
meta = resource_metadata_for(resource_class, context)
|
59
|
-
resource_metadata << meta unless none_defined(meta)
|
60
|
-
end
|
61
|
-
return resource_metadata
|
62
|
-
else
|
63
|
-
resource_class = CIMI::Model.const_get("#{id.camelize}")
|
64
|
-
resource_metadata_for(resource_class, context)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.resource_metadata_for(resource_class, context)
|
69
|
-
attributes = rm_attributes_for(resource_class, context)
|
70
|
-
capabilities = rm_capabilities_for(resource_class, context)
|
71
|
-
actions = rm_actions_for(resource_class, context)
|
72
|
-
cimi_resource = resource_class.name.split("::").last
|
73
|
-
self.new({ :id => context.resource_metadata_url(cimi_resource.underscore),
|
74
|
-
:name => cimi_resource,
|
75
|
-
:type_uri => resource_class.resource_uri,
|
76
|
-
:attributes => attributes,
|
77
|
-
:capabilities => capabilities,
|
78
|
-
:actions => actions
|
79
|
-
})
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.resource_attributes
|
83
|
-
@resource_attributes ||= {}
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.add_resource_attribute!(klass, name, opts={})
|
87
|
-
resource_attributes[klass.name] ||= {}
|
88
|
-
resource_attributes[klass.name][name] = opts
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
def self.rm_attributes_for(resource_class, context)
|
94
|
-
return [] if resource_attributes[resource_class.name].nil?
|
95
|
-
resource_attributes[resource_class.name].map do |attr_name, attr_def|
|
96
|
-
if attr_def.has_key? :constraints
|
97
|
-
constraints = attr_def[:constraints].call(context)
|
98
|
-
else
|
99
|
-
constraints = []
|
100
|
-
end
|
101
|
-
{
|
102
|
-
:name => attr_name.to_s,
|
103
|
-
# TODO: We need to make this URI return description of this 'non-CIMI'
|
104
|
-
# attribute
|
105
|
-
:namespace => "http://deltacloud.org/cimi/#{resource_class.name.split('::').last}/#{attr_name}",
|
106
|
-
:type => translate_attr_type(attr_def[:type]),
|
107
|
-
:required => attr_def[:required] ? 'true' : 'false',
|
108
|
-
:constraints => constraints.map { |v| { :value => v }}
|
109
|
-
}
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.rm_capabilities_for(resource_class,context)
|
114
|
-
cimi_object = resource_class.name.split("::").last.underscore.pluralize.to_sym
|
115
|
-
capabilities = (context.driver.class.features[cimi_object] || []).inject([]) do |res, cur|
|
116
|
-
feat = CIMI::FakeCollection.feature(cur)
|
117
|
-
values = (context.driver.class.constraints[cimi_object][feat.name][:values] || []).inject([]) do |vals, val|
|
118
|
-
vals << val
|
119
|
-
vals
|
120
|
-
end
|
121
|
-
res << {:name => feat.name.to_s.camelize,
|
122
|
-
:uri => CMWG_NAMESPACE+"/capability/#{cimi_object.to_s.camelize.singularize}/#{feat.name.to_s.camelize}",
|
123
|
-
:description => feat.description,
|
124
|
-
:value => values.join(",") }
|
125
|
-
res
|
126
|
-
end
|
127
|
-
#cimi_resource.underscore.pluralize.to_sym
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.rm_actions_for(resource_class, context)
|
131
|
-
[]
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.translate_attr_type(type)
|
135
|
-
case type
|
136
|
-
when :href then 'URI'
|
137
|
-
when :text then 'string'
|
138
|
-
when :boolean then 'boolean'
|
139
|
-
else 'text'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def self.none_defined(metadata)
|
144
|
-
return true if metadata.capabilities.empty? && metadata.capabilities.empty? && metadata.attributes.empty?
|
145
|
-
return false
|
146
|
-
end
|
147
|
-
|
148
54
|
end
|
data/lib/cimi/models/schema.rb
CHANGED
@@ -124,12 +124,12 @@ class CIMI::Model::Schema
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def to_xml(model, xml)
|
127
|
-
conv = convert_to_xml(model
|
127
|
+
conv = convert_to_xml(extract(model))
|
128
128
|
xml[xml_name] = [conv] unless conv.empty?
|
129
129
|
end
|
130
130
|
|
131
131
|
def to_json(model, json)
|
132
|
-
conv = convert_to_json(model
|
132
|
+
conv = convert_to_json(extract(model))
|
133
133
|
json[json_name] = conv unless conv.empty?
|
134
134
|
end
|
135
135
|
|
@@ -179,6 +179,14 @@ class CIMI::Model::Schema
|
|
179
179
|
@struct_class ||= ::Struct.new(nil, *@schema.attribute_names)
|
180
180
|
end
|
181
181
|
end
|
182
|
+
def extract(model)
|
183
|
+
if model.respond_to?("[]")
|
184
|
+
model[name] || {}
|
185
|
+
else
|
186
|
+
{}
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
182
190
|
end
|
183
191
|
|
184
192
|
class Ref < CIMI::Model::Schema::Struct
|
@@ -191,20 +199,6 @@ class CIMI::Model::Schema
|
|
191
199
|
else
|
192
200
|
@klass = Class.new(opts[:class]) do |m|
|
193
201
|
scalar :href
|
194
|
-
|
195
|
-
def ref_id(ctx)
|
196
|
-
# FIXME: We should use ctx's routes to split
|
197
|
-
# out the :id
|
198
|
-
href.split('/').last
|
199
|
-
end
|
200
|
-
|
201
|
-
def find(ctx)
|
202
|
-
klass.find(ref_id(ctx), ctx)
|
203
|
-
end
|
204
|
-
|
205
|
-
def klass
|
206
|
-
self.class.superclass
|
207
|
-
end
|
208
202
|
end
|
209
203
|
CIMI::Model::const_set(refname, @klass)
|
210
204
|
end
|
@@ -282,13 +276,21 @@ class CIMI::Model::Schema
|
|
282
276
|
end
|
283
277
|
|
284
278
|
def to_xml(model, xml)
|
285
|
-
|
286
|
-
xml[xml_name] =
|
279
|
+
mapped = extract(model).map { |k, v| { "key" => k, "content" => v } }
|
280
|
+
xml[xml_name] = mapped unless mapped.empty?
|
287
281
|
end
|
288
282
|
|
289
283
|
def to_json(model, json)
|
290
|
-
|
291
|
-
|
284
|
+
h = extract(model)
|
285
|
+
json[json_name] = h unless h.empty?
|
286
|
+
end
|
287
|
+
|
288
|
+
private
|
289
|
+
def extract(model)
|
290
|
+
if model.respond_to?("[]")
|
291
|
+
model[name] || {}
|
292
|
+
else
|
293
|
+
{}
|
292
294
|
end
|
293
295
|
end
|
294
296
|
end
|
@@ -302,7 +304,10 @@ class CIMI::Model::Schema
|
|
302
304
|
raise "Specify the class of collection entries using :class"
|
303
305
|
end
|
304
306
|
params[:embedded] = true
|
305
|
-
|
307
|
+
unless opts[:class].collection_class
|
308
|
+
opts[:class].collection_class = CIMI::Model::Collection.generate(opts[:class], params)
|
309
|
+
end
|
310
|
+
@collection_class = opts[:class].collection_class
|
306
311
|
end
|
307
312
|
|
308
313
|
def from_xml(xml, model)
|
@@ -422,15 +427,6 @@ class CIMI::Model::Schema
|
|
422
427
|
# +add_attributes!+ method
|
423
428
|
module DSL
|
424
429
|
|
425
|
-
def resource_attr(name, opts={})
|
426
|
-
CIMI::Model::ResourceMetadata.add_resource_attribute!(self, name, opts)
|
427
|
-
if opts[:type]
|
428
|
-
send(opts[:type], name)
|
429
|
-
else
|
430
|
-
text name
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
430
|
def href(*args)
|
435
431
|
opts = args.extract_opts!
|
436
432
|
args.each { |arg| struct(arg, opts) { scalar :href, :required => opts[:required] } }
|
@@ -461,12 +457,12 @@ class CIMI::Model::Schema
|
|
461
457
|
add_attributes!([name, opts], Ref)
|
462
458
|
end
|
463
459
|
|
464
|
-
def
|
460
|
+
def hash_map(name)
|
465
461
|
add_attributes!([name, {}], Hash)
|
466
462
|
end
|
467
463
|
|
468
464
|
def collection(name, opts={})
|
469
|
-
opts[:scope] = self
|
465
|
+
opts[:scope] = self
|
470
466
|
add_attributes!([name, opts], Collection)
|
471
467
|
end
|
472
468
|
end
|