2014-02-01 21:13:17 -05:00
|
|
|
require 'fog/core'
|
2014-02-19 09:29:09 -05:00
|
|
|
require 'fog/json'
|
2014-02-01 21:13:17 -05:00
|
|
|
require 'uri'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Cloudstack
|
|
|
|
extend Fog::Provider
|
|
|
|
|
2014-02-01 22:02:40 -05:00
|
|
|
service(:compute, 'Compute')
|
2014-02-01 21:13:17 -05:00
|
|
|
|
|
|
|
@@digest = OpenSSL::Digest.new('sha1')
|
|
|
|
|
|
|
|
def self.escape(string)
|
|
|
|
string = CGI::escape(string)
|
|
|
|
string = string.gsub("+","%20")
|
|
|
|
string
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.signed_params(key,params)
|
2014-05-22 21:40:43 -04:00
|
|
|
query = params.map{|k,v| [k.to_s, v]}.sort.map{|c| "#{c[0]}=#{escape(c[1].to_s)}"}.join('&').downcase
|
2014-02-01 21:13:17 -05:00
|
|
|
|
|
|
|
signed_string = Base64.encode64(OpenSSL::HMAC.digest(@@digest,key,query)).strip
|
|
|
|
|
|
|
|
signed_string
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.uuid
|
|
|
|
[8,4,4,4,12].map{|i| Fog::Mock.random_hex(i)}.join("-")
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.ip_address
|
|
|
|
4.times.map{ Fog::Mock.random_numbers(3) }.join(".")
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.mac_address
|
|
|
|
6.times.map{ Fog::Mock.random_numbers(2) }.join(":")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|