deltacloud-core 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NOTICE +1 -1
- data/Rakefile +63 -21
- data/bin/deltacloudd +10 -6
- data/config.ru +62 -6
- data/config/drivers/ec2.yaml +8 -0
- data/config/drivers/fgcp.yaml +13 -0
- data/deltacloud-core.gemspec +10 -2
- data/lib/cimi/collections.rb +58 -0
- data/lib/cimi/collections/address_templates.rb +49 -0
- data/lib/cimi/collections/addresses.rb +74 -0
- data/lib/cimi/collections/cloud_entry_point.rb +37 -0
- data/lib/{deltacloud/helpers/conversion_helper.rb → cimi/collections/entity_metadata.rb} +24 -16
- data/lib/cimi/collections/machine_admins.rb +74 -0
- data/lib/cimi/collections/machine_configurations.rb +49 -0
- data/lib/cimi/collections/machine_images.rb +50 -0
- data/lib/cimi/collections/machines.rb +157 -0
- data/lib/cimi/collections/network_configurations.rb +47 -0
- data/lib/cimi/collections/network_templates.rb +48 -0
- data/lib/cimi/collections/networks.rb +125 -0
- data/lib/cimi/collections/routing_group_templates.rb +47 -0
- data/lib/cimi/collections/routing_groups.rb +48 -0
- data/lib/cimi/collections/volume_configurations.rb +48 -0
- data/lib/cimi/collections/volume_images.rb +50 -0
- data/lib/cimi/collections/volumes.rb +80 -0
- data/lib/cimi/collections/vsp_configurations.rb +48 -0
- data/lib/cimi/collections/vsp_templates.rb +50 -0
- data/lib/cimi/collections/vsps.rb +108 -0
- data/lib/cimi/dependencies.rb +1 -0
- data/lib/cimi/helpers.rb +116 -0
- data/lib/cimi/helpers/cimi_helper.rb +6 -2
- data/lib/cimi/models.rb +72 -0
- data/lib/cimi/{model → models}/action.rb +1 -1
- data/lib/cimi/models/address.rb +72 -0
- data/lib/cimi/models/address_collection.rb +34 -0
- data/lib/cimi/models/address_template.rb +54 -0
- data/lib/cimi/models/address_template_collection.rb +34 -0
- data/lib/cimi/{model → models}/base.rb +2 -2
- data/lib/cimi/{model → models}/cloud_entry_point.rb +3 -5
- data/lib/cimi/{model → models}/entity_metadata.rb +7 -6
- data/lib/cimi/{model → models}/entity_metadata_collection.rb +2 -2
- data/lib/cimi/{model → models}/errors.rb +8 -0
- data/lib/cimi/{model → models}/machine.rb +10 -10
- data/lib/cimi/{model → models}/machine_admin.rb +1 -1
- data/lib/cimi/{model → models}/machine_admin_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_configuration.rb +9 -6
- data/lib/cimi/{model → models}/machine_configuration_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_image.rb +1 -1
- data/lib/cimi/{model → models}/machine_image_collection.rb +2 -2
- data/lib/cimi/{model → models}/machine_template.rb +0 -0
- data/lib/cimi/{model → models}/machine_template_collection.rb +2 -2
- data/lib/cimi/models/network.rb +109 -0
- data/lib/cimi/{model → models}/network_collection.rb +2 -2
- data/lib/cimi/{model → models}/network_configuration.rb +3 -4
- data/lib/cimi/{model → models}/network_configuration_collection.rb +2 -2
- data/lib/cimi/models/network_template.rb +36 -0
- data/lib/cimi/models/network_template_collection.rb +35 -0
- data/lib/cimi/models/routing_group.rb +34 -0
- data/lib/cimi/models/routing_group_collection.rb +34 -0
- data/lib/cimi/models/routing_group_template.rb +34 -0
- data/lib/cimi/models/routing_group_template_collection.rb +35 -0
- data/lib/cimi/{model → models}/schema.rb +0 -0
- data/lib/cimi/{model → models}/volume.rb +4 -4
- data/lib/cimi/{model → models}/volume_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_configuration.rb +1 -1
- data/lib/cimi/{model → models}/volume_configuration_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_image.rb +1 -1
- data/lib/cimi/{model → models}/volume_image_collection.rb +2 -2
- data/lib/cimi/{model → models}/volume_template.rb +0 -0
- data/lib/cimi/{model → models}/volume_template_collection.rb +2 -2
- data/lib/cimi/models/vsp.rb +102 -0
- data/lib/cimi/models/vsp_collection.rb +34 -0
- data/lib/cimi/models/vsp_configuration.rb +40 -0
- data/lib/cimi/models/vsp_configuration_collection.rb +34 -0
- data/lib/cimi/models/vsp_template.rb +34 -0
- data/lib/cimi/models/vsp_template_collection.rb +34 -0
- data/lib/cimi/server.rb +27 -549
- data/lib/deltacloud/api.rb +79 -0
- data/lib/deltacloud/collections.rb +54 -0
- data/lib/deltacloud/collections/addresses.rb +91 -0
- data/lib/deltacloud/collections/buckets.rb +273 -0
- data/lib/deltacloud/collections/drivers.rb +51 -0
- data/lib/deltacloud/collections/firewalls.rb +116 -0
- data/lib/deltacloud/collections/hardware_profiles.rb +29 -0
- data/lib/deltacloud/collections/images.rb +73 -0
- data/lib/deltacloud/collections/instance_states.rb +59 -0
- data/lib/deltacloud/collections/instances.rb +113 -0
- data/lib/deltacloud/collections/keys.rb +61 -0
- data/lib/deltacloud/collections/load_balancers.rb +102 -0
- data/lib/deltacloud/collections/metrics.rb +28 -0
- data/lib/deltacloud/collections/realms.rb +28 -0
- data/lib/deltacloud/collections/storage_snapshots.rb +51 -0
- data/lib/deltacloud/collections/storage_volumes.rb +99 -0
- data/lib/deltacloud/core_ext.rb +14 -6
- data/lib/deltacloud/core_ext/string.rb +17 -5
- data/lib/deltacloud/drivers.rb +6 -42
- data/lib/deltacloud/drivers/azure/azure_driver.rb +0 -4
- data/lib/deltacloud/{base_driver → drivers}/base_driver.rb +56 -18
- data/lib/deltacloud/drivers/condor/condor_driver.rb +1 -8
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +142 -33
- data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +2 -6
- data/lib/deltacloud/{base_driver → drivers}/exceptions.rb +25 -2
- data/lib/deltacloud/drivers/features.rb +154 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +387 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1435 -0
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +8 -11
- data/lib/deltacloud/drivers/google/google_driver.rb +2 -5
- data/lib/deltacloud/drivers/mock/data/keys/test-key.yml +28 -0
- data/lib/deltacloud/drivers/mock/mock_client.rb +2 -2
- data/lib/deltacloud/drivers/mock/mock_driver.rb +58 -40
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +145 -0
- data/lib/deltacloud/drivers/opennebula/cloud_client.rb +107 -73
- data/lib/deltacloud/drivers/opennebula/occi_client.rb +285 -145
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +189 -126
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +427 -8
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +7 -9
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +48 -66
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +44 -51
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +7 -8
- data/lib/deltacloud/drivers/sbc/sbc_client.rb +1 -1
- data/lib/deltacloud/drivers/sbc/sbc_driver.rb +3 -3
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +8 -8
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +39 -13
- data/lib/deltacloud/drivers/vsphere/vsphere_filemanager.rb +1 -0
- data/lib/deltacloud/helpers.rb +79 -7
- data/lib/{sinatra/lazy_auth.rb → deltacloud/helpers/auth_helper.rb} +5 -9
- data/lib/deltacloud/helpers/{blob_stream.rb → blob_stream_helper.rb} +7 -7
- data/lib/deltacloud/helpers/deltacloud_helper.rb +286 -0
- data/lib/deltacloud/helpers/driver_helper.rb +58 -0
- data/lib/deltacloud/helpers/rabbit_helper.rb +34 -0
- data/lib/{sinatra/url_for.rb → deltacloud/helpers/url_helper.rb} +31 -9
- data/lib/deltacloud/models.rb +19 -17
- data/lib/deltacloud/models/bucket.rb +4 -0
- data/lib/deltacloud/{hardware_profile.rb → models/hardware_profile.rb} +4 -2
- data/lib/deltacloud/models/image.rb +1 -0
- data/lib/deltacloud/models/instance.rb +4 -2
- data/lib/deltacloud/models/instance_address.rb +4 -0
- data/lib/deltacloud/models/key.rb +4 -0
- data/lib/deltacloud/models/metric.rb +40 -0
- data/lib/deltacloud/{state_machine.rb → models/state_machine.rb} +18 -1
- data/lib/deltacloud/server.rb +41 -1222
- data/lib/deltacloud_rack.rb +79 -0
- data/lib/{cimi/model/network_template.rb → ec2/helpers.rb} +7 -10
- data/lib/{deltacloud/backend_capability.rb → ec2/helpers/errors.rb} +24 -29
- data/lib/ec2/helpers/result.rb +31 -0
- data/lib/ec2/query_parser.rb +152 -0
- data/lib/ec2/server.rb +70 -0
- data/lib/{deltacloud.rb → sinatra.rb} +7 -12
- data/lib/sinatra/rack_accept.rb +13 -7
- data/lib/sinatra/rack_driver_select.rb +1 -1
- data/lib/sinatra/rack_matrix_params.rb +1 -3
- data/public/images/metric.png +0 -0
- data/public/javascripts/jquery.mobile-1.0.1.min.js +177 -0
- data/public/stylesheets/jquery.mobile-1.0.1.min.css +2 -0
- data/public/stylesheets/new.css +10 -0
- data/support/fedora/deltacloud-core.spec +1 -1
- data/tests/api/common.rb +1 -0
- data/tests/api/driver_test.rb +79 -0
- data/tests/api/library_test.rb +48 -0
- data/tests/cimi/features/step_definitions/common_steps.rb +2 -2
- data/tests/cimi/features/step_definitions/machines_steps.rb +5 -4
- data/tests/cimi/features/step_definitions/volumes_steps.rb +8 -8
- data/tests/cimi/features/support/env.rb +33 -11
- data/tests/common.rb +7 -8
- data/tests/drivers/ec2/api_test.rb +19 -0
- data/tests/drivers/ec2/common.rb +23 -0
- data/tests/drivers/ec2/drivers_test.rb +120 -0
- data/tests/drivers/ec2/hardware_profiles_test.rb +224 -0
- data/tests/drivers/ec2/images_test.rb +230 -0
- data/tests/drivers/ec2/instances_test.rb +356 -0
- data/tests/drivers/ec2/keys_test.rb +181 -0
- data/tests/drivers/ec2/realms_test.rb +146 -0
- data/tests/drivers/fgcp/api_test.rb +47 -0
- data/tests/drivers/fgcp/hardware_profiles_test.rb +54 -0
- data/tests/drivers/fgcp/realms_test.rb +42 -0
- data/tests/drivers/{rackspace → fgcp}/setup.rb +5 -6
- data/tests/drivers/google/api_test.rb +10 -26
- data/tests/drivers/google/buckets_test.rb +79 -95
- data/tests/drivers/google/common.rb +54 -0
- data/tests/drivers/mock/api_test.rb +4 -127
- data/tests/drivers/mock/buckets_test.rb +195 -0
- data/tests/drivers/mock/common.rb +7 -0
- data/tests/drivers/mock/drivers_test.rb +123 -0
- data/tests/drivers/mock/hardware_profiles_test.rb +190 -100
- data/tests/drivers/mock/images_test.rb +162 -103
- data/tests/drivers/mock/instances_test.rb +310 -220
- data/tests/drivers/mock/keys_test.rb +161 -0
- data/tests/drivers/mock/realms_test.rb +109 -70
- data/tests/drivers/mock/storage_snapshots_test.rb +114 -0
- data/tests/drivers/mock/storage_volumes_test.rb +122 -0
- data/tests/drivers/openstack/api_test.rb +8 -3
- data/tests/drivers/openstack/common.rb +21 -0
- data/tests/drivers/openstack/hardware_profiles_test.rb +20 -9
- data/tests/drivers/openstack/images_test.rb +11 -5
- data/tests/drivers/openstack/instances_test.rb +61 -16
- data/tests/drivers/openstack/realms_test.rb +11 -7
- data/tests/drivers/rackspace/api_test.rb +7 -2
- data/tests/drivers/rackspace/buckets_test.rb +7 -2
- data/tests/drivers/rackspace/common.rb +16 -0
- data/tests/drivers/rackspace/hardware_profiles_test.rb +7 -2
- data/tests/drivers/rackspace/images_test.rb +7 -2
- data/tests/drivers/rackspace/instances_test.rb +10 -5
- data/tests/drivers/rackspace/realms_test.rb +7 -2
- data/tests/drivers/rhevm/api_test.rb +12 -6
- data/tests/drivers/rhevm/{setup.rb → common.rb} +8 -1
- data/tests/drivers/rhevm/hardware_profiles_test.rb +7 -2
- data/tests/drivers/rhevm/images_test.rb +8 -2
- data/tests/drivers/rhevm/instances_test.rb +7 -2
- data/tests/drivers/rhevm/realms_test.rb +7 -2
- data/tests/minitest_common.rb +58 -0
- data/tests/minitest_common_api_test.rb +115 -0
- data/views/addresses/associate.html.haml +1 -1
- data/views/addresses/index.html.haml +1 -1
- data/views/addresses/show.html.haml +2 -3
- data/views/api/show.html.haml +22 -9
- data/views/api/show.xml.haml +8 -7
- data/views/blobs/show.xml.haml +7 -4
- data/views/buckets/new.html.haml +2 -2
- data/views/cimi/errors/401.xml.haml +1 -1
- data/views/error.html.haml +3 -3
- data/views/errors/400.html.haml +1 -1
- data/views/errors/400.xml.haml +1 -2
- data/views/errors/401.html.haml +8 -7
- data/views/errors/401.xml.haml +1 -1
- data/views/errors/404.xml.haml +1 -0
- data/views/errors/500.xml.haml +4 -2
- data/views/{cimi/errors/403.html.haml → errors/501.html.haml} +4 -2
- data/views/errors/501.xml.haml +1 -0
- data/views/errors/502.xml.haml +1 -7
- data/views/{cimi/errors/500.html.haml → errors/504.html.haml} +0 -0
- data/views/errors/504.xml.haml +1 -0
- data/views/firewalls/new.html.haml +2 -2
- data/views/firewalls/new_rule.html.haml +1 -1
- data/views/firewalls/show.html.haml +1 -1
- data/views/hardware_profiles/index.html.haml +3 -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 +3 -3
- data/views/images/show.html.haml +5 -0
- data/views/images/show.xml.haml +6 -1
- data/views/instance_states/show.html.haml +1 -1
- data/views/instances/index.html.haml +1 -1
- data/views/instances/new.html.haml +54 -39
- data/views/instances/run_command.html.haml +24 -15
- data/views/instances/show.html.haml +7 -3
- data/views/instances/show.xml.haml +2 -2
- data/views/keys/show.xml.haml +1 -0
- data/views/layout.html.haml +5 -9
- data/views/load_balancers/show.html.haml +12 -6
- data/views/metrics/index.html.haml +13 -0
- data/views/metrics/index.xml.haml +5 -0
- data/views/metrics/show.html.haml +23 -0
- data/views/metrics/show.xml.haml +9 -0
- data/views/realms/show.xml.haml +2 -1
- data/views/root/index.html.haml +1 -1
- data/views/storage_snapshots/show.html.haml +1 -1
- data/views/storage_snapshots/show.xml.haml +1 -0
- data/views/storage_volumes/attach.html.haml +1 -2
- data/views/storage_volumes/index.html.haml +1 -1
- data/views/storage_volumes/new.html.haml +22 -16
- data/views/storage_volumes/show.html.haml +10 -4
- data/views/storage_volumes/show.xml.haml +3 -4
- metadata +547 -519
- data/DISCLAIMER +0 -8
- data/lib/cimi/model.rb +0 -52
- data/lib/cimi/model/network.rb +0 -69
- data/lib/deltacloud/base_driver.rb +0 -18
- data/lib/deltacloud/base_driver/features.rb +0 -262
- data/lib/deltacloud/base_driver/mock_driver.rb +0 -78
- data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +0 -186
- data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +0 -521
- data/lib/deltacloud/helpers/application_helper.rb +0 -267
- data/lib/deltacloud/helpers/hardware_profiles_helper.rb +0 -50
- data/lib/deltacloud/helpers/json_helper.rb +0 -31
- data/lib/deltacloud/method_serializer.rb +0 -83
- data/lib/deltacloud/validation.rb +0 -107
- data/lib/sinatra/rabbit.rb +0 -441
- data/lib/sinatra/rack_runtime.rb +0 -47
- data/lib/sinatra/rack_syslog.rb +0 -86
- data/lib/sinatra/sinatra_verbose.rb +0 -73
- data/lib/sinatra/static_assets.rb +0 -99
- data/public/javascripts/jquery.mobile-1.0rc1.min.js +0 -170
- data/public/stylesheets/jquery.mobile-1.0rc1.min.css +0 -12
- data/tests/drivers/google/setup.rb +0 -38
- data/tests/drivers/mock/instance_states_test.rb +0 -71
- data/tests/drivers/mock/setup.rb +0 -3
- data/tests/drivers/mock/url_for_test.rb +0 -67
- data/tests/drivers/openstack/setup.rb +0 -20
- data/views/cimi/errors/400.html.haml +0 -41
- data/views/cimi/errors/401.html.haml +0 -41
- data/views/cimi/errors/404.html.haml +0 -29
- data/views/cimi/errors/405.html.haml +0 -29
- data/views/cimi/errors/502.html.haml +0 -43
- data/views/cimi/errors/backend_capability_failure.html.haml +0 -29
@@ -18,11 +18,30 @@
|
|
18
18
|
require 'rubygems'
|
19
19
|
require 'uri'
|
20
20
|
|
21
|
+
require 'digest/sha1'
|
21
22
|
require 'net/https'
|
22
23
|
|
24
|
+
require "rexml/document"
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rexml/formatters/pretty'
|
28
|
+
REXML_FORMATTERS=true
|
29
|
+
rescue LoadError
|
30
|
+
REXML_FORMATTERS=false
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'curb'
|
35
|
+
CURL_LOADED=true
|
36
|
+
rescue LoadError
|
37
|
+
CURL_LOADED=false
|
38
|
+
end
|
39
|
+
|
23
40
|
begin
|
24
|
-
|
41
|
+
require 'net/http/post/multipart'
|
42
|
+
MULTIPART_LOADED=true
|
25
43
|
rescue LoadError
|
44
|
+
MULTIPART_LOADED=false
|
26
45
|
end
|
27
46
|
|
28
47
|
###############################################################################
|
@@ -30,85 +49,100 @@ end
|
|
30
49
|
# Cloud Client
|
31
50
|
###############################################################################
|
32
51
|
module CloudClient
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
raise "Authorization data malformed" if one_auth.length < 2
|
55
|
-
|
56
|
-
one_auth
|
52
|
+
# #########################################################################
|
53
|
+
# Default location for the authentication file
|
54
|
+
# #########################################################################
|
55
|
+
DEFAULT_AUTH_FILE = ENV["HOME"]+"/.one/one_auth"
|
56
|
+
|
57
|
+
# #########################################################################
|
58
|
+
# Gets authorization credentials from ONE_AUTH or default
|
59
|
+
# auth file.
|
60
|
+
#
|
61
|
+
# Raises an error if authorization is not found
|
62
|
+
# #########################################################################
|
63
|
+
def self.get_one_auth
|
64
|
+
if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
|
65
|
+
File.file?(ENV["ONE_AUTH"])
|
66
|
+
one_auth=File.read(ENV["ONE_AUTH"]).strip.split(':')
|
67
|
+
elsif File.file?(DEFAULT_AUTH_FILE)
|
68
|
+
one_auth=File.read(DEFAULT_AUTH_FILE).strip.split(':')
|
69
|
+
else
|
70
|
+
raise "No authorization data present"
|
57
71
|
end
|
58
72
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
rescue Errno::ECONNREFUSED => e
|
75
|
-
str = "Error connecting to server (#{e.to_s})."
|
76
|
-
str << "Server: #{url.host}:#{url.port}"
|
77
|
-
|
78
|
-
return CloudClient::Error.new(str)
|
79
|
-
end
|
73
|
+
raise "Authorization data malformed" if one_auth.length < 2
|
74
|
+
|
75
|
+
one_auth
|
76
|
+
end
|
77
|
+
|
78
|
+
# #########################################################################
|
79
|
+
# Starts an http connection and calls the block provided. SSL flag
|
80
|
+
# is set if needed.
|
81
|
+
# #########################################################################
|
82
|
+
def self.http_start(url, timeout, &block)
|
83
|
+
http = Net::HTTP.new(url.host, url.port)
|
84
|
+
|
85
|
+
if timeout
|
86
|
+
http.read_timeout = timeout.to_i
|
80
87
|
end
|
81
88
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# #########################################################################
|
86
|
-
class Error
|
87
|
-
attr_reader :message
|
88
|
-
|
89
|
-
# +message+ a description of the error
|
90
|
-
def initialize(message=nil)
|
91
|
-
@message=message
|
92
|
-
end
|
93
|
-
|
94
|
-
def to_s()
|
95
|
-
@message
|
96
|
-
end
|
89
|
+
if url.scheme=='https'
|
90
|
+
http.use_ssl = true
|
91
|
+
http.verify_mode=OpenSSL::SSL::VERIFY_NONE
|
97
92
|
end
|
98
93
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
94
|
+
begin
|
95
|
+
res = http.start do |connection|
|
96
|
+
block.call(connection)
|
97
|
+
end
|
98
|
+
rescue Errno::ECONNREFUSED => e
|
99
|
+
str = "Error connecting to server (#{e.to_s}).\n"
|
100
|
+
str << "Server: #{url.host}:#{url.port}"
|
101
|
+
|
102
|
+
return CloudClient::Error.new(str,"503")
|
103
|
+
rescue Errno::ETIMEDOUT => e
|
104
|
+
str = "Error timeout connecting to server (#{e.to_s}).\n"
|
105
|
+
str << "Server: #{url.host}:#{url.port}"
|
106
|
+
|
107
|
+
return CloudClient::Error.new(str,"504")
|
108
|
+
rescue Timeout::Error => e
|
109
|
+
str = "Error timeout while connected to server (#{e.to_s}).\n"
|
110
|
+
str << "Server: #{url.host}:#{url.port}"
|
111
|
+
|
112
|
+
return CloudClient::Error.new(str,"504")
|
105
113
|
end
|
106
|
-
end
|
107
114
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
File.basename($0)
|
115
|
+
if res.is_a?(Net::HTTPSuccess)
|
116
|
+
res
|
117
|
+
else
|
118
|
+
CloudClient::Error.new(res.body, res.code)
|
113
119
|
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# #########################################################################
|
123
|
+
# The Error Class represents a generic error in the Cloud Client
|
124
|
+
# library. It contains a readable representation of the error.
|
125
|
+
# #########################################################################
|
126
|
+
class Error
|
127
|
+
attr_reader :message
|
128
|
+
attr_reader :code
|
129
|
+
|
130
|
+
# +message+ a description of the error
|
131
|
+
def initialize(message=nil, code="500")
|
132
|
+
@message=message
|
133
|
+
@code=code
|
134
|
+
end
|
135
|
+
|
136
|
+
def to_s()
|
137
|
+
@message
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# #########################################################################
|
142
|
+
# Returns true if the object returned by a method of the OpenNebula
|
143
|
+
# library is an Error
|
144
|
+
# #########################################################################
|
145
|
+
def self.is_error?(value)
|
146
|
+
value.class==CloudClient::Error
|
147
|
+
end
|
114
148
|
end
|
@@ -16,187 +16,327 @@
|
|
16
16
|
#
|
17
17
|
|
18
18
|
require 'rubygems'
|
19
|
-
require 'uri'
|
20
19
|
require 'rexml/document'
|
20
|
+
require 'uri'
|
21
21
|
|
22
22
|
require 'deltacloud/drivers/opennebula/cloud_client'
|
23
23
|
|
24
24
|
|
25
25
|
module OCCIClient
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
27
|
+
#####################################################################
|
28
|
+
# Client Library to interface with the OpenNebula OCCI Service
|
29
|
+
#####################################################################
|
30
|
+
class Client
|
31
|
+
|
32
|
+
attr_accessor :endpoint
|
33
|
+
|
34
|
+
######################################################################
|
35
|
+
# Initialize client library
|
36
|
+
######################################################################
|
37
|
+
def initialize(endpoint_str=nil, user=nil, pass=nil,
|
38
|
+
timeout=nil, debug_flag=true)
|
39
|
+
@debug = debug_flag
|
40
|
+
@timeout = timeout
|
41
|
+
|
42
|
+
# Server location
|
43
|
+
@endpoint = ENV["OCCI_URL"] || endpoint_str || Proc.new(raise "No OpenNebula Provider location configured! Client needs to set \'X-Deltacloud-Provider\' HTTP request header, OR, Deltacloud server administrator must set either the OCCI_URL or API_PROVIDER environment variables")
|
44
|
+
#"http://localhost:4567"
|
45
|
+
|
46
|
+
# Autentication
|
47
|
+
if user && pass
|
48
|
+
@occiauth = [user, pass]
|
49
|
+
else
|
50
|
+
@occiauth = CloudClient::get_one_auth
|
51
|
+
end
|
52
|
+
|
53
|
+
if !@occiauth
|
54
|
+
raise "No authorization data present"
|
55
|
+
end
|
56
|
+
|
57
|
+
@occiauth[1] = Digest::SHA1.hexdigest(@occiauth[1])
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
#################################
|
61
|
+
# Pool Resource Request Methods #
|
62
|
+
#################################
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
def get_root
|
65
|
+
get('/')
|
66
|
+
end
|
67
|
+
|
68
|
+
######################################################################
|
69
|
+
# Retieves the available Instance types
|
70
|
+
######################################################################
|
71
|
+
def get_instance_types
|
72
|
+
get('/instance_type?verbose=yes')
|
73
|
+
end
|
72
74
|
|
73
|
-
|
75
|
+
######################################################################
|
76
|
+
# Post a new VM to the VM Pool
|
77
|
+
# :xmlfile
|
78
|
+
######################################################################
|
79
|
+
def post_vms(xmlfile)
|
80
|
+
post('/compute', xmlfile)
|
81
|
+
end
|
74
82
|
|
75
|
-
|
76
|
-
|
83
|
+
######################################################################
|
84
|
+
# Retieves the pool of Virtual Machines
|
85
|
+
######################################################################
|
86
|
+
def get_vms
|
87
|
+
get('/compute')
|
88
|
+
end
|
77
89
|
|
78
|
-
|
90
|
+
######################################################################
|
91
|
+
# Post a new Network to the VN Pool
|
92
|
+
# :xmlfile xml description of the Virtual Network
|
93
|
+
######################################################################
|
94
|
+
def post_network(xmlfile)
|
95
|
+
post('/network', xmlfile)
|
96
|
+
end
|
79
97
|
|
80
|
-
|
81
|
-
|
82
|
-
|
98
|
+
######################################################################
|
99
|
+
# Retieves the pool of Virtual Networks
|
100
|
+
######################################################################
|
101
|
+
def get_networks
|
102
|
+
get('/network')
|
103
|
+
end
|
83
104
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
105
|
+
######################################################################
|
106
|
+
# Post a new Image to the Image Pool
|
107
|
+
# :xmlfile
|
108
|
+
######################################################################
|
109
|
+
def post_image(xmlfile, curb=true)
|
110
|
+
xml = File.read(xmlfile)
|
90
111
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
112
|
+
begin
|
113
|
+
image_info = REXML::Document.new(xml).root
|
114
|
+
rescue Exception => e
|
115
|
+
error = CloudClient::Error.new(e.message)
|
116
|
+
return error
|
117
|
+
end
|
97
118
|
|
98
|
-
|
119
|
+
if image_info.elements['URL']
|
120
|
+
file_path = image_info.elements['URL'].text
|
99
121
|
|
100
|
-
|
101
|
-
http.request(req)
|
102
|
-
}
|
122
|
+
m = file_path.match(/^\w+:\/\/(.*)$/)
|
103
123
|
|
104
|
-
|
105
|
-
|
106
|
-
else
|
107
|
-
return res.body
|
108
|
-
end
|
124
|
+
if m
|
125
|
+
file_path="/"+m[1]
|
109
126
|
end
|
127
|
+
elsif !image_info.elements['TYPE'] == "DATABLOCK"
|
128
|
+
return CloudClient::Error.new("Can not find URL")
|
129
|
+
end
|
130
|
+
|
131
|
+
if curb
|
132
|
+
if !CURL_LOADED
|
133
|
+
error_msg = "curb gem not loaded"
|
134
|
+
error = CloudClient::Error.new(error_msg)
|
135
|
+
return error
|
136
|
+
end
|
137
|
+
|
138
|
+
curl=Curl::Easy.new(@endpoint+"/storage")
|
110
139
|
|
111
|
-
|
112
|
-
#
|
113
|
-
|
114
|
-
|
115
|
-
url = URI.parse(@endpoint+"/storage")
|
116
|
-
req = Net::HTTP::Get.new(url.path)
|
140
|
+
curl.http_auth_types = Curl::CURLAUTH_BASIC
|
141
|
+
curl.userpwd = "#{@occiauth[0]}:#{@occiauth[1]}"
|
142
|
+
curl.verbose = true if @debug
|
143
|
+
curl.multipart_form_post = true
|
117
144
|
|
118
|
-
|
145
|
+
begin
|
146
|
+
postfields = Array.new
|
147
|
+
postfields << Curl::PostField.content('occixml', xml)
|
119
148
|
|
120
|
-
|
121
|
-
|
122
|
-
|
149
|
+
if file_path
|
150
|
+
postfields << Curl::PostField.file('file', file_path)
|
151
|
+
end
|
123
152
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
return res.body
|
128
|
-
end
|
153
|
+
curl.http_post(*postfields)
|
154
|
+
rescue Exception => e
|
155
|
+
return CloudClient::Error.new(e.message)
|
129
156
|
end
|
130
157
|
|
131
|
-
|
132
|
-
|
133
|
-
|
158
|
+
return curl.body_str
|
159
|
+
else
|
160
|
+
if !MULTIPART_LOADED
|
161
|
+
error_msg = "multipart-post gem not loaded"
|
162
|
+
error = CloudClient::Error.new(error_msg)
|
163
|
+
return error
|
164
|
+
end
|
134
165
|
|
135
|
-
|
136
|
-
# :id VM identifier
|
137
|
-
######################################################################
|
138
|
-
def get_vm(id)
|
139
|
-
url = URI.parse(@endpoint+"/compute/" + id.to_s)
|
140
|
-
req = Net::HTTP::Get.new(url.path)
|
166
|
+
params=Hash.new
|
141
167
|
|
142
|
-
|
168
|
+
if file_path
|
169
|
+
file=File.open(file_path)
|
170
|
+
params["file"]=UploadIO.new(file,
|
171
|
+
'application/octet-stream', file_path)
|
172
|
+
end
|
143
173
|
|
144
|
-
|
145
|
-
http.request(req)
|
146
|
-
}
|
174
|
+
params['occixml'] = xml
|
147
175
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
176
|
+
url = URI.parse(@endpoint+"/storage")
|
177
|
+
|
178
|
+
req = Net::HTTP::Post::Multipart.new(url.path, params)
|
179
|
+
|
180
|
+
req.basic_auth @occiauth[0], @occiauth[1]
|
181
|
+
|
182
|
+
res = CloudClient::http_start(url, @timeout) do |http|
|
183
|
+
http.request(req)
|
153
184
|
end
|
154
185
|
|
155
|
-
|
156
|
-
# Puts a new Compute representation in order to change its state
|
157
|
-
# :xmlfile Compute OCCI xml representation
|
158
|
-
######################################################################
|
159
|
-
def put_vm(xmlfile)
|
160
|
-
xml=File.read(xmlfile)
|
161
|
-
vm_info=REXML::Document.new(xml).root.elements
|
186
|
+
file.close if file_path
|
162
187
|
|
163
|
-
|
188
|
+
if CloudClient::is_error?(res)
|
189
|
+
return res
|
190
|
+
else
|
191
|
+
return res.body
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
164
195
|
|
165
|
-
|
166
|
-
|
196
|
+
######################################################################
|
197
|
+
# Retieves the pool of Images owned by the user
|
198
|
+
######################################################################
|
199
|
+
def get_images
|
200
|
+
get('/storage')
|
201
|
+
end
|
167
202
|
|
168
|
-
req.basic_auth @occiauth[0], @occiauth[1]
|
169
203
|
|
170
|
-
|
171
|
-
|
172
|
-
|
204
|
+
####################################
|
205
|
+
# Entity Resource Request Methods #
|
206
|
+
####################################
|
173
207
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
208
|
+
######################################################################
|
209
|
+
# :id VM identifier
|
210
|
+
######################################################################
|
211
|
+
def get_vm(id)
|
212
|
+
get('/compute/'+id.to_s)
|
213
|
+
end
|
180
214
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
215
|
+
######################################################################
|
216
|
+
# Puts a new Compute representation in order to change its state
|
217
|
+
# :xmlfile Compute OCCI xml representation
|
218
|
+
######################################################################
|
219
|
+
def put_vm(xmlfile)
|
220
|
+
put('/compute/', xmlfile)
|
221
|
+
end
|
222
|
+
|
223
|
+
####################################################################
|
224
|
+
# :id Compute identifier
|
225
|
+
####################################################################
|
226
|
+
def delete_vm(id)
|
227
|
+
delete('/compute/'+id.to_s)
|
228
|
+
end
|
229
|
+
|
230
|
+
######################################################################
|
231
|
+
# Retrieves a Virtual Network
|
232
|
+
# :id Virtual Network identifier
|
233
|
+
######################################################################
|
234
|
+
def get_network(id)
|
235
|
+
get('/network/'+id.to_s)
|
236
|
+
end
|
237
|
+
|
238
|
+
######################################################################
|
239
|
+
# Puts a new Network representation in order to change its state
|
240
|
+
# :xmlfile Network OCCI xml representation
|
241
|
+
######################################################################
|
242
|
+
def put_network(xmlfile)
|
243
|
+
put('/network/', xmlfile)
|
244
|
+
end
|
245
|
+
|
246
|
+
######################################################################
|
247
|
+
# :id VM identifier
|
248
|
+
######################################################################
|
249
|
+
def delete_network(id)
|
250
|
+
delete('/network/'+id.to_s)
|
251
|
+
end
|
252
|
+
|
253
|
+
#######################################################################
|
254
|
+
# Retieves an Image
|
255
|
+
# :image_uuid Image identifier
|
256
|
+
######################################################################
|
257
|
+
def get_image(id)
|
258
|
+
get('/storage/'+id.to_s)
|
259
|
+
end
|
260
|
+
|
261
|
+
######################################################################
|
262
|
+
# Puts a new Storage representation in order to change its state
|
263
|
+
# :xmlfile Storage OCCI xml representation
|
264
|
+
######################################################################
|
265
|
+
def put_image(xmlfile)
|
266
|
+
put('/storage/', xmlfile)
|
267
|
+
end
|
268
|
+
|
269
|
+
######################################################################
|
270
|
+
# :id VM identifier
|
271
|
+
######################################################################
|
272
|
+
def delete_image(id)
|
273
|
+
delete('/storage/'+id.to_s)
|
274
|
+
end
|
275
|
+
|
276
|
+
private
|
277
|
+
|
278
|
+
def get(path)
|
279
|
+
url = URI.parse(@endpoint+path)
|
280
|
+
path = url.path
|
281
|
+
path << "?#{url.query}" if url.query
|
282
|
+
req = Net::HTTP::Get.new(path)
|
283
|
+
|
284
|
+
do_request(url, req)
|
285
|
+
end
|
286
|
+
|
287
|
+
def post(path, xmlfile)
|
288
|
+
url = URI.parse(@endpoint+path)
|
289
|
+
req = Net::HTTP::Post.new(url.path)
|
290
|
+
|
291
|
+
req.body=File.read(xmlfile)
|
292
|
+
|
293
|
+
do_request(url, req)
|
294
|
+
end
|
295
|
+
|
296
|
+
def delete(path, xmlfile)
|
297
|
+
url = URI.parse(@endpoint+path)
|
298
|
+
req = Net::HTTP::Delete.new(url.path)
|
299
|
+
|
300
|
+
do_request(url, req)
|
301
|
+
end
|
302
|
+
|
303
|
+
def put(path, xmlfile)
|
304
|
+
xml = File.read(xmlfile)
|
305
|
+
|
306
|
+
# Get ID from XML
|
307
|
+
begin
|
308
|
+
info = REXML::Document.new(xml).root
|
309
|
+
rescue Exception => e
|
310
|
+
error = CloudClient::Error.new(e.message)
|
311
|
+
return error
|
312
|
+
end
|
313
|
+
|
314
|
+
if info.elements['ID'] == nil
|
315
|
+
return CloudClient::Error.new("Can not find RESOURCE ID")
|
316
|
+
end
|
317
|
+
|
318
|
+
resource_id = info.elements['ID'].text
|
319
|
+
|
320
|
+
url = URI.parse(@endpoint+path + resource_id)
|
321
|
+
req = Net::HTTP::Put.new(url.path)
|
322
|
+
|
323
|
+
req.body = xml
|
324
|
+
|
325
|
+
do_request(url, req)
|
326
|
+
end
|
327
|
+
|
328
|
+
def do_request(url, req)
|
329
|
+
req.basic_auth @occiauth[0], @occiauth[1]
|
330
|
+
|
331
|
+
res = CloudClient::http_start(url, @timeout) do |http|
|
332
|
+
http.request(req)
|
333
|
+
end
|
334
|
+
|
335
|
+
if CloudClient::is_error?(res)
|
336
|
+
return res
|
337
|
+
else
|
338
|
+
return res.body
|
339
|
+
end
|
201
340
|
end
|
341
|
+
end
|
202
342
|
end
|