Module: CloudClient

Defined in:
lib/deltacloud/drivers/opennebula/cloud_client.rb

Overview

The CloudClient module contains general functionality to implement a Cloud Client

Defined Under Namespace

Classes: Error

Constant Summary collapse

DEFAULT_AUTH_FILE =

######################################################################### Default location for the authentication file #########################################################################

ENV["HOME"]+"/.one/one_auth"

Class Method Summary collapse

Class Method Details

.get_one_authObject

######################################################################### Gets authorization credentials from ONE_AUTH or default auth file.

Raises an error if authorization is not found #########################################################################



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/deltacloud/drivers/opennebula/cloud_client.rb', line 46

def self.get_one_auth
    if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
       File.file?(ENV["ONE_AUTH"])
        one_auth=File.read(ENV["ONE_AUTH"]).strip.split(':')
    elsif File.file?(DEFAULT_AUTH_FILE)
        one_auth=File.read(DEFAULT_AUTH_FILE).strip.split(':')
    else
        raise "No authorization data present"
    end

    raise "Authorization data malformed" if one_auth.length < 2

    one_auth
end

.http_start(url, &block) ⇒ Object

######################################################################### Starts an http connection and calls the block provided. SSL flag is set if needed. #########################################################################



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/deltacloud/drivers/opennebula/cloud_client.rb', line 65

def self.http_start(url, &block)
    http = Net::HTTP.new(url.host, url.port)
    if url.scheme=='https'
        http.use_ssl = true
        http.verify_mode=OpenSSL::SSL::VERIFY_NONE
    end

    begin
        http.start do |connection|
            block.call(connection)
        end
    rescue Errno::ECONNREFUSED => e
        str =  "Error connecting to server (#{e.to_s})."
        str << "Server: #{url.host}:#{url.port}"

        return CloudClient::Error.new(str)
    end
end

.is_error?(value) ⇒ Boolean

######################################################################### Returns true if the object returned by a method of the OpenNebula library is an Error #########################################################################

Returns:

  • (Boolean)


105
106
107
# File 'lib/deltacloud/drivers/opennebula/cloud_client.rb', line 105

def self.is_error?(value)
    value.class==CloudClient::Error
end