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
@@ -29,39 +29,268 @@ module Deltacloud::Drivers::Fgcp
|
|
29
29
|
def systems(credentials, opts={})
|
30
30
|
safely do
|
31
31
|
client = new_client(credentials)
|
32
|
+
xml = client.list_vsys['vsyss']
|
33
|
+
return [] if xml.nil?
|
34
|
+
context = opts[:env]
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
else
|
36
|
-
xml = client.list_vsys['vsyss']
|
37
|
-
return [] if xml.nil?
|
38
|
-
vsys_ids = xml[0]['vsys'].collect { |vsys| vsys['vsysId'][0] }
|
39
|
-
end
|
40
|
-
|
41
|
-
vsys_ids.collect do |vsys_id|
|
42
|
-
vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
|
36
|
+
systems = xml[0]['vsys'].collect do |vsys|
|
37
|
+
vsys_id = vsys['vsysId'][0]
|
43
38
|
vsys_description_el = vsys['description']
|
44
39
|
CIMI::Model::System.new(
|
45
|
-
:id =>
|
40
|
+
:id => vsys_id,
|
46
41
|
:name => vsys['vsysName'][0],
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
:
|
42
|
+
:description => vsys_description_el ? vsys_description_el[0] : nil,
|
43
|
+
:machines => { :href => context.system_machines_url(vsys_id) },
|
44
|
+
:volumes => { :href => context.system_volumes_url(vsys_id) },
|
45
|
+
:networks => { :href => context.system_networks_url(vsys_id) },
|
46
|
+
:addresses => { :href => context.system_addresses_url(vsys_id) },
|
47
|
+
:operations => []
|
52
48
|
)
|
53
49
|
end
|
50
|
+
systems = systems.select { |s| opts[:id] == s[:id] } if opts[:id]
|
51
|
+
|
52
|
+
# now add system state and advertise operations
|
53
|
+
systems.each do |system|
|
54
|
+
vservers = client.list_vservers(system[:id])['vservers'][0]['vserver']
|
55
|
+
if vservers.nil?
|
56
|
+
system[:state] = client.get_vsys_status(system[:id])['vsysStatus'][0] == 'DEPLOYING' ? 'CREATING' : 'MIXED'
|
57
|
+
else
|
58
|
+
vservers.each do |vserver|
|
59
|
+
state = @@MACHINE_STATE_MAP[client.get_vserver_status(vserver['vserverId'][0])['vserverStatus'][0]]
|
60
|
+
system[:state] ||= state
|
61
|
+
system[:operations] << { :href => context.system_url("#{system[:id]}/start"), :rel => "http://schemas.dmtf.org/cimi/1/action/start" } if state == 'STOPPED'
|
62
|
+
system[:operations] << { :href => context.system_url("#{system[:id]}/stop"), :rel => "http://schemas.dmtf.org/cimi/1/action/stop" } if state == 'STARTED'
|
63
|
+
if system[:state] != state
|
64
|
+
system[:state] = 'MIXED'
|
65
|
+
# this case could have been caused by one machine in capturing state and one in e.g. creating,
|
66
|
+
# but just advertise both operations to cut it short
|
67
|
+
system[:operations] << { :href => context.system_url("#{system[:id]}/start"), :rel => "http://schemas.dmtf.org/cimi/1/action/start" }
|
68
|
+
system[:operations] << { :href => context.system_url("#{system[:id]}/stop"), :rel => "http://schemas.dmtf.org/cimi/1/action/stop" }
|
69
|
+
break
|
70
|
+
end
|
71
|
+
end
|
72
|
+
system[:operations].uniq!
|
73
|
+
end
|
74
|
+
# check for special case: in destroy_system the FW is stopped before the system is deleted
|
75
|
+
system[:state] = 'DELETING' if ((vservers.nil? and system[:state] != 'CREATING') or system[:state] == 'STOPPED') and
|
76
|
+
['STOPPED', 'STOPPING'].include? client.get_efm_status("#{system[:id]}-S-0001")['efmStatus'][0]
|
77
|
+
system[:operations] << { :href => context.system_url(system[:id]), :rel => "delete" } if system[:state] == 'STOPPED'
|
78
|
+
end
|
79
|
+
systems
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def create_system(credentials, opts={})
|
84
|
+
safely do
|
85
|
+
client = new_client(credentials)
|
86
|
+
name = opts[:name] || "system_#{Time.now.to_s}"
|
87
|
+
template = opts[:system_template]
|
88
|
+
template_id = template.id || template.href.to_s.gsub(/.*\/([^\/]+)$/, '\1')
|
89
|
+
vsys_id = client.create_vsys(template_id, name)['vsysId'][0]
|
90
|
+
opts[:id] = vsys_id
|
91
|
+
systems(credentials, opts).first
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def destroy_system(credentials, id)
|
96
|
+
delete_firewall(credentials, :id => "#{id}-S-0001")
|
97
|
+
end
|
98
|
+
|
99
|
+
def start_system(credentials, opts={})
|
100
|
+
safely do
|
101
|
+
client = new_client(credentials)
|
102
|
+
context = opts[:env]
|
103
|
+
vsys_id = opts[:id]
|
104
|
+
xml = client.list_vservers(vsys_id)['vservers']
|
105
|
+
return unless xml and xml[0]['vserver']
|
106
|
+
|
107
|
+
# FIXME: maybe this should be done in a separate thread (in case of gigantic number of servers)
|
108
|
+
# FIXME: error handling (ok to exit loop? Cleanup?) - at this time the cimi spec is quiet on that
|
109
|
+
xml[0]['vserver'].each do |vserver|
|
110
|
+
begin
|
111
|
+
client.start_vserver(vserver['vserverId'][0])
|
112
|
+
rescue Exception => ex
|
113
|
+
raise ex if not ex.message =~ /(ALREADY_STARTED|ILLEGAL_STATE).*/
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def stop_system(credentials, opts={})
|
120
|
+
safely do
|
121
|
+
client = new_client(credentials)
|
122
|
+
context = opts[:env]
|
123
|
+
vsys_id = opts[:id]
|
124
|
+
xml = client.list_vservers(vsys_id)['vservers']
|
125
|
+
return unless xml and xml[0]['vserver']
|
126
|
+
|
127
|
+
# FIXME: maybe this should be done in a separate thread (in case of gigantic number of servers)
|
128
|
+
# FIXME: error handling (ok to exit loop? Cleanup?) - at this time the cimi spec is quiet on that
|
129
|
+
xml[0]['vserver'].each do |vserver|
|
130
|
+
begin
|
131
|
+
client.stop_vserver(vserver['vserverId'][0])
|
132
|
+
rescue Exception => ex
|
133
|
+
raise ex if not ex.message =~ /(ALREADY_STOPPED|ILLEGAL_STATE).*/
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def system_machines(credentials, opts={})
|
140
|
+
safely do
|
141
|
+
client = new_client(credentials)
|
142
|
+
#if :expand not specified, list of hrefs only, else convert from :instances?
|
143
|
+
context = opts[:env]
|
144
|
+
vsys_id = opts[:system_id]
|
145
|
+
xml = client.list_vservers(vsys_id)['vservers']
|
146
|
+
return [] unless xml and xml[0]['vserver']
|
147
|
+
|
148
|
+
machines = xml[0]['vserver'].collect do |vserver|
|
149
|
+
vserver_id = vserver['vserverId'][0]
|
150
|
+
CIMI::Model::SystemMachine.new(
|
151
|
+
:id => context.system_machine_url(:id => vsys_id, :ent_id => vserver_id),
|
152
|
+
:name => vserver['vserverName'][0],
|
153
|
+
:machine => { :href => context.machine_url(vserver_id)}
|
154
|
+
) unless opts[:id] and opts[:id] != vserver_id
|
155
|
+
end
|
156
|
+
machines.compact
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def system_volumes(credentials, opts={})
|
161
|
+
safely do
|
162
|
+
client = new_client(credentials)
|
163
|
+
context = opts[:env]
|
164
|
+
vsys_id = opts[:system_id]
|
165
|
+
#if :expand not specified, list of hrefs only, else convert from :storage_volumes?
|
166
|
+
xml = client.list_vdisk(vsys_id)['vdisks']
|
167
|
+
return [] unless xml and xml[0]['vdisk']
|
168
|
+
|
169
|
+
volumes = xml[0]['vdisk'].collect do |vdisk|
|
170
|
+
vdisk_id = vdisk['vdiskId'][0]
|
171
|
+
CIMI::Model::SystemVolume.new(
|
172
|
+
:id => context.system_volume_url(:id => vsys_id, :ent_id => vdisk_id),
|
173
|
+
:name => vdisk['vdiskName'][0],
|
174
|
+
:volume => { :href => context.volume_url(vdisk_id)}
|
175
|
+
) unless (opts[:id] and opts[:id] != vdisk_id) or determine_storage_type(vdisk_id) == 'system'
|
176
|
+
end
|
177
|
+
volumes.compact
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def system_networks(credentials, opts={})
|
182
|
+
safely do
|
183
|
+
client = new_client(credentials)
|
184
|
+
context = opts[:env]
|
185
|
+
vsys_id = opts[:system_id]
|
186
|
+
#if :expand not specified, list of hrefs only, else ??
|
187
|
+
vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
|
188
|
+
|
189
|
+
# retrieve network segment (subnet) info
|
190
|
+
networks = vsys['vnets'][0]['vnet'].collect do |vnet|
|
191
|
+
network_id = vnet['networkId'][0]
|
192
|
+
network_id =~ /.*-(\w)$/
|
193
|
+
CIMI::Model::SystemNetwork.new(
|
194
|
+
:id => context.system_network_url(:id => vsys_id, :ent_id => network_id),
|
195
|
+
:name => "#{$1} for system #{vsys['vsysName'][0]}",
|
196
|
+
:network => { :href => context.network_url(network_id)}
|
197
|
+
) unless opts[:id] and opts[:id] != network_id
|
198
|
+
end
|
199
|
+
networks.compact
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def system_addresses(credentials, opts={})
|
204
|
+
safely do
|
205
|
+
client = new_client(credentials)
|
206
|
+
context = opts[:env]
|
207
|
+
vsys_id = opts[:system_id]
|
208
|
+
#if :expand not specified, list of hrefs only, else ??
|
209
|
+
xml = client.list_public_ips(vsys_id)['publicips']
|
210
|
+
return [] unless xml and xml[0]['publicip']
|
211
|
+
|
212
|
+
# retrieve network segment (subnet) info
|
213
|
+
addresses = xml[0]['publicip'].collect do |ip|
|
214
|
+
address = ip['address'][0]
|
215
|
+
CIMI::Model::SystemAddress.new(
|
216
|
+
:id => context.system_address_url(:id => vsys_id, :ent_id => address),
|
217
|
+
:name => "Public IP address allocated to system #{ip['vsysId'][0]}",
|
218
|
+
:address => { :href => context.address_url(address)}
|
219
|
+
) unless opts[:id] and opts[:id] != address
|
220
|
+
end
|
221
|
+
addresses.compact
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def system_forwarding_groups(credentials, opts={})
|
226
|
+
safely do
|
227
|
+
client = new_client(credentials)
|
228
|
+
context = opts[:env]
|
229
|
+
vsys_id = opts[:system_id]
|
230
|
+
#if :expand not specified, list of hrefs only, else ??
|
231
|
+
vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
|
232
|
+
|
233
|
+
group_id = "#{vsys_id}-INTRA"
|
234
|
+
groups = []
|
235
|
+
groups << CIMI::Model::SystemForwardingGroup.new(
|
236
|
+
:id => context.system_forwarding_group_url(:id => vsys_id, :ent_id => group_id),
|
237
|
+
:name => "Routing group of system #{vsys['vsysName'][0]}",
|
238
|
+
:forwarding_group => { :href => context.forwarding_group_url(group_id)}
|
239
|
+
) unless vsys['vnets'][0]['vnet'].size <= 1 or (opts[:id] and opts[:id] != group_id)
|
240
|
+
groups
|
54
241
|
end
|
55
242
|
end
|
56
243
|
|
57
244
|
def system_templates(credentials, opts={})
|
58
245
|
safely do
|
59
246
|
client = new_client(credentials)
|
247
|
+
context = opts[:env]
|
60
248
|
templates = client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].collect do |desc|
|
249
|
+
conf = client.get_vsys_descriptor_configuration(desc['vsysdescriptorId'][0])['vsysdescriptor'][0]
|
250
|
+
components = conf['vservers'][0]['vserver'].collect do |vserver|
|
251
|
+
next if vserver['vserverType'][0] == 'firewall'
|
252
|
+
volume_templates = vserver['vdisks'][0]['vdisk'].collect do |vdisk|
|
253
|
+
CIMI::Model::VolumeTemplateWithLocation.new(
|
254
|
+
:volume_config => CIMI::Model::VolumeConfiguration.new(:capacity => vdisk['size'][0].to_i * 1024 * 1024)
|
255
|
+
)
|
256
|
+
end if vserver['vdisks']
|
257
|
+
{
|
258
|
+
:name => desc['vsysdescriptorName'][0],
|
259
|
+
:description => '',
|
260
|
+
:type => "http://schemas.dmtf.org/cimi/1/Machine",
|
261
|
+
:machine_template => CIMI::Model::MachineTemplate.new(
|
262
|
+
:name => vserver['vserverName'][0],
|
263
|
+
:description => '',
|
264
|
+
:machine_config => CIMI::Service::MachineConfiguration.find(vserver['vserverType'][0], context),
|
265
|
+
:machine_image => { :href => context.machine_image_url(vserver['diskimageId'][0]) },
|
266
|
+
:volume_templates => volume_templates
|
267
|
+
)
|
268
|
+
}
|
269
|
+
end
|
270
|
+
# add network templates
|
271
|
+
if conf['vsysdescriptorId'][0] =~ /(1|2|3)-tier Skeleton/
|
272
|
+
tiers = ['DMZ', 'Secure1', 'Secure2']
|
273
|
+
components += 1.upto($1.to_i).collect do |n|
|
274
|
+
{
|
275
|
+
:name => tiers[n],
|
276
|
+
:description => "Network tier #{n}",
|
277
|
+
:type => "http://schemas.dmtf.org/cimi/1/Network",
|
278
|
+
:network_template => CIMI::Model::NetworkTemplate.new(
|
279
|
+
:name => 'Private network',
|
280
|
+
:description => '',
|
281
|
+
:network_config => CIMI::Model::NetworkConfiguration.new(
|
282
|
+
:network_type => 'PRIVATE',
|
283
|
+
:class_of_service => 'BRONZE'
|
284
|
+
)
|
285
|
+
)
|
286
|
+
}
|
287
|
+
end
|
288
|
+
end
|
61
289
|
CIMI::Model::SystemTemplate.new(
|
62
|
-
:id
|
63
|
-
:name
|
64
|
-
:description
|
290
|
+
:id => desc['vsysdescriptorId'][0],
|
291
|
+
:name => desc['vsysdescriptorName'][0],
|
292
|
+
:description => desc['description'][0],
|
293
|
+
:component_descriptors => components.compact
|
65
294
|
)
|
66
295
|
end
|
67
296
|
templates = templates.select { |t| opts[:id] == t[:id] } if opts[:id]
|
@@ -69,6 +298,24 @@ module Deltacloud::Drivers::Fgcp
|
|
69
298
|
end
|
70
299
|
end
|
71
300
|
|
301
|
+
# FGCP instance states mapped to CIMI machine states
|
302
|
+
@@MACHINE_STATE_MAP = {
|
303
|
+
'DEPLOYING' => 'CREATING',
|
304
|
+
'RUNNING' => 'STARTED',
|
305
|
+
'STOPPING' => 'STOPPING',
|
306
|
+
'STOPPED' => 'STOPPED',
|
307
|
+
'STARTING' => 'STARTING', # not sure about this one
|
308
|
+
'FAILOVER' => 'STARTED',
|
309
|
+
'UNEXPECTED_STOP' => 'STOPPED',
|
310
|
+
'RESTORING' => 'RESTORING',
|
311
|
+
'BACKUP_ING' => 'CAPTURING',
|
312
|
+
'ERROR' => 'ERROR', # allowed actions limited
|
313
|
+
'START_ERROR' => 'STOPPED', # allowed actions are same as for STOPPED
|
314
|
+
'STOP_ERROR' => 'STARTED', # allowed actions are same as for RUNNING
|
315
|
+
'REGISTERING' => 'PENDING',
|
316
|
+
'CHANGE_TYPE' => 'PENDING'
|
317
|
+
}
|
318
|
+
|
72
319
|
end
|
73
320
|
|
74
321
|
end
|
@@ -114,7 +114,7 @@ module Deltacloud::Drivers::Mock
|
|
114
114
|
results
|
115
115
|
end
|
116
116
|
|
117
|
-
def filter_by_owner(images, owner_id)
|
117
|
+
def filter_by_owner(credentials, images, owner_id)
|
118
118
|
return images unless owner_id
|
119
119
|
if owner_id == 'self'
|
120
120
|
images.select { |e| e.owner_id == credentials.user }
|
@@ -131,7 +131,7 @@ module Deltacloud::Drivers::Mock
|
|
131
131
|
images = @client.build_all(Image)
|
132
132
|
|
133
133
|
images = filter_on(images, opts, :id, :architecture)
|
134
|
-
images = filter_by_owner(images, opts[:owner_id])
|
134
|
+
images = filter_by_owner(credentials, images, opts[:owner_id])
|
135
135
|
|
136
136
|
# Add hardware profiles to each image
|
137
137
|
images = images.map { |i| (i.hardware_profiles = hardware_profiles(nil)) && i }
|
@@ -32,7 +32,110 @@ module Deltacloud::Drivers::Mock
|
|
32
32
|
return []
|
33
33
|
end
|
34
34
|
end
|
35
|
-
systems.map{|sys|
|
35
|
+
systems.map{|sys| convert_urls(sys, opts[:env])}.flatten
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_system(credentials, opts={})
|
39
|
+
check_credentials(credentials)
|
40
|
+
id = "#{opts[:env].send("systems_url")}/#{opts[:name]}"
|
41
|
+
sys_hsh = { "id"=> id,
|
42
|
+
"name" => opts[:name],
|
43
|
+
"description" => opts[:description],
|
44
|
+
"created" => Time.now,
|
45
|
+
"state" => "STOPPED",
|
46
|
+
"systemTemplate"=> { "href" => opts[:system_template].id },
|
47
|
+
"operations" => [{"rel"=>"http://schemas.dmtf.org/cimi/1/action/start", "href"=> "#{id}/start"},
|
48
|
+
{"rel"=>"edit", "href"=> id},
|
49
|
+
{"rel"=>"delete", "href"=> id}] }
|
50
|
+
system = CIMI::Model::System.from_json(JSON.generate(sys_hsh))
|
51
|
+
|
52
|
+
@client.store_cimi(:system, system)
|
53
|
+
system
|
54
|
+
end
|
55
|
+
|
56
|
+
def destroy_system(credentials, id)
|
57
|
+
check_credentials(credentials)
|
58
|
+
@client.destroy_cimi(:system, id)
|
59
|
+
end
|
60
|
+
|
61
|
+
def start_system(credentials, id)
|
62
|
+
check_credentials(credentials)
|
63
|
+
update_object_state(id, "System", "STARTED")
|
64
|
+
end
|
65
|
+
|
66
|
+
def stop_system(credentials, id)
|
67
|
+
check_credentials(credentials)
|
68
|
+
update_object_state(id, "System", "STOPPED")
|
69
|
+
end
|
70
|
+
|
71
|
+
def system_machines(credentials, opts={})
|
72
|
+
check_credentials(credentials)
|
73
|
+
if opts[:id].nil?
|
74
|
+
machines = @client.load_all_cimi(:system_machine).map{|mach| CIMI::Model::SystemMachine.from_json(mach)}
|
75
|
+
else
|
76
|
+
begin
|
77
|
+
machines = [CIMI::Model::SystemMachine.from_json(@client.load_cimi(:system_machine, opts[:id]))]
|
78
|
+
rescue Errno::ENOENT
|
79
|
+
return []
|
80
|
+
end
|
81
|
+
end
|
82
|
+
machines.map{|m|convert_urls(m, opts[:env])}.flatten
|
83
|
+
end
|
84
|
+
|
85
|
+
def system_volumes(credentials, opts={})
|
86
|
+
check_credentials(credentials)
|
87
|
+
if opts[:id].nil?
|
88
|
+
volumes = @client.load_all_cimi(:system_volume).map{|vol| CIMI::Model::SystemVolume.from_json(vol)}
|
89
|
+
else
|
90
|
+
begin
|
91
|
+
volumes = [CIMI::Model::SystemVolume.from_json(@client.load_cimi(:system_volume, opts[:id]))]
|
92
|
+
rescue Errno::ENOENT
|
93
|
+
return []
|
94
|
+
end
|
95
|
+
end
|
96
|
+
volumes.map{|vol|convert_urls(vol, opts[:env])}.flatten
|
97
|
+
end
|
98
|
+
|
99
|
+
def system_networks(credentials, opts={})
|
100
|
+
check_credentials(credentials)
|
101
|
+
if opts[:id].nil?
|
102
|
+
networks = @client.load_all_cimi(:system_network).map{|net| CIMI::Model::SystemNetwork.from_json(net)}
|
103
|
+
else
|
104
|
+
begin
|
105
|
+
networks = [CIMI::Model::SystemNetwork.from_json(@client.load_cimi(:system_network, opts[:id]))]
|
106
|
+
rescue Errno::ENOENT
|
107
|
+
return []
|
108
|
+
end
|
109
|
+
end
|
110
|
+
networks.map{|n|convert_urls(n, opts[:env])}.flatten
|
111
|
+
end
|
112
|
+
|
113
|
+
def system_addresses(credentials, opts={})
|
114
|
+
check_credentials(credentials)
|
115
|
+
if opts[:id].nil?
|
116
|
+
addresses = @client.load_all_cimi(:system_address).map{|a| CIMI::Model::SystemAddress.from_json(a)}
|
117
|
+
else
|
118
|
+
begin
|
119
|
+
addresses = [CIMI::Model::SystemVolume.from_json(@client.load_cimi(:system_address, opts[:id]))]
|
120
|
+
rescue Errno::ENOENT
|
121
|
+
return []
|
122
|
+
end
|
123
|
+
end
|
124
|
+
addresses.map{|a|convert_urls(a, opts[:env])}.flatten
|
125
|
+
end
|
126
|
+
|
127
|
+
def system_forwarding_groups(credentials, opts={})
|
128
|
+
check_credentials(credentials)
|
129
|
+
if opts[:id].nil?
|
130
|
+
groups = @client.load_all_cimi(:system_forwarding_group).map{|group| CIMI::Model::SystemForwardingGroup.from_json(group)}
|
131
|
+
else
|
132
|
+
begin
|
133
|
+
groups = [CIMI::Model::SystemForwardingGroup.from_json(@client.load_cimi(:system_forwarding_group, opts[:id]))]
|
134
|
+
rescue Errno::ENOENT
|
135
|
+
return []
|
136
|
+
end
|
137
|
+
end
|
138
|
+
groups.map{|g|convert_urls(g, opts[:env])}.flatten
|
36
139
|
end
|
37
140
|
|
38
141
|
def system_templates(credentials, opts={})
|
@@ -46,17 +149,17 @@ module Deltacloud::Drivers::Mock
|
|
46
149
|
return []
|
47
150
|
end
|
48
151
|
end
|
49
|
-
system_templates.map{|sys_templ|
|
152
|
+
system_templates.map{|sys_templ| convert_urls(sys_templ, opts[:env])}.flatten
|
50
153
|
end
|
51
154
|
|
52
155
|
def networks(credentials, opts={})
|
53
156
|
check_credentials(credentials)
|
54
157
|
if opts[:id].nil?
|
55
158
|
networks = @client.load_all_cimi(:network).map{|net| CIMI::Model::Network.from_json(net)}
|
56
|
-
networks.map{|net|
|
159
|
+
networks.map{|net| convert_urls(net, opts[:env])}.flatten
|
57
160
|
else
|
58
161
|
network = CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:id]))
|
59
|
-
|
162
|
+
convert_urls(network, opts[:env])
|
60
163
|
end
|
61
164
|
end
|
62
165
|
|
@@ -106,10 +209,10 @@ module Deltacloud::Drivers::Mock
|
|
106
209
|
check_credentials(credentials)
|
107
210
|
if opts[:id].nil?
|
108
211
|
network_configs = @client.load_all_cimi(:network_configuration).map{|net_config| CIMI::Model::NetworkConfiguration.from_json(net_config)}
|
109
|
-
network_configs.map{|net_config|
|
212
|
+
network_configs.map{|net_config| convert_urls(net_config, opts[:env])}.flatten
|
110
213
|
else
|
111
214
|
network_config = CIMI::Model::NetworkConfiguration.from_json(@client.load_cimi(:network_configuration, opts[:id]))
|
112
|
-
|
215
|
+
convert_urls(network_config, opts[:env])
|
113
216
|
end
|
114
217
|
end
|
115
218
|
|
@@ -117,10 +220,10 @@ module Deltacloud::Drivers::Mock
|
|
117
220
|
check_credentials(credentials)
|
118
221
|
if opts[:id].nil?
|
119
222
|
network_templates = @client.load_all_cimi(:network_template).map{|net_templ| CIMI::Model::NetworkTemplate.from_json(net_templ)}
|
120
|
-
network_templates.map{|net_templ|
|
223
|
+
network_templates.map{|net_templ| convert_urls(net_templ, opts[:env])}.flatten
|
121
224
|
else
|
122
225
|
network_template = CIMI::Model::NetworkTemplate.from_json(@client.load_cimi(:network_template, opts[:id]))
|
123
|
-
|
226
|
+
convert_urls(network_template, opts[:env])
|
124
227
|
end
|
125
228
|
end
|
126
229
|
|
@@ -128,10 +231,10 @@ module Deltacloud::Drivers::Mock
|
|
128
231
|
check_credentials(credentials)
|
129
232
|
if opts[:id].nil?
|
130
233
|
forwarding_groups = @client.load_all_cimi(:forwarding_group).map{|fg| CIMI::Model::ForwardingGroup.from_json(fg)}
|
131
|
-
forwarding_groups.map{|fg|
|
234
|
+
forwarding_groups.map{|fg| convert_urls(fg, opts[:env])}.flatten
|
132
235
|
else
|
133
236
|
forwarding_group = CIMI::Model::ForwardingGroup.from_json(@client.load_cimi(:forwarding_group, opts[:id]))
|
134
|
-
|
237
|
+
convert_urls(forwarding_group, opts[:env])
|
135
238
|
end
|
136
239
|
end
|
137
240
|
|
@@ -139,10 +242,10 @@ module Deltacloud::Drivers::Mock
|
|
139
242
|
check_credentials(credentials)
|
140
243
|
if opts[:id].nil?
|
141
244
|
forwarding_group_templates = @client.load_all_cimi(:forwarding_group_template).map{|fg_templ| CIMI::Model::ForwardingGroupTemplate.from_json(fg_templ)}
|
142
|
-
forwarding_group_templates.map{|fg_templ|
|
245
|
+
forwarding_group_templates.map{|fg_templ| convert_urls(fg_templ, opts[:env])}.flatten
|
143
246
|
else
|
144
247
|
forwarding_group_template = CIMI::Model::ForwardingGroupTemplate.from_json(@client.load_cimi(:forwarding_group_template, opts[:id]))
|
145
|
-
|
248
|
+
convert_urls(forwarding_group_template, opts[:env])
|
146
249
|
end
|
147
250
|
end
|
148
251
|
|
@@ -150,10 +253,10 @@ module Deltacloud::Drivers::Mock
|
|
150
253
|
check_credentials(credentials)
|
151
254
|
if opts[:id].nil?
|
152
255
|
ports = @client.load_all_cimi(:network_port).map{|net_port| CIMI::Model::NetworkPort.from_json(net_port)}
|
153
|
-
ports.map{|net_port|
|
256
|
+
ports.map{|net_port| convert_urls(net_port, opts[:env])}.flatten
|
154
257
|
else
|
155
258
|
port = CIMI::Model::NetworkPort.from_json(@client.load_cimi(:network_port, opts[:id]))
|
156
|
-
|
259
|
+
convert_urls(port, opts[:env])
|
157
260
|
end
|
158
261
|
end
|
159
262
|
|
@@ -161,10 +264,10 @@ module Deltacloud::Drivers::Mock
|
|
161
264
|
check_credentials(credentials)
|
162
265
|
if opts[:id].nil?
|
163
266
|
network_port_configurations = @client.load_all_cimi(:network_port_configuration).map{|network_port_config| CIMI::Model::NetworkPortConfiguration.from_json(network_port_config)}
|
164
|
-
network_port_configurations.map{|network_port_config|
|
267
|
+
network_port_configurations.map{|network_port_config| convert_urls(network_port_config, opts[:env])}.flatten
|
165
268
|
else
|
166
269
|
network_port_configuration = CIMI::Model::NetworkPortConfiguration.from_json(@client.load_cimi(:network_port_configuration, opts[:id]))
|
167
|
-
|
270
|
+
convert_urls(network_port_configuration, opts[:env])
|
168
271
|
end
|
169
272
|
end
|
170
273
|
|
@@ -172,10 +275,10 @@ module Deltacloud::Drivers::Mock
|
|
172
275
|
check_credentials(credentials)
|
173
276
|
if opts[:id].nil?
|
174
277
|
network_port_templates = @client.load_all_cimi(:network_port_template).map{|net_port_templ| CIMI::Model::NetworkPortTemplate.from_json(net_port_templ)}
|
175
|
-
network_port_templates.map{|net_port_templ|
|
278
|
+
network_port_templates.map{|net_port_templ| convert_urls(net_port_templ, opts[:env])}.flatten
|
176
279
|
else
|
177
280
|
network_port_template = CIMI::Model::NetworkPortTemplate.from_json(@client.load_cimi(:network_port_template, opts[:id]))
|
178
|
-
|
281
|
+
convert_urls(network_port_template, opts[:env])
|
179
282
|
end
|
180
283
|
end
|
181
284
|
|
@@ -183,54 +286,63 @@ module Deltacloud::Drivers::Mock
|
|
183
286
|
check_credentials(credentials)
|
184
287
|
if opts[:id].nil?
|
185
288
|
address_templates = @client.load_all_cimi(:address_template).map{|addr_templ| CIMI::Model::AddressTemplate.from_json(addr_templ)}
|
186
|
-
address_templates.map{|addr_templ|
|
289
|
+
address_templates.map{|addr_templ| convert_urls(addr_templ, opts[:env])}.flatten
|
187
290
|
else
|
188
291
|
address_template = CIMI::Model::AddressTemplate.from_json(@client.load_cimi(:address_template, opts[:id]))
|
189
|
-
|
292
|
+
convert_urls(address_template, opts[:env])
|
190
293
|
end
|
191
294
|
end
|
192
295
|
|
193
296
|
private
|
194
297
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
298
|
+
# Convert all attributes that have values of the form
|
299
|
+
# http://cimi.example.org/COLL/ID
|
300
|
+
# or
|
301
|
+
# http://cimi.example.org/COLL/ID/SUBCOLL/ENT_ID
|
302
|
+
def convert_urls(val, context)
|
303
|
+
if val.nil? || val.is_a?(Fixnum)
|
304
|
+
# Nothing to do
|
305
|
+
elsif val.is_a?(Struct)
|
306
|
+
val.members.each { |m| val[m] = convert_urls(val[m], context) }
|
307
|
+
elsif val.is_a?(Hash)
|
308
|
+
val.keys.each { |m| val[m] = convert_urls(val[m], context) }
|
309
|
+
elsif val.is_a?(Array)
|
310
|
+
val.each_index { |i| val[i] = convert_urls(val[i], context) }
|
311
|
+
elsif val.is_a?(String)
|
312
|
+
val = rewrite_url(val, context)
|
313
|
+
elsif val.is_a?(CIMI::Model::Resource)
|
314
|
+
val.attribute_values.each do |k, v|
|
315
|
+
val[k] = convert_urls(val[k], context)
|
210
316
|
end
|
317
|
+
else
|
318
|
+
# Need to add a branch for val.class
|
319
|
+
raise "Whoa ! #{val.inspect}"
|
211
320
|
end
|
212
|
-
|
213
|
-
cimi_object.id=object_url
|
214
|
-
cimi_object.operations.each{|op| op.href=object_url }
|
215
|
-
cimi_object
|
321
|
+
val
|
216
322
|
end
|
217
323
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
324
|
+
# Rewrite URL assuming it points at a valid resource; if that's not
|
325
|
+
# possible, return +s+
|
326
|
+
#
|
327
|
+
# URLs that should be rewritten need to be in the form
|
328
|
+
# http://cimi.example.org/COLLECTION/ID
|
329
|
+
# or
|
330
|
+
# http://cimi.example.org/COLLECTION/SYSTEM_ID/SUBCOLLECTION/ENT_ID
|
331
|
+
def rewrite_url(s, context)
|
332
|
+
begin
|
333
|
+
u = URI.parse(s)
|
334
|
+
rescue URI::InvalidURIError
|
335
|
+
return s
|
336
|
+
end
|
337
|
+
return s unless u.scheme == 'http' && u.host == 'cimi.example.org'
|
338
|
+
_, coll, id, sub_coll, sub_id = u.path.split("/")
|
339
|
+
method = sub_coll ? "#{coll.singularize}_#{sub_coll.singularize}_url"
|
340
|
+
: "#{coll.singularize}_url"
|
341
|
+
if context.respond_to?(method)
|
342
|
+
sub_coll ? context.send(method, :id => id, :ent_id => sub_id)
|
343
|
+
: context.send(method, id)
|
227
344
|
else
|
228
|
-
|
229
|
-
if cimi_name.to_s.end_with?("config")
|
230
|
-
struct.href = context.send(:"#{cimi_name}uration_url", obj_name)
|
231
|
-
else
|
232
|
-
struct.href = context.send(:"#{cimi_name}_url", obj_name)
|
233
|
-
end
|
345
|
+
s
|
234
346
|
end
|
235
347
|
end
|
236
348
|
|