create core for each provider. keep load hook for provider.

This commit is contained in:
Lance Ivy 2014-02-01 21:13:17 -05:00
parent 35c777044e
commit 1cdd969a34
179 changed files with 2466 additions and 2364 deletions

View File

@ -1,11 +1 @@
require 'fog/core'
module Fog
module Atmos
extend Fog::Provider
service(:storage, 'atmos/storage', 'Storage')
end
end
require 'fog/atmos/storage'

11
lib/fog/atmos/core.rb Normal file
View File

@ -0,0 +1,11 @@
require 'fog/core'
module Fog
module Atmos
extend Fog::Provider
service(:storage, 'atmos/storage', 'Storage')
end
end

View File

@ -1,4 +1,4 @@
require 'fog/atmos'
require 'fog/atmos/core'
require 'fog/storage'
module Fog

View File

@ -1,329 +1,22 @@
require 'fog/core'
require 'fog/aws/credential_fetcher'
require 'fog/aws/signaturev4'
module Fog
module AWS
extend Fog::Provider
service(:auto_scaling, 'aws/auto_scaling', 'AutoScaling')
service(:beanstalk, 'aws/beanstalk', 'ElasticBeanstalk')
service(:cdn, 'aws/cdn', 'CDN')
service(:compute, 'aws/compute', 'Compute')
service(:cloud_formation, 'aws/cloud_formation', 'CloudFormation')
service(:cloud_watch, 'aws/cloud_watch', 'CloudWatch')
service(:data_pipeline, 'aws/data_pipeline', 'DataPipeline')
service(:dynamodb, 'aws/dynamodb', 'DynamoDB')
service(:dns, 'aws/dns', 'DNS')
service(:elasticache, 'aws/elasticache', 'Elasticache')
service(:elb, 'aws/elb', 'ELB')
service(:emr, 'aws/emr', 'EMR')
service(:glacier, 'aws/glacier', 'Glacier')
service(:iam, 'aws/iam', 'IAM')
service(:rds, 'aws/rds', 'RDS')
service(:redshift, 'aws/redshift', 'Redshift')
service(:ses, 'aws/ses', 'SES')
service(:simpledb, 'aws/simpledb', 'SimpleDB')
service(:sns, 'aws/sns', 'SNS')
service(:sqs, 'aws/sqs', 'SQS')
service(:sts, 'aws/sts', 'STS')
service(:storage, 'aws/storage', 'Storage')
def self.indexed_param(key, values)
params = {}
unless key.include?('%d')
key << '.%d'
end
[*values].each_with_index do |value, index|
if value.respond_to?('keys')
k = format(key, index + 1)
value.each do | vkey, vvalue |
params["#{k}.#{vkey}"] = vvalue
end
else
params[format(key, index + 1)] = value
end
end
params
end
def self.serialize_keys(key, value, options = {})
case value
when Hash
value.each do | k, v |
options.merge!(serialize_keys("#{key}.#{k}", v))
end
return options
when Array
value.each_with_index do | it, idx |
options.merge!(serialize_keys("#{key}.member.#{(idx + 1)}", it))
end
return options
else
return {key => value}
end
end
def self.indexed_request_param(name, values)
idx = -1
Array(values).inject({}) do |params, value|
params["#{name}.#{idx += 1}"] = value
params
end
end
def self.indexed_filters(filters)
params = {}
filters.keys.each_with_index do |key, key_index|
key_index += 1
params[format('Filter.%d.Name', key_index)] = key
[*filters[key]].each_with_index do |value, value_index|
value_index += 1
params[format('Filter.%d.Value.%d', key_index, value_index)] = value
end
end
params
end
def self.escape(string)
unless @unf_loaded_or_warned
begin
require('unf/normalizer')
rescue LoadError
Fog::Logger.warning("Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.")
end
@unf_loaded_or_warned = true
end
string = defined?(::UNF::Normalizer) ? ::UNF::Normalizer.normalize(string, :nfc) : string
string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
}
end
def self.signed_params(params, options = {})
params.merge!({
'AWSAccessKeyId' => options[:aws_access_key_id],
'SignatureMethod' => 'HmacSHA256',
'SignatureVersion' => '2',
'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
'Version' => options[:version]
})
params.merge!({
'SecurityToken' => options[:aws_session_token]
}) if options[:aws_session_token]
body = ''
for key in params.keys.sort
unless (value = params[key]).nil?
body << "#{key}=#{escape(value.to_s)}&"
end
end
string_to_sign = "POST\n#{options[:host]}:#{options[:port]}\n#{options[:path]}\n" << body.chop
signed_string = options[:hmac].sign(string_to_sign)
body << "Signature=#{escape(Base64.encode64(signed_string).chomp!)}"
body
end
class Mock
def self.arn(vendor, account_id, path, region = nil)
"arn:aws:#{vendor}:#{region}:#{account_id}:#{path}"
end
def self.availability_zone(region)
"#{region}#{Fog::Mock.random_selection('abcd', 1)}"
end
def self.box_usage
sprintf("%0.10f", rand / 100).to_f
end
def self.console_output
# "[ 0.000000] Linux version 2.6.18-xenU-ec2-v1.2 (root@domU-12-31-39-07-51-82) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)) #2 SMP Wed Aug 19 09:04:38 EDT 2009"
Base64.decode64("WyAwLjAwMDAwMF0gTGludXggdmVyc2lvbiAyLjYuMTgteGVuVS1lYzItdjEu\nMiAocm9vdEBkb21VLTEyLTMxLTM5LTA3LTUxLTgyKSAoZ2NjIHZlcnNpb24g\nNC4xLjIgMjAwNzA2MjYgKFJlZCBIYXQgNC4xLjItMTMpKSAjMiBTTVAgV2Vk\nIEF1ZyAxOSAwOTowNDozOCBFRFQgMjAwOQ==\n")
end
def self.dns_name_for(ip_address)
"ec2-#{ip_address.gsub('.','-')}.compute-1.amazonaws.com"
end
def self.private_dns_name_for(ip_address)
"ip-#{ip_address.gsub('.','-')}.ec2.internal"
end
def self.image
path = []
(rand(3) + 2).times do
path << Fog::Mock.random_letters(rand(9) + 8)
end
{
"imageOwnerId" => Fog::Mock.random_letters(rand(5) + 4),
"blockDeviceMapping" => [],
"productCodes" => [],
"kernelId" => kernel_id,
"ramdiskId" => ramdisk_id,
"imageState" => "available",
"imageId" => image_id,
"architecture" => "i386",
"isPublic" => true,
"imageLocation" => path.join('/'),
"imageType" => "machine",
"rootDeviceType" => ["ebs","instance-store"][rand(2)],
"rootDeviceName" => "/dev/sda1"
}
end
def self.image_id
"ami-#{Fog::Mock.random_hex(8)}"
end
def self.key_fingerprint
fingerprint = []
20.times do
fingerprint << Fog::Mock.random_hex(2)
end
fingerprint.join(':')
end
def self.instance_id
"i-#{Fog::Mock.random_hex(8)}"
end
def self.ip_address
Fog::Mock.random_ip
end
def self.private_ip_address
ip_address.gsub(/^\d{1,3}\./,"10.")
end
def self.kernel_id
"aki-#{Fog::Mock.random_hex(8)}"
end
def self.key_material
OpenSSL::PKey::RSA.generate(1024).to_s
end
def self.owner_id
Fog::Mock.random_numbers(12)
end
def self.ramdisk_id
"ari-#{Fog::Mock.random_hex(8)}"
end
def self.request_id
request_id = []
request_id << Fog::Mock.random_hex(8)
3.times do
request_id << Fog::Mock.random_hex(4)
end
request_id << Fog::Mock.random_hex(12)
request_id.join('-')
end
class << self
alias :reserved_instances_id :request_id
alias :reserved_instances_offering_id :request_id
alias :sqs_message_id :request_id
alias :sqs_sender_id :request_id
end
def self.reservation_id
"r-#{Fog::Mock.random_hex(8)}"
end
def self.snapshot_id
"snap-#{Fog::Mock.random_hex(8)}"
end
def self.volume_id
"vol-#{Fog::Mock.random_hex(8)}"
end
def self.security_group_id
"sg-#{Fog::Mock.random_hex(8)}"
end
def self.network_acl_id
"acl-#{Fog::Mock.random_hex(8)}"
end
def self.network_acl_association_id
"aclassoc-#{Fog::Mock.random_hex(8)}"
end
def self.network_interface_id
"eni-#{Fog::Mock.random_hex(8)}"
end
def self.internet_gateway_id
"igw-#{Fog::Mock.random_hex(8)}"
end
def self.dhcp_options_id
"dopt-#{Fog::Mock.random_hex(8)}"
end
def self.vpc_id
"vpc-#{Fog::Mock.random_hex(8)}"
end
def self.subnet_id
"subnet-#{Fog::Mock.random_hex(8)}"
end
def self.zone_id
"zone-#{Fog::Mock.random_hex(8)}"
end
def self.change_id
Fog::Mock.random_letters_and_numbers(14)
end
def self.nameservers
[
'ns-2048.awsdns-64.com',
'ns-2049.awsdns-65.net',
'ns-2050.awsdns-66.org',
'ns-2051.awsdns-67.co.uk'
]
end
def self.key_id(length=21)
#Probably close enough
Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',length)
end
def self.rds_address(db_name,region)
"#{db_name}.#{Fog::Mock.random_letters(rand(12) + 4)}.#{region}.rds.amazonaws.com"
end
end
def self.parse_security_group_options(group_name, options)
options ||= Hash.new
if group_name.is_a?(Hash)
options = group_name
elsif group_name
if options.key?('GroupName')
raise Fog::Compute::AWS::Error, 'Arguments specified both group_name and GroupName in options'
end
options = options.clone
options['GroupName'] = group_name
end
name_specified = options.key?('GroupName') && !options['GroupName'].nil?
group_id_specified = options.key?('GroupId') && !options['GroupId'].nil?
unless name_specified || group_id_specified
raise Fog::Compute::AWS::Error, 'Neither GroupName nor GroupId specified'
end
if name_specified && group_id_specified
options.delete('GroupName')
end
options
end
module Errors
def self.match_error(error)
matcher = lambda {|s| s.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)}
[error.message, error.response.body].each(&Proc.new {|s|
match = matcher.call(s)
return {:code => match[1].split('.').last, :message => match[2]} if match
})
{} # we did not match the message or response body
end
end
end
end
require 'fog/aws/auto_scaling'
require 'fog/aws/beanstalk'
require 'fog/aws/cdn'
require 'fog/aws/cloud_formation'
require 'fog/aws/cloud_watch'
require 'fog/aws/compute'
require 'fog/aws/data_pipeline'
require 'fog/aws/dns'
require 'fog/aws/dynamodb'
require 'fog/aws/elasticache'
require 'fog/aws/elb'
require 'fog/aws/emr'
require 'fog/aws/glacier'
require 'fog/aws/iam'
require 'fog/aws/rds'
require 'fog/aws/redshift'
require 'fog/aws/ses'
require 'fog/aws/simpledb'
require 'fog/aws/sns'
require 'fog/aws/sqs'
require 'fog/aws/storage'
require 'fog/aws/sts'

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
require 'fog/cdn'
module Fog

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
require 'fog/compute'
module Fog

329
lib/fog/aws/core.rb Normal file
View File

@ -0,0 +1,329 @@
require 'fog/core'
require 'fog/aws/credential_fetcher'
require 'fog/aws/signaturev4'
module Fog
module AWS
extend Fog::Provider
service(:auto_scaling, 'aws/auto_scaling', 'AutoScaling')
service(:beanstalk, 'aws/beanstalk', 'ElasticBeanstalk')
service(:cdn, 'aws/cdn', 'CDN')
service(:compute, 'aws/compute', 'Compute')
service(:cloud_formation, 'aws/cloud_formation', 'CloudFormation')
service(:cloud_watch, 'aws/cloud_watch', 'CloudWatch')
service(:data_pipeline, 'aws/data_pipeline', 'DataPipeline')
service(:dynamodb, 'aws/dynamodb', 'DynamoDB')
service(:dns, 'aws/dns', 'DNS')
service(:elasticache, 'aws/elasticache', 'Elasticache')
service(:elb, 'aws/elb', 'ELB')
service(:emr, 'aws/emr', 'EMR')
service(:glacier, 'aws/glacier', 'Glacier')
service(:iam, 'aws/iam', 'IAM')
service(:rds, 'aws/rds', 'RDS')
service(:redshift, 'aws/redshift', 'Redshift')
service(:ses, 'aws/ses', 'SES')
service(:simpledb, 'aws/simpledb', 'SimpleDB')
service(:sns, 'aws/sns', 'SNS')
service(:sqs, 'aws/sqs', 'SQS')
service(:sts, 'aws/sts', 'STS')
service(:storage, 'aws/storage', 'Storage')
def self.indexed_param(key, values)
params = {}
unless key.include?('%d')
key << '.%d'
end
[*values].each_with_index do |value, index|
if value.respond_to?('keys')
k = format(key, index + 1)
value.each do | vkey, vvalue |
params["#{k}.#{vkey}"] = vvalue
end
else
params[format(key, index + 1)] = value
end
end
params
end
def self.serialize_keys(key, value, options = {})
case value
when Hash
value.each do | k, v |
options.merge!(serialize_keys("#{key}.#{k}", v))
end
return options
when Array
value.each_with_index do | it, idx |
options.merge!(serialize_keys("#{key}.member.#{(idx + 1)}", it))
end
return options
else
return {key => value}
end
end
def self.indexed_request_param(name, values)
idx = -1
Array(values).inject({}) do |params, value|
params["#{name}.#{idx += 1}"] = value
params
end
end
def self.indexed_filters(filters)
params = {}
filters.keys.each_with_index do |key, key_index|
key_index += 1
params[format('Filter.%d.Name', key_index)] = key
[*filters[key]].each_with_index do |value, value_index|
value_index += 1
params[format('Filter.%d.Value.%d', key_index, value_index)] = value
end
end
params
end
def self.escape(string)
unless @unf_loaded_or_warned
begin
require('unf/normalizer')
rescue LoadError
Fog::Logger.warning("Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.")
end
@unf_loaded_or_warned = true
end
string = defined?(::UNF::Normalizer) ? ::UNF::Normalizer.normalize(string, :nfc) : string
string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
}
end
def self.signed_params(params, options = {})
params.merge!({
'AWSAccessKeyId' => options[:aws_access_key_id],
'SignatureMethod' => 'HmacSHA256',
'SignatureVersion' => '2',
'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
'Version' => options[:version]
})
params.merge!({
'SecurityToken' => options[:aws_session_token]
}) if options[:aws_session_token]
body = ''
for key in params.keys.sort
unless (value = params[key]).nil?
body << "#{key}=#{escape(value.to_s)}&"
end
end
string_to_sign = "POST\n#{options[:host]}:#{options[:port]}\n#{options[:path]}\n" << body.chop
signed_string = options[:hmac].sign(string_to_sign)
body << "Signature=#{escape(Base64.encode64(signed_string).chomp!)}"
body
end
class Mock
def self.arn(vendor, account_id, path, region = nil)
"arn:aws:#{vendor}:#{region}:#{account_id}:#{path}"
end
def self.availability_zone(region)
"#{region}#{Fog::Mock.random_selection('abcd', 1)}"
end
def self.box_usage
sprintf("%0.10f", rand / 100).to_f
end
def self.console_output
# "[ 0.000000] Linux version 2.6.18-xenU-ec2-v1.2 (root@domU-12-31-39-07-51-82) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)) #2 SMP Wed Aug 19 09:04:38 EDT 2009"
Base64.decode64("WyAwLjAwMDAwMF0gTGludXggdmVyc2lvbiAyLjYuMTgteGVuVS1lYzItdjEu\nMiAocm9vdEBkb21VLTEyLTMxLTM5LTA3LTUxLTgyKSAoZ2NjIHZlcnNpb24g\nNC4xLjIgMjAwNzA2MjYgKFJlZCBIYXQgNC4xLjItMTMpKSAjMiBTTVAgV2Vk\nIEF1ZyAxOSAwOTowNDozOCBFRFQgMjAwOQ==\n")
end
def self.dns_name_for(ip_address)
"ec2-#{ip_address.gsub('.','-')}.compute-1.amazonaws.com"
end
def self.private_dns_name_for(ip_address)
"ip-#{ip_address.gsub('.','-')}.ec2.internal"
end
def self.image
path = []
(rand(3) + 2).times do
path << Fog::Mock.random_letters(rand(9) + 8)
end
{
"imageOwnerId" => Fog::Mock.random_letters(rand(5) + 4),
"blockDeviceMapping" => [],
"productCodes" => [],
"kernelId" => kernel_id,
"ramdiskId" => ramdisk_id,
"imageState" => "available",
"imageId" => image_id,
"architecture" => "i386",
"isPublic" => true,
"imageLocation" => path.join('/'),
"imageType" => "machine",
"rootDeviceType" => ["ebs","instance-store"][rand(2)],
"rootDeviceName" => "/dev/sda1"
}
end
def self.image_id
"ami-#{Fog::Mock.random_hex(8)}"
end
def self.key_fingerprint
fingerprint = []
20.times do
fingerprint << Fog::Mock.random_hex(2)
end
fingerprint.join(':')
end
def self.instance_id
"i-#{Fog::Mock.random_hex(8)}"
end
def self.ip_address
Fog::Mock.random_ip
end
def self.private_ip_address
ip_address.gsub(/^\d{1,3}\./,"10.")
end
def self.kernel_id
"aki-#{Fog::Mock.random_hex(8)}"
end
def self.key_material
OpenSSL::PKey::RSA.generate(1024).to_s
end
def self.owner_id
Fog::Mock.random_numbers(12)
end
def self.ramdisk_id
"ari-#{Fog::Mock.random_hex(8)}"
end
def self.request_id
request_id = []
request_id << Fog::Mock.random_hex(8)
3.times do
request_id << Fog::Mock.random_hex(4)
end
request_id << Fog::Mock.random_hex(12)
request_id.join('-')
end
class << self
alias :reserved_instances_id :request_id
alias :reserved_instances_offering_id :request_id
alias :sqs_message_id :request_id
alias :sqs_sender_id :request_id
end
def self.reservation_id
"r-#{Fog::Mock.random_hex(8)}"
end
def self.snapshot_id
"snap-#{Fog::Mock.random_hex(8)}"
end
def self.volume_id
"vol-#{Fog::Mock.random_hex(8)}"
end
def self.security_group_id
"sg-#{Fog::Mock.random_hex(8)}"
end
def self.network_acl_id
"acl-#{Fog::Mock.random_hex(8)}"
end
def self.network_acl_association_id
"aclassoc-#{Fog::Mock.random_hex(8)}"
end
def self.network_interface_id
"eni-#{Fog::Mock.random_hex(8)}"
end
def self.internet_gateway_id
"igw-#{Fog::Mock.random_hex(8)}"
end
def self.dhcp_options_id
"dopt-#{Fog::Mock.random_hex(8)}"
end
def self.vpc_id
"vpc-#{Fog::Mock.random_hex(8)}"
end
def self.subnet_id
"subnet-#{Fog::Mock.random_hex(8)}"
end
def self.zone_id
"zone-#{Fog::Mock.random_hex(8)}"
end
def self.change_id
Fog::Mock.random_letters_and_numbers(14)
end
def self.nameservers
[
'ns-2048.awsdns-64.com',
'ns-2049.awsdns-65.net',
'ns-2050.awsdns-66.org',
'ns-2051.awsdns-67.co.uk'
]
end
def self.key_id(length=21)
#Probably close enough
Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',length)
end
def self.rds_address(db_name,region)
"#{db_name}.#{Fog::Mock.random_letters(rand(12) + 4)}.#{region}.rds.amazonaws.com"
end
end
def self.parse_security_group_options(group_name, options)
options ||= Hash.new
if group_name.is_a?(Hash)
options = group_name
elsif group_name
if options.key?('GroupName')
raise Fog::Compute::AWS::Error, 'Arguments specified both group_name and GroupName in options'
end
options = options.clone
options['GroupName'] = group_name
end
name_specified = options.key?('GroupName') && !options['GroupName'].nil?
group_id_specified = options.key?('GroupId') && !options['GroupId'].nil?
unless name_specified || group_id_specified
raise Fog::Compute::AWS::Error, 'Neither GroupName nor GroupId specified'
end
if name_specified && group_id_specified
options.delete('GroupName')
end
options
end
module Errors
def self.match_error(error)
matcher = lambda {|s| s.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)}
[error.message, error.response.body].each(&Proc.new {|s|
match = matcher.call(s)
return {:code => match[1].split('.').last, :message => match[2]} if match
})
{} # we did not match the message or response body
end
end
end
end

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
require 'fog/dns'
module Fog

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
require 'fog/storage'
module Fog

View File

@ -1,4 +1,4 @@
require 'fog/aws'
require 'fog/aws/core'
module Fog
module AWS

View File

@ -1,11 +1 @@
require 'fog/core'
module Fog
module BareMetalCloud
extend Fog::Provider
service(:compute, 'bare_metal_cloud/compute', 'Compute')
end
end
require 'fog/bare_metal_cloud/compute'

View File

@ -1,4 +1,4 @@
require 'fog/bare_metal_cloud'
require 'fog/bare_metal_cloud/core'
require 'fog/compute'
module Fog

View File

@ -0,0 +1,11 @@
require 'fog/core'
module Fog
module BareMetalCloud
extend Fog::Provider
service(:compute, 'bare_metal_cloud/compute', 'Compute')
end
end

View File

@ -1,13 +1,3 @@
require 'fog/core'
module Fog
module Bluebox
extend Fog::Provider
service(:blb, 'bluebox/blb', 'BLB')
service(:compute, 'bluebox/compute', 'Compute')
service(:dns, 'bluebox/dns', 'DNS')
end
end
require 'fog/bluebox/blb'
require 'fog/bluebox/compute'
require 'fog/bluebox/dns'

View File

@ -1,4 +1,4 @@
require 'fog/bluebox'
require 'fog/bluebox/core'
module Fog
module Bluebox

View File

@ -1,4 +1,4 @@
require 'fog/bluebox'
require 'fog/bluebox/core'
require 'fog/compute'
module Fog

13
lib/fog/bluebox/core.rb Normal file
View File

@ -0,0 +1,13 @@
require 'fog/core'
module Fog
module Bluebox
extend Fog::Provider
service(:blb, 'bluebox/blb', 'BLB')
service(:compute, 'bluebox/compute', 'Compute')
service(:dns, 'bluebox/dns', 'DNS')
end
end

View File

@ -1,4 +1,4 @@
require 'fog/bluebox'
require 'fog/bluebox/core'
require 'fog/dns'
module Fog

View File

@ -1,10 +1 @@
require 'fog/core'
module Fog
module Brightbox
extend Fog::Provider
service(:compute, 'brightbox/compute', 'Compute')
end
end
require 'fog/brightbox/compute'

View File

@ -1,4 +1,4 @@
require 'fog/brightbox'
require 'fog/brightbox/core'
require 'fog/compute'
require 'fog/brightbox/compute/shared'
require 'fog/brightbox/compute/image_selector'

10
lib/fog/brightbox/core.rb Normal file
View File

@ -0,0 +1,10 @@
require 'fog/core'
module Fog
module Brightbox
extend Fog::Provider
service(:compute, 'brightbox/compute', 'Compute')
end
end

View File

@ -1,34 +1 @@
require 'fog/core'
module Fog
module Clodo
extend Fog::Provider
service(:compute, 'clodo/compute', 'Compute')
def self.authenticate(options)
clodo_auth_url = options[:clodo_auth_url] || "api.clodo.ru"
url = clodo_auth_url.match(/^https?:/) ? \
clodo_auth_url : 'https://' + clodo_auth_url
uri = URI.parse(url)
connection = Fog::Connection.new(url)
@clodo_api_key = options[:clodo_api_key]
@clodo_username = options[:clodo_username]
response = connection.request({
:expects => [200, 204],
:headers => {
'X-Auth-Key' => @clodo_api_key,
'X-Auth-User' => @clodo_username
},
:host => uri.host,
:method => 'GET',
:path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0'
})
response.headers.reject do |key, value|
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
end
end # authenticate
end # module Clodo
end # module Fog
require 'fog/clodo/compute'

View File

@ -1,4 +1,4 @@
require 'fog/clodo'
require 'fog/clodo/core'
module Fog
module Compute

34
lib/fog/clodo/core.rb Normal file
View File

@ -0,0 +1,34 @@
require 'fog/core'
module Fog
module Clodo
extend Fog::Provider
service(:compute, 'clodo/compute', 'Compute')
def self.authenticate(options)
clodo_auth_url = options[:clodo_auth_url] || "api.clodo.ru"
url = clodo_auth_url.match(/^https?:/) ? \
clodo_auth_url : 'https://' + clodo_auth_url
uri = URI.parse(url)
connection = Fog::Connection.new(url)
@clodo_api_key = options[:clodo_api_key]
@clodo_username = options[:clodo_username]
response = connection.request({
:expects => [200, 204],
:headers => {
'X-Auth-Key' => @clodo_api_key,
'X-Auth-User' => @clodo_username
},
:host => uri.host,
:method => 'GET',
:path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0'
})
response.headers.reject do |key, value|
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
end
end # authenticate
end # module Clodo
end # module Fog

View File

@ -1,9 +1 @@
require 'fog/core'
module Fog
module CloudSigma
extend Fog::Provider
service(:compute, 'cloudsigma/compute', 'Compute')
end
end
require 'fog/cloudsigma/compute'

View File

@ -1,4 +1,4 @@
require 'fog/cloudsigma'
require 'fog/cloudsigma/core'
require 'fog/cloudsigma/connection'
require 'fog/compute'

View File

@ -0,0 +1,9 @@
require 'fog/core'
module Fog
module CloudSigma
extend Fog::Provider
service(:compute, 'cloudsigma/compute', 'Compute')
end
end

View File

@ -1,40 +1 @@
require 'fog/core'
require 'uri'
module Fog
module Cloudstack
extend Fog::Provider
service(:compute, 'cloudstack/compute','Compute')
@@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)
query = params.map{|k,v| [k.to_s, v]}.sort.collect{|c| "#{c[0]}=#{escape(c[1].to_s)}"}.join('&').downcase
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
require 'fog/cloudstack/compute'

View File

@ -1,4 +1,4 @@
require 'fog/cloudstack'
require 'fog/cloudstack/core'
require 'fog/compute'
require 'digest/md5'

View File

@ -0,0 +1,40 @@
require 'fog/core'
require 'uri'
module Fog
module Cloudstack
extend Fog::Provider
service(:compute, 'cloudstack/compute','Compute')
@@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)
query = params.map{|k,v| [k.to_s, v]}.sort.collect{|c| "#{c[0]}=#{escape(c[1].to_s)}"}.join('&').downcase
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

View File

@ -1,9 +1 @@
require 'fog/core'
module Fog
module DigitalOcean
extend Fog::Provider
service(:compute, 'digitalocean/compute', 'Compute')
end
end
require 'fog/digitalocean/compute'

View File

@ -1,4 +1,4 @@
require 'fog/digitalocean'
require 'fog/digitalocean/core'
require 'fog/compute'
module Fog

View File

@ -0,0 +1,9 @@
require 'fog/core'
module Fog
module DigitalOcean
extend Fog::Provider
service(:compute, 'digitalocean/compute', 'Compute')
end
end

View File

@ -1,11 +1 @@
require 'fog/core'
module Fog
module DNSimple
extend Fog::Provider
service(:dns, 'dnsimple/dns', 'DNS')
end
end
require 'fog/dnsimple/dns'

11
lib/fog/dnsimple/core.rb Normal file
View File

@ -0,0 +1,11 @@
require 'fog/core'
module Fog
module DNSimple
extend Fog::Provider
service(:dns, 'dnsimple/dns', 'DNS')
end
end

View File

@ -1,4 +1,4 @@
require 'fog/dnsimple'
require 'fog/dnsimple/core'
require 'fog/dns'
module Fog

View File

@ -1,11 +1 @@
require 'fog/core'
module Fog
module DNSMadeEasy
extend Fog::Provider
service(:dns, 'dnsmadeeasy/dns', 'DNS')
end
end
require 'fog/dnsmadeeasy/dns'

View File

@ -0,0 +1,11 @@
require 'fog/core'
module Fog
module DNSMadeEasy
extend Fog::Provider
service(:dns, 'dnsmadeeasy/dns', 'DNS')
end
end

View File

@ -1,4 +1,4 @@
require 'fog/dnsmadeeasy'
require 'fog/dnsmadeeasy/core'
require 'fog/dns'
module Fog

View File

@ -1,11 +1 @@
require 'fog/core'
module Fog
module Dreamhost
extend Fog::Provider
service(:dns, 'dreamhost/dns', 'DNS')
end
end
require 'fog/dreamhost/dns'

11
lib/fog/dreamhost/core.rb Normal file
View File

@ -0,0 +1,11 @@
require 'fog/core'
module Fog
module Dreamhost
extend Fog::Provider
service(:dns, 'dreamhost/dns', 'DNS')
end
end

View File

@ -1,4 +1,4 @@
require 'fog/dreamhost'
require 'fog/dreamhost/core'
require 'fog/dns'
module Fog

View File

@ -1,26 +1 @@
require 'nokogiri'
require 'fog/core'
require 'fog/core/parser'
module Fog
module Dynect
extend Fog::Provider
service(:dns, 'dynect/dns', 'DNS')
class Mock
def self.job_id
Fog::Mock.random_numbers(8).to_i
end
def self.token
Fog::Mock.random_hex(48)
end
def self.version
[Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1)].join('.')
end
end
end
end
require 'fog/dynect/dns'

26
lib/fog/dynect/core.rb Normal file
View File

@ -0,0 +1,26 @@
require 'nokogiri'
require 'fog/core'
require 'fog/core/parser'
module Fog
module Dynect
extend Fog::Provider
service(:dns, 'dynect/dns', 'DNS')
class Mock
def self.job_id
Fog::Mock.random_numbers(8).to_i
end
def self.token
Fog::Mock.random_hex(48)
end
def self.version
[Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1)].join('.')
end
end
end
end

View File

@ -1,4 +1,4 @@
require 'fog/dynect'
require 'fog/dynect/core'
require 'fog/dns'
module Fog

View File

@ -1,31 +1 @@
require 'fog/core'
module Fog
module Ecloud
ECLOUD_OPTIONS = [:ecloud_authentication_method]
extend Fog::Provider
service(:compute, 'ecloud/compute', 'Compute')
def self.keep(hash, *keys)
{}.tap do |kept|
keys.each{|k| kept[k]= hash[k] if hash.key?(k)}
end
end
def self.slice(hash, *keys)
hash.dup.tap do |sliced|
keys.each{|k| sliced.delete(k)}
end
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
require 'fog/ecloud/compute'

View File

@ -1,4 +1,4 @@
require 'fog/ecloud'
require 'fog/ecloud/core'
require 'fog/ecloud/collection'
require 'fog/ecloud/model'
require 'builder'

31
lib/fog/ecloud/core.rb Normal file
View File

@ -0,0 +1,31 @@
require 'fog/core'
module Fog
module Ecloud
ECLOUD_OPTIONS = [:ecloud_authentication_method]
extend Fog::Provider
service(:compute, 'ecloud/compute', 'Compute')
def self.keep(hash, *keys)
{}.tap do |kept|
keys.each{|k| kept[k]= hash[k] if hash.key?(k)}
end
end
def self.slice(hash, *keys)
hash.dup.tap do |sliced|
keys.each{|k| sliced.delete(k)}
end
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

View File

@ -1,11 +1 @@
require 'fog/core'
module Fog
module Glesys
extend Fog::Provider
service(:compute, 'glesys/compute', 'Compute')
end
end
require 'fog/glesys/compute'

View File

@ -1,4 +1,4 @@
require 'fog/glesys'
require 'fog/glesys/core'
module Fog
module Compute

11
lib/fog/glesys/core.rb Normal file
View File

@ -0,0 +1,11 @@
require 'fog/core'
module Fog
module Glesys
extend Fog::Provider
service(:compute, 'glesys/compute', 'Compute')
end
end

View File

@ -1,11 +1 @@
require 'fog/core'
module Fog
module GoGrid
extend Fog::Provider
service(:compute, 'go_grid/compute', 'Compute')
end
end
require 'fog/go_grid/compute'

View File

@ -1,4 +1,4 @@
require 'fog/go_grid'
require 'fog/go_grid/core'
require 'fog/compute'
module Fog

11
lib/fog/go_grid/core.rb Normal file
View File

@ -0,0 +1,11 @@
require 'fog/core'
module Fog
module GoGrid
extend Fog::Provider
service(:compute, 'go_grid/compute', 'Compute')
end
end

View File

@ -1,24 +1,2 @@
require 'fog/core'
module Fog
module Google
extend Fog::Provider
service(:compute, 'google/compute', 'Compute')
service(:storage, 'google/storage', 'Storage')
class Mock
def self.etag
hex(32)
end
def self.hex(length)
max = ('f' * length).to_i(16)
rand(max).to_s(16)
end
end
end
end
require 'fog/google/compute'
require 'fog/google/storage'

View File

@ -1,4 +1,4 @@
require 'fog/google'
require 'fog/google/core'
require 'fog/compute'
module Fog

24
lib/fog/google/core.rb Normal file
View File

@ -0,0 +1,24 @@
require 'fog/core'
module Fog
module Google
extend Fog::Provider
service(:compute, 'google/compute', 'Compute')
service(:storage, 'google/storage', 'Storage')
class Mock
def self.etag
hex(32)
end
def self.hex(length)
max = ('f' * length).to_i(16)
rand(max).to_s(16)
end
end
end
end

View File

@ -1,4 +1,4 @@
require 'fog/google'
require 'fog/google/core'
require 'fog/storage'
module Fog

View File

@ -1,352 +1,9 @@
require 'fog/core'
require 'fog/hp/simple_http_instrumentor'
module Fog
module HP
# define a specific version for the HP Provider
unless const_defined?(:VERSION)
VERSION = '0.0.22'
end
extend Fog::Provider
module Errors
class ServiceError < Fog::Errors::Error
attr_reader :response_data
def self.slurp(error)
if error.response.body.empty?
data = nil
message = nil
else
begin
data = Fog::JSON.decode(error.response.body)
message = data['message']
if message.nil? and !data.values.first.nil?
message = data.values.first['message']
end
rescue Fog::JSON::DecodeError
message = error.response.body #### body is not in JSON format, so just return as is
end
end
new_error = super(error, message)
new_error.instance_variable_set(:@response_data, data)
new_error
end
end
class InternalServerError < ServiceError; end
class Conflict < ServiceError; end
class NotFound < ServiceError; end
class Forbidden < ServiceError; end
class ServiceUnavailable < ServiceError; end
class BadRequest < ServiceError
attr_reader :validation_errors
def self.slurp(error)
new_error = super(error)
unless new_error.response_data.nil? or new_error.response_data['badRequest'].nil?
new_error.instance_variable_set(:@validation_errors, new_error.response_data['badRequest']['validationErrors'])
end
new_error
end
end
end
service(:block_storage, 'hp/block_storage', 'BlockStorage')
service(:block_storage_v2, 'hp/block_storage_v2', 'BlockStorageV2')
service(:cdn, 'hp/cdn', 'CDN')
service(:compute, 'hp/compute', 'Compute')
service(:dns, 'hp/dns', 'DNS')
service(:lb, 'hp/lb', 'LB')
service(:network, 'hp/network', 'Network')
service(:storage, 'hp/storage', 'Storage')
# legacy swauth 1.0/1.1 style authentication
def self.authenticate_v1(options, connection_options = {})
hp_auth_uri = options[:hp_auth_uri] || "https://region-a.geo-1.objects.hpcloudsvc.com/auth/v1.0/"
endpoint = URI.parse(hp_auth_uri)
@scheme = endpoint.scheme || "http"
@host = endpoint.host || "region-a.geo-1.objects.hpcloudsvc.com"
@port = endpoint.port.to_s || "80"
if (endpoint.path)
@auth_path = endpoint.path.slice(1, endpoint.path.length) # remove the leading slash
else
@auth_path = "auth/v1.0"
end
service_url = "#{@scheme}://#{@host}:#{@port}"
# Set the User-Agent
@user_agent = options[:user_agent]
set_user_agent_header(connection_options, "fog/#{Fog::VERSION}", @user_agent)
connection = Fog::Connection.new(service_url, false, connection_options)
@hp_access_key = options[:hp_access_key]
@hp_secret_key = options[:hp_secret_key]
response = connection.request({
:expects => [200, 204],
:headers => {
'X-Auth-Key' => @hp_secret_key,
'X-Auth-User' => @hp_access_key
},
:method => 'GET',
:path => @auth_path
})
response.headers.reject do |key, value|
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
end
return {
:auth_token => response.headers['X-Auth-Token'],
:endpoint_url => nil,
:cdn_endpoint_url => response.headers['X-Storage-Url']
}
end
def self.service_catalog(options, connection_options = {})
creds = authenticate_v2(options, connection_options)
return {} if creds.nil?
return {} if creds[:service_catalog].nil?
return creds[:service_catalog]
end
# keystone based control services style authentication
def self.authenticate_v2(options, connection_options = {})
unless options[:credentials].nil?
expires = true
begin
expire = DateTime.parse(options[:credentials][:expires])
expires = false if expire > DateTime.now
rescue
end
if expires
options = options.clone
options.delete(:credentials)
else
service_catalog = options[:credentials][:service_catalog]
type = options[:hp_service_type]
zone = options[:hp_avl_zone]
begin
creds = options[:credentials].clone
creds[:endpoint_url] = get_endpoint_url(service_catalog, type, zone)
begin
creds[:cdn_endpoint_url] = get_endpoint_url(service_catalog, "CDN", zone)
rescue
end
return creds
rescue
end
options = options.clone
options.delete(:credentials)
end
end
hp_auth_uri = options[:hp_auth_uri] || "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"
# append /tokens if missing from auth uri
@hp_auth_uri = hp_auth_uri.include?('tokens')? hp_auth_uri : hp_auth_uri + "tokens"
endpoint = URI.parse(@hp_auth_uri)
@scheme = endpoint.scheme || "https"
@host = endpoint.host || "region-a.geo-1.identity.hpcloudsvc.com"
@port = endpoint.port.to_s || "35357"
if (endpoint.path)
@auth_path = endpoint.path.slice(1, endpoint.path.length) # remove the leading slash
else
@auth_path = "v2.0/tokens"
end
service_url = "#{@scheme}://#{@host}:#{@port}"
# Set the User-Agent. If the caller sets a user_agent, use it.
@user_agent = options[:user_agent]
set_user_agent_header(connection_options, "fog/#{Fog::VERSION}", @user_agent)
connection = Fog::Connection.new(service_url, false, connection_options)
### Implement HP Control Services Authentication services ###
# Get the style of auth credentials passed, defaults to access/secret key style
@hp_use_upass_auth_style = options[:hp_use_upass_auth_style] || false
@hp_access_key = options[:hp_access_key]
@hp_secret_key = options[:hp_secret_key]
@hp_tenant_id = options[:hp_tenant_id]
@hp_service_type = options[:hp_service_type]
@hp_avl_zone = options[:hp_avl_zone]
### Decide which auth style to use
unless (@hp_use_upass_auth_style)
# If Access Key style credentials are provided, use that
request_body = {
'auth' => {
'apiAccessKeyCredentials' => {
'accessKey' => "#{@hp_access_key}",
'secretKey' => "#{@hp_secret_key}"
}
}
}
else
# Otherwise use the Username/Password style
request_body = {
'auth' => {
'passwordCredentials' => {
'username' => "#{@hp_access_key}",
'password' => "#{@hp_secret_key}"
}
}
}
end
# add tenant_id if specified
request_body['auth']['tenantId'] = @hp_tenant_id if @hp_tenant_id
### Make the call to CS to get auth token and service catalog
response = connection.request(
{
:expects => 200,
:headers => {
'Content-Type' => 'application/json'
},
:method => 'POST',
:body => Fog::JSON.encode(request_body),
:path => @auth_path
}
)
body = Fog::JSON.decode(response.body)
### fish out auth_token and endpoint for the service
auth_token = body['access']['token']['id']
expires = body['access']['token']['expires']
service_catalog = get_service_catalog(body['access']['serviceCatalog'])
endpoint_url = get_endpoint_url(service_catalog, @hp_service_type, @hp_avl_zone)
begin
cdn_endpoint_url = get_endpoint_url(service_catalog, "CDN", @hp_avl_zone)
rescue
end
creds = {
:auth_token => auth_token,
:expires => expires,
:service_catalog => service_catalog,
:endpoint_url => endpoint_url,
:cdn_endpoint_url => cdn_endpoint_url
}
return creds
end
# CGI.escape, but without special treatment on spaces
def self.escape(str,extra_exclude_chars = '')
str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
end
end
# converts any attributes hash from aliased keys to original attribute keys
def self.convert_aliased_attributes_to_original(model, attributes)
original_attributes = {}
attributes.each do |k, v|
if orig_key = model.aliases.invert[k]
original_attributes[orig_key] = v
else
original_attributes[k] = v
end
end
original_attributes
end
private
def self.get_service_catalog(body)
raise "Unable to parse service catalog." unless body
service_catalog = {}
body.each do |s|
name = s["name"]
next if name.nil?
name = name.to_sym
next if s['endpoints'].nil?
service_catalog[name] = {}
s['endpoints'].each do |ep|
next if ep['region'].nil?
next if ep['publicURL'].nil?
next if ep['publicURL'].empty?
service_catalog[name][ep['region'].to_sym] = ep['publicURL']
end
end
return service_catalog
end
def self.get_endpoint_url(service_catalog, service_type, avl_zone)
return nil if service_type.nil?
service_type = service_type.to_sym
avl_zone = avl_zone.to_sym
unless service_catalog[service_type].nil?
unless service_catalog[service_type][avl_zone].nil?
return service_catalog[service_type][avl_zone]
end
end
raise "Unable to retrieve endpoint service url for availability zone '#{avl_zone}' from service catalog. "
end
def self.set_user_agent_header(conn_opts, base_str, client_str)
if client_str
user_agent = {'User-Agent' => base_str + " (#{client_str})"}
else
user_agent = {'User-Agent' => base_str}
end
if conn_opts[:headers]
conn_opts[:headers] = user_agent.merge!(conn_opts[:headers])
else
conn_opts[:headers] = user_agent
end
end
class Mock
def self.etag
Fog::Mock.random_hex(32)
end
def self.key_fingerprint
fingerprint = []
20.times do
fingerprint << Fog::Mock.random_hex(2)
end
fingerprint.join(':')
end
def self.key_material
private_key = OpenSSL::PKey::RSA.generate(1024)
public_key = private_key.public_key
return private_key.to_s, public_key.to_s
end
def self.user_id
"dev_" + Fog::Mock.random_numbers(14)
end
def self.instance_id
Fog::Mock.random_numbers(6)
end
def self.ip_address
ip = []
4.times do
ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
end
ip.join('.')
end
def self.uuid
# pattern of 8-4-4-4-12 hexadecimal digits
uuid = []
[8,4,4,4,12].each do |x|
uuid << Fog::Mock.random_hex(x)
end
uuid.join('-')
end
def self.mac_address
mac_add = []
6.times do
mac_add << Fog::Mock.random_hex(2)
end
mac_add.join(':')
end
end
end
end
require 'fog/hp/block_storage'
require 'fog/hp/block_storage_v2'
require 'fog/hp/cdn'
require 'fog/hp/compute'
require 'fog/hp/compute_v2'
require 'fog/hp/dns'
require 'fog/hp/lb'
require 'fog/hp/network'
require 'fog/hp/storage'

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
module Fog
module HP

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
module Fog
module HP

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
require 'fog/cdn'
module Fog

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
require 'fog/compute'
module Fog

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
require 'fog/compute'
module Fog

352
lib/fog/hp/core.rb Normal file
View File

@ -0,0 +1,352 @@
require 'fog/core'
require 'fog/hp/simple_http_instrumentor'
module Fog
module HP
# define a specific version for the HP Provider
unless const_defined?(:VERSION)
VERSION = '0.0.22'
end
extend Fog::Provider
module Errors
class ServiceError < Fog::Errors::Error
attr_reader :response_data
def self.slurp(error)
if error.response.body.empty?
data = nil
message = nil
else
begin
data = Fog::JSON.decode(error.response.body)
message = data['message']
if message.nil? and !data.values.first.nil?
message = data.values.first['message']
end
rescue Fog::JSON::DecodeError
message = error.response.body #### body is not in JSON format, so just return as is
end
end
new_error = super(error, message)
new_error.instance_variable_set(:@response_data, data)
new_error
end
end
class InternalServerError < ServiceError; end
class Conflict < ServiceError; end
class NotFound < ServiceError; end
class Forbidden < ServiceError; end
class ServiceUnavailable < ServiceError; end
class BadRequest < ServiceError
attr_reader :validation_errors
def self.slurp(error)
new_error = super(error)
unless new_error.response_data.nil? or new_error.response_data['badRequest'].nil?
new_error.instance_variable_set(:@validation_errors, new_error.response_data['badRequest']['validationErrors'])
end
new_error
end
end
end
service(:block_storage, 'hp/block_storage', 'BlockStorage')
service(:block_storage_v2, 'hp/block_storage_v2', 'BlockStorageV2')
service(:cdn, 'hp/cdn', 'CDN')
service(:compute, 'hp/compute', 'Compute')
service(:dns, 'hp/dns', 'DNS')
service(:lb, 'hp/lb', 'LB')
service(:network, 'hp/network', 'Network')
service(:storage, 'hp/storage', 'Storage')
# legacy swauth 1.0/1.1 style authentication
def self.authenticate_v1(options, connection_options = {})
hp_auth_uri = options[:hp_auth_uri] || "https://region-a.geo-1.objects.hpcloudsvc.com/auth/v1.0/"
endpoint = URI.parse(hp_auth_uri)
@scheme = endpoint.scheme || "http"
@host = endpoint.host || "region-a.geo-1.objects.hpcloudsvc.com"
@port = endpoint.port.to_s || "80"
if (endpoint.path)
@auth_path = endpoint.path.slice(1, endpoint.path.length) # remove the leading slash
else
@auth_path = "auth/v1.0"
end
service_url = "#{@scheme}://#{@host}:#{@port}"
# Set the User-Agent
@user_agent = options[:user_agent]
set_user_agent_header(connection_options, "fog/#{Fog::VERSION}", @user_agent)
connection = Fog::Connection.new(service_url, false, connection_options)
@hp_access_key = options[:hp_access_key]
@hp_secret_key = options[:hp_secret_key]
response = connection.request({
:expects => [200, 204],
:headers => {
'X-Auth-Key' => @hp_secret_key,
'X-Auth-User' => @hp_access_key
},
:method => 'GET',
:path => @auth_path
})
response.headers.reject do |key, value|
!['X-Server-Management-Url', 'X-Storage-Url', 'X-CDN-Management-Url', 'X-Auth-Token'].include?(key)
end
return {
:auth_token => response.headers['X-Auth-Token'],
:endpoint_url => nil,
:cdn_endpoint_url => response.headers['X-Storage-Url']
}
end
def self.service_catalog(options, connection_options = {})
creds = authenticate_v2(options, connection_options)
return {} if creds.nil?
return {} if creds[:service_catalog].nil?
return creds[:service_catalog]
end
# keystone based control services style authentication
def self.authenticate_v2(options, connection_options = {})
unless options[:credentials].nil?
expires = true
begin
expire = DateTime.parse(options[:credentials][:expires])
expires = false if expire > DateTime.now
rescue
end
if expires
options = options.clone
options.delete(:credentials)
else
service_catalog = options[:credentials][:service_catalog]
type = options[:hp_service_type]
zone = options[:hp_avl_zone]
begin
creds = options[:credentials].clone
creds[:endpoint_url] = get_endpoint_url(service_catalog, type, zone)
begin
creds[:cdn_endpoint_url] = get_endpoint_url(service_catalog, "CDN", zone)
rescue
end
return creds
rescue
end
options = options.clone
options.delete(:credentials)
end
end
hp_auth_uri = options[:hp_auth_uri] || "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens"
# append /tokens if missing from auth uri
@hp_auth_uri = hp_auth_uri.include?('tokens')? hp_auth_uri : hp_auth_uri + "tokens"
endpoint = URI.parse(@hp_auth_uri)
@scheme = endpoint.scheme || "https"
@host = endpoint.host || "region-a.geo-1.identity.hpcloudsvc.com"
@port = endpoint.port.to_s || "35357"
if (endpoint.path)
@auth_path = endpoint.path.slice(1, endpoint.path.length) # remove the leading slash
else
@auth_path = "v2.0/tokens"
end
service_url = "#{@scheme}://#{@host}:#{@port}"
# Set the User-Agent. If the caller sets a user_agent, use it.
@user_agent = options[:user_agent]
set_user_agent_header(connection_options, "fog/#{Fog::VERSION}", @user_agent)
connection = Fog::Connection.new(service_url, false, connection_options)
### Implement HP Control Services Authentication services ###
# Get the style of auth credentials passed, defaults to access/secret key style
@hp_use_upass_auth_style = options[:hp_use_upass_auth_style] || false
@hp_access_key = options[:hp_access_key]
@hp_secret_key = options[:hp_secret_key]
@hp_tenant_id = options[:hp_tenant_id]
@hp_service_type = options[:hp_service_type]
@hp_avl_zone = options[:hp_avl_zone]
### Decide which auth style to use
unless (@hp_use_upass_auth_style)
# If Access Key style credentials are provided, use that
request_body = {
'auth' => {
'apiAccessKeyCredentials' => {
'accessKey' => "#{@hp_access_key}",
'secretKey' => "#{@hp_secret_key}"
}
}
}
else
# Otherwise use the Username/Password style
request_body = {
'auth' => {
'passwordCredentials' => {
'username' => "#{@hp_access_key}",
'password' => "#{@hp_secret_key}"
}
}
}
end
# add tenant_id if specified
request_body['auth']['tenantId'] = @hp_tenant_id if @hp_tenant_id
### Make the call to CS to get auth token and service catalog
response = connection.request(
{
:expects => 200,
:headers => {
'Content-Type' => 'application/json'
},
:method => 'POST',
:body => Fog::JSON.encode(request_body),
:path => @auth_path
}
)
body = Fog::JSON.decode(response.body)
### fish out auth_token and endpoint for the service
auth_token = body['access']['token']['id']
expires = body['access']['token']['expires']
service_catalog = get_service_catalog(body['access']['serviceCatalog'])
endpoint_url = get_endpoint_url(service_catalog, @hp_service_type, @hp_avl_zone)
begin
cdn_endpoint_url = get_endpoint_url(service_catalog, "CDN", @hp_avl_zone)
rescue
end
creds = {
:auth_token => auth_token,
:expires => expires,
:service_catalog => service_catalog,
:endpoint_url => endpoint_url,
:cdn_endpoint_url => cdn_endpoint_url
}
return creds
end
# CGI.escape, but without special treatment on spaces
def self.escape(str,extra_exclude_chars = '')
str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
end
end
# converts any attributes hash from aliased keys to original attribute keys
def self.convert_aliased_attributes_to_original(model, attributes)
original_attributes = {}
attributes.each do |k, v|
if orig_key = model.aliases.invert[k]
original_attributes[orig_key] = v
else
original_attributes[k] = v
end
end
original_attributes
end
private
def self.get_service_catalog(body)
raise "Unable to parse service catalog." unless body
service_catalog = {}
body.each do |s|
name = s["name"]
next if name.nil?
name = name.to_sym
next if s['endpoints'].nil?
service_catalog[name] = {}
s['endpoints'].each do |ep|
next if ep['region'].nil?
next if ep['publicURL'].nil?
next if ep['publicURL'].empty?
service_catalog[name][ep['region'].to_sym] = ep['publicURL']
end
end
return service_catalog
end
def self.get_endpoint_url(service_catalog, service_type, avl_zone)
return nil if service_type.nil?
service_type = service_type.to_sym
avl_zone = avl_zone.to_sym
unless service_catalog[service_type].nil?
unless service_catalog[service_type][avl_zone].nil?
return service_catalog[service_type][avl_zone]
end
end
raise "Unable to retrieve endpoint service url for availability zone '#{avl_zone}' from service catalog. "
end
def self.set_user_agent_header(conn_opts, base_str, client_str)
if client_str
user_agent = {'User-Agent' => base_str + " (#{client_str})"}
else
user_agent = {'User-Agent' => base_str}
end
if conn_opts[:headers]
conn_opts[:headers] = user_agent.merge!(conn_opts[:headers])
else
conn_opts[:headers] = user_agent
end
end
class Mock
def self.etag
Fog::Mock.random_hex(32)
end
def self.key_fingerprint
fingerprint = []
20.times do
fingerprint << Fog::Mock.random_hex(2)
end
fingerprint.join(':')
end
def self.key_material
private_key = OpenSSL::PKey::RSA.generate(1024)
public_key = private_key.public_key
return private_key.to_s, public_key.to_s
end
def self.user_id
"dev_" + Fog::Mock.random_numbers(14)
end
def self.instance_id
Fog::Mock.random_numbers(6)
end
def self.ip_address
ip = []
4.times do
ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
end
ip.join('.')
end
def self.uuid
# pattern of 8-4-4-4-12 hexadecimal digits
uuid = []
[8,4,4,4,12].each do |x|
uuid << Fog::Mock.random_hex(x)
end
uuid.join('-')
end
def self.mac_address
mac_add = []
6.times do
mac_add << Fog::Mock.random_hex(2)
end
mac_add.join(':')
end
end
end
end

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
module Fog
module HP

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
module Fog
module HP

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
module Fog
module HP

View File

@ -1,4 +1,4 @@
require 'fog/hp'
require 'fog/hp/core'
require 'fog/storage'
module Fog

View File

@ -1,176 +1,2 @@
require 'fog/core'
module Fog
module IBM
extend Fog::Provider
service(:compute, 'ibm/compute', 'Compute')
service(:storage, 'ibm/storage', 'Storage')
# Provisioning is very slow. We'll pass this arg explicitly until there's a way
# to set the default timeout on a per-provider basis.
def self.timeout
1800
end
class Connection < Fog::Connection
def initialize(user, password)
@user = user
@password = password
@endpoint = URI.parse('https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331')
@base_path = @endpoint.path
super("#{@endpoint.scheme}://#{@endpoint.host}:#{@endpoint.port}")
end
def request(options)
options[:path] = @base_path + options[:path]
options[:headers] ||= {}
options[:headers]['Authorization'] = auth_header
options[:headers]['Accept'] = 'application/json'
options[:headers]['Accept-Encoding'] = 'gzip'
unless options[:body].nil?
options[:headers]['Content-Type'] = 'application/x-www-form-urlencoded'
options[:body] = form_encode(options[:body])
end
response = super(options)
unless response.body.empty?
response.body = Fog::JSON.decode(response.body)
end
response
end
def auth_header
@auth_header ||= 'Basic ' + Base64.encode64("#{@user}:#{@password}").gsub("\n",'')
end
def form_encode(params)
params.reject {|k, v| v.nil? }.map {|pair| pair.map {|x| URI.escape(x.to_s) }.join('=') }.join('&')
end
end
class Mock
class << self
def id
Fog::Mock.random_numbers(7).to_i.to_s
end
alias :instance_id :id
alias :request_id :id
def primary_ip
{ "type" => 0, "ip" => Fog::IBM::Mock.ip_address, "hostname" => Fog::IBM::Mock.hostname }
end
def ip_address
ip = []
4.times do
ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
end
ip.join('.')
end
def hostname
"vhost" + Fog::Mock.random_numbers(3).to_i.to_s + ".fake.compute.ihost.com"
end
# Miliseconds since epoch
def launch_time
(Time.now.tv_sec * 1000).to_i
end
# 1 year from now, in miliseconds since epoch
def expiry_time
((Time.now.tv_sec + 31556926) * 1000).to_i
end
def owner
"user" + Fog::Mock.random_numbers(3).to_i.to_s + "@company.com"
end
def key_material
OpenSSL::PKey::RSA.generate(1024)
end
def private_image(name, description)
{
"name" => name,
"createdTime" => Fog::IBM::Mock.launch_time,
"productCodes"=> [],
"id" => Fog::IBM::Mock.instance_id,
"description" => description,
"visibility" => "PRIVATE",
"state" => 0
}
end
def create_instance(name, image_id, instance_type, location, options)
{
"name" => name,
"location" => location,
"keyName" => options[:key_name],
"primaryIP" => Fog::IBM::Mock.primary_ip,
"productCodes" => [],
"requestId" => Fog::IBM::Mock.request_id,
"imageId" => image_id,
"launchTime" => Fog::IBM::Mock.launch_time,
"id" => Fog::IBM::Mock.instance_id,
"volumes" => [],
"isMiniEphemeral" => "false",
"instanceType" => instance_type,
"diskSize" => "60",
"requestName" => "",
"secondaryIP" => [],
"status" => 1,
"software" => [
{ "name"=>"SUSE Linux Enterprise Server",
"type"=>"OS",
"version"=>"11 SP1" }
],
"expirationTime"=> Fog::IBM::Mock.expiry_time,
"owner" => Fog::IBM::Mock.owner
}
end
def create_volume(name, format, location_id, size, offering_id)
{
"instanceId" => "0",
"state" => 1,
"size" => size,
"offeringId" => offering_id,
"ioPrice" => {
"rate" => 0.11,
"unitOfMeasure" => "CNT",
"countryCode" => "897",
"effectiveDate" => Fog::IBM::Mock.launch_time,
"currencyCode" => "USD",
"pricePerQuantity" => 1
},
"owner" => Fog::IBM::Mock.owner,
"createdTime" => Fog::IBM::Mock.launch_time,
"location" => location_id,
"productCodes"=> [],
"format" => format,
"name" => name,
"id" => Fog::IBM::Mock.id,
}
end
def create_address(location_id, offering_id, vlan_id)
# TODO: Figure out vlan handling
{
"id" => Fog::IBM::Mock.id,
"location" => location_id,
"offeringId"=> offering_id,
"ip" => "",
"state" => 0
}
end
end
end
end
end
require 'fog/ibm/compute'
require 'fog/ibm/storage'

View File

@ -1,4 +1,4 @@
require 'fog/ibm'
require 'fog/ibm/core'
require 'fog/compute'
module Fog

176
lib/fog/ibm/core.rb Normal file
View File

@ -0,0 +1,176 @@
require 'fog/core'
module Fog
module IBM
extend Fog::Provider
service(:compute, 'ibm/compute', 'Compute')
service(:storage, 'ibm/storage', 'Storage')
# Provisioning is very slow. We'll pass this arg explicitly until there's a way
# to set the default timeout on a per-provider basis.
def self.timeout
1800
end
class Connection < Fog::Connection
def initialize(user, password)
@user = user
@password = password
@endpoint = URI.parse('https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331')
@base_path = @endpoint.path
super("#{@endpoint.scheme}://#{@endpoint.host}:#{@endpoint.port}")
end
def request(options)
options[:path] = @base_path + options[:path]
options[:headers] ||= {}
options[:headers]['Authorization'] = auth_header
options[:headers]['Accept'] = 'application/json'
options[:headers]['Accept-Encoding'] = 'gzip'
unless options[:body].nil?
options[:headers]['Content-Type'] = 'application/x-www-form-urlencoded'
options[:body] = form_encode(options[:body])
end
response = super(options)
unless response.body.empty?
response.body = Fog::JSON.decode(response.body)
end
response
end
def auth_header
@auth_header ||= 'Basic ' + Base64.encode64("#{@user}:#{@password}").gsub("\n",'')
end
def form_encode(params)
params.reject {|k, v| v.nil? }.map {|pair| pair.map {|x| URI.escape(x.to_s) }.join('=') }.join('&')
end
end
class Mock
class << self
def id
Fog::Mock.random_numbers(7).to_i.to_s
end
alias :instance_id :id
alias :request_id :id
def primary_ip
{ "type" => 0, "ip" => Fog::IBM::Mock.ip_address, "hostname" => Fog::IBM::Mock.hostname }
end
def ip_address
ip = []
4.times do
ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
end
ip.join('.')
end
def hostname
"vhost" + Fog::Mock.random_numbers(3).to_i.to_s + ".fake.compute.ihost.com"
end
# Miliseconds since epoch
def launch_time
(Time.now.tv_sec * 1000).to_i
end
# 1 year from now, in miliseconds since epoch
def expiry_time
((Time.now.tv_sec + 31556926) * 1000).to_i
end
def owner
"user" + Fog::Mock.random_numbers(3).to_i.to_s + "@company.com"
end
def key_material
OpenSSL::PKey::RSA.generate(1024)
end
def private_image(name, description)
{
"name" => name,
"createdTime" => Fog::IBM::Mock.launch_time,
"productCodes"=> [],
"id" => Fog::IBM::Mock.instance_id,
"description" => description,
"visibility" => "PRIVATE",
"state" => 0
}
end
def create_instance(name, image_id, instance_type, location, options)
{
"name" => name,
"location" => location,
"keyName" => options[:key_name],
"primaryIP" => Fog::IBM::Mock.primary_ip,
"productCodes" => [],
"requestId" => Fog::IBM::Mock.request_id,
"imageId" => image_id,
"launchTime" => Fog::IBM::Mock.launch_time,
"id" => Fog::IBM::Mock.instance_id,
"volumes" => [],
"isMiniEphemeral" => "false",
"instanceType" => instance_type,
"diskSize" => "60",
"requestName" => "",
"secondaryIP" => [],
"status" => 1,
"software" => [
{ "name"=>"SUSE Linux Enterprise Server",
"type"=>"OS",
"version"=>"11 SP1" }
],
"expirationTime"=> Fog::IBM::Mock.expiry_time,
"owner" => Fog::IBM::Mock.owner
}
end
def create_volume(name, format, location_id, size, offering_id)
{
"instanceId" => "0",
"state" => 1,
"size" => size,
"offeringId" => offering_id,
"ioPrice" => {
"rate" => 0.11,
"unitOfMeasure" => "CNT",
"countryCode" => "897",
"effectiveDate" => Fog::IBM::Mock.launch_time,
"currencyCode" => "USD",
"pricePerQuantity" => 1
},
"owner" => Fog::IBM::Mock.owner,
"createdTime" => Fog::IBM::Mock.launch_time,
"location" => location_id,
"productCodes"=> [],
"format" => format,
"name" => name,
"id" => Fog::IBM::Mock.id,
}
end
def create_address(location_id, offering_id, vlan_id)
# TODO: Figure out vlan handling
{
"id" => Fog::IBM::Mock.id,
"location" => location_id,
"offeringId"=> offering_id,
"ip" => "",
"state" => 0
}
end
end
end
end
end

View File

@ -1,4 +1,4 @@
require 'fog/ibm'
require 'fog/ibm/core'
require 'fog/storage'
module Fog

View File

@ -1,292 +1 @@
require 'fog/core'
require 'fog/internet_archive/signaturev4'
module Fog
module InternetArchive
COMPLIANT_BUCKET_NAMES = /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\-(?![\.])){1,61}[a-z0-9]$/
DOMAIN_NAME = 'archive.org'
API_DOMAIN_NAME = 's3.us.' + DOMAIN_NAME
extend Fog::Provider
service(:storage, 'internet_archive/storage', 'Storage')
def self.indexed_param(key, values)
params = {}
unless key.include?('%d')
key << '.%d'
end
[*values].each_with_index do |value, index|
if value.respond_to?('keys')
k = format(key, index + 1)
value.each do | vkey, vvalue |
params["#{k}.#{vkey}"] = vvalue
end
else
params[format(key, index + 1)] = value
end
end
params
end
def self.serialize_keys(key, value, options = {})
case value
when Hash
value.each do | k, v |
options.merge!(serialize_keys("#{key}.#{k}", v))
end
return options
when Array
value.each_with_index do | it, idx |
options.merge!(serialize_keys("#{key}.member.#{(idx + 1)}", it))
end
return options
else
return {key => value}
end
end
def self.indexed_request_param(name, values)
idx = -1
Array(values).inject({}) do |params, value|
params["#{name}.#{idx += 1}"] = value
params
end
end
def self.indexed_filters(filters)
params = {}
filters.keys.each_with_index do |key, key_index|
key_index += 1
params[format('Filter.%d.Name', key_index)] = key
[*filters[key]].each_with_index do |value, value_index|
value_index += 1
params[format('Filter.%d.Value.%d', key_index, value_index)] = value
end
end
params
end
def self.escape(string)
string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
}
end
def self.signed_params(params, options = {})
params.merge!({
'AWSAccessKeyId' => options[:ia_access_key_id],
'SignatureMethod' => 'HmacSHA256',
'SignatureVersion' => '2',
'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
'Version' => options[:version]
})
params.merge!({
'SecurityToken' => options[:ia_session_token]
}) if options[:ia_session_token]
body = ''
for key in params.keys.sort
unless (value = params[key]).nil?
body << "#{key}=#{escape(value.to_s)}&"
end
end
string_to_sign = "POST\n#{options[:host]}:#{options[:port]}\n#{options[:path]}\n" << body.chop
signed_string = options[:hmac].sign(string_to_sign)
body << "Signature=#{escape(Base64.encode64(signed_string).chomp!)}"
body
end
class Mock
def self.arn(vendor, account_id, path, region = nil)
"arn:aws:#{vendor}:#{region}:#{account_id}:#{path}"
end
def self.availability_zone(region)
"#{region}#{Fog::Mock.random_selection('abcd', 1)}"
end
def self.box_usage
sprintf("%0.10f", rand / 100).to_f
end
def self.console_output
# "[ 0.000000] Linux version 2.6.18-xenU-ec2-v1.2 (root@domU-12-31-39-07-51-82) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)) #2 SMP Wed Aug 19 09:04:38 EDT 2009"
Base64.decode64("WyAwLjAwMDAwMF0gTGludXggdmVyc2lvbiAyLjYuMTgteGVuVS1lYzItdjEu\nMiAocm9vdEBkb21VLTEyLTMxLTM5LTA3LTUxLTgyKSAoZ2NjIHZlcnNpb24g\nNC4xLjIgMjAwNzA2MjYgKFJlZCBIYXQgNC4xLjItMTMpKSAjMiBTTVAgV2Vk\nIEF1ZyAxOSAwOTowNDozOCBFRFQgMjAwOQ==\n")
end
def self.dns_name_for(ip_address)
"ec2-#{ip_address.gsub('.','-')}.compute-1.amazonaws.com"
end
def self.private_dns_name_for(ip_address)
"ip-#{ip_address.gsub('.','-')}.ec2.internal"
end
def self.image
path = []
(rand(3) + 2).times do
path << Fog::Mock.random_letters(rand(9) + 8)
end
{
"imageOwnerId" => Fog::Mock.random_letters(rand(5) + 4),
"blockDeviceMapping" => [],
"productCodes" => [],
"kernelId" => kernel_id,
"ramdiskId" => ramdisk_id,
"imageState" => "available",
"imageId" => image_id,
"architecture" => "i386",
"isPublic" => true,
"imageLocation" => path.join('/'),
"imageType" => "machine",
"rootDeviceType" => ["ebs","instance-store"][rand(2)],
"rootDeviceName" => "/dev/sda1"
}
end
def self.image_id
"ami-#{Fog::Mock.random_hex(8)}"
end
def self.key_fingerprint
fingerprint = []
20.times do
fingerprint << Fog::Mock.random_hex(2)
end
fingerprint.join(':')
end
def self.instance_id
"i-#{Fog::Mock.random_hex(8)}"
end
def self.ip_address
ip = []
4.times do
ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
end
ip.join('.')
end
def self.private_ip_address
ip_address.gsub(/^\d{1,3}\./,"10.")
end
def self.kernel_id
"aki-#{Fog::Mock.random_hex(8)}"
end
def self.key_material
OpenSSL::PKey::RSA.generate(1024).to_s
end
def self.owner_id
Fog::Mock.random_numbers(12)
end
def self.ramdisk_id
"ari-#{Fog::Mock.random_hex(8)}"
end
def self.request_id
request_id = []
request_id << Fog::Mock.random_hex(8)
3.times do
request_id << Fog::Mock.random_hex(4)
end
request_id << Fog::Mock.random_hex(12)
request_id.join('-')
end
class << self
alias :reserved_instances_id :request_id
alias :reserved_instances_offering_id :request_id
alias :sqs_message_id :request_id
alias :sqs_sender_id :request_id
end
def self.reservation_id
"r-#{Fog::Mock.random_hex(8)}"
end
def self.snapshot_id
"snap-#{Fog::Mock.random_hex(8)}"
end
def self.volume_id
"vol-#{Fog::Mock.random_hex(8)}"
end
def self.security_group_id
"sg-#{Fog::Mock.random_hex(8)}"
end
def self.network_interface_id
"eni-#{Fog::Mock.random_hex(8)}"
end
def self.internet_gateway_id
"igw-#{Fog::Mock.random_hex(8)}"
end
def self.dhcp_options_id
"dopt-#{Fog::Mock.random_hex(8)}"
end
def self.vpc_id
"vpc-#{Fog::Mock.random_hex(8)}"
end
def self.subnet_id
"subnet-#{Fog::Mock.random_hex(8)}"
end
def self.zone_id
"zone-#{Fog::Mock.random_hex(8)}"
end
def self.change_id
"change-#{Fog::Mock.random_hex(8)}"
end
def self.nameservers
[
'ns-2048.awsdns-64.com',
'ns-2049.awsdns-65.net',
'ns-2050.awsdns-66.org',
'ns-2051.awsdns-67.co.uk'
]
end
def self.key_id(length=21)
#Probably close enough
Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',length)
end
def self.rds_address(db_name,region)
"#{db_name}.#{Fog::Mock.random_letters(rand(12) + 4)}.#{region}.rds.amazonaws.com"
end
end
def self.parse_security_group_options(group_name, options)
options ||= Hash.new
if group_name.is_a?(Hash)
options = group_name
elsif group_name
if options.key?('GroupName')
raise Fog::Compute::InternetArchive::Error, 'Arguments specified both group_name and GroupName in options'
end
options = options.clone
options['GroupName'] = group_name
end
name_specified = options.key?('GroupName') && !options['GroupName'].nil?
group_id_specified = options.key?('GroupId') && !options['GroupId'].nil?
unless name_specified || group_id_specified
raise Fog::Compute::InternetArchive::Error, 'Neither GroupName nor GroupId specified'
end
if name_specified && group_id_specified
options.delete('GroupName')
end
options
end
end
end
require 'fog/internet_archive/storage'

View File

@ -0,0 +1,292 @@
require 'fog/core'
require 'fog/internet_archive/signaturev4'
module Fog
module InternetArchive
COMPLIANT_BUCKET_NAMES = /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\-(?![\.])){1,61}[a-z0-9]$/
DOMAIN_NAME = 'archive.org'
API_DOMAIN_NAME = 's3.us.' + DOMAIN_NAME
extend Fog::Provider
service(:storage, 'internet_archive/storage', 'Storage')
def self.indexed_param(key, values)
params = {}
unless key.include?('%d')
key << '.%d'
end
[*values].each_with_index do |value, index|
if value.respond_to?('keys')
k = format(key, index + 1)
value.each do | vkey, vvalue |
params["#{k}.#{vkey}"] = vvalue
end
else
params[format(key, index + 1)] = value
end
end
params
end
def self.serialize_keys(key, value, options = {})
case value
when Hash
value.each do | k, v |
options.merge!(serialize_keys("#{key}.#{k}", v))
end
return options
when Array
value.each_with_index do | it, idx |
options.merge!(serialize_keys("#{key}.member.#{(idx + 1)}", it))
end
return options
else
return {key => value}
end
end
def self.indexed_request_param(name, values)
idx = -1
Array(values).inject({}) do |params, value|
params["#{name}.#{idx += 1}"] = value
params
end
end
def self.indexed_filters(filters)
params = {}
filters.keys.each_with_index do |key, key_index|
key_index += 1
params[format('Filter.%d.Name', key_index)] = key
[*filters[key]].each_with_index do |value, value_index|
value_index += 1
params[format('Filter.%d.Value.%d', key_index, value_index)] = value
end
end
params
end
def self.escape(string)
string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
}
end
def self.signed_params(params, options = {})
params.merge!({
'AWSAccessKeyId' => options[:ia_access_key_id],
'SignatureMethod' => 'HmacSHA256',
'SignatureVersion' => '2',
'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
'Version' => options[:version]
})
params.merge!({
'SecurityToken' => options[:ia_session_token]
}) if options[:ia_session_token]
body = ''
for key in params.keys.sort
unless (value = params[key]).nil?
body << "#{key}=#{escape(value.to_s)}&"
end
end
string_to_sign = "POST\n#{options[:host]}:#{options[:port]}\n#{options[:path]}\n" << body.chop
signed_string = options[:hmac].sign(string_to_sign)
body << "Signature=#{escape(Base64.encode64(signed_string).chomp!)}"
body
end
class Mock
def self.arn(vendor, account_id, path, region = nil)
"arn:aws:#{vendor}:#{region}:#{account_id}:#{path}"
end
def self.availability_zone(region)
"#{region}#{Fog::Mock.random_selection('abcd', 1)}"
end
def self.box_usage
sprintf("%0.10f", rand / 100).to_f
end
def self.console_output
# "[ 0.000000] Linux version 2.6.18-xenU-ec2-v1.2 (root@domU-12-31-39-07-51-82) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)) #2 SMP Wed Aug 19 09:04:38 EDT 2009"
Base64.decode64("WyAwLjAwMDAwMF0gTGludXggdmVyc2lvbiAyLjYuMTgteGVuVS1lYzItdjEu\nMiAocm9vdEBkb21VLTEyLTMxLTM5LTA3LTUxLTgyKSAoZ2NjIHZlcnNpb24g\nNC4xLjIgMjAwNzA2MjYgKFJlZCBIYXQgNC4xLjItMTMpKSAjMiBTTVAgV2Vk\nIEF1ZyAxOSAwOTowNDozOCBFRFQgMjAwOQ==\n")
end
def self.dns_name_for(ip_address)
"ec2-#{ip_address.gsub('.','-')}.compute-1.amazonaws.com"
end
def self.private_dns_name_for(ip_address)
"ip-#{ip_address.gsub('.','-')}.ec2.internal"
end
def self.image
path = []
(rand(3) + 2).times do
path << Fog::Mock.random_letters(rand(9) + 8)
end
{
"imageOwnerId" => Fog::Mock.random_letters(rand(5) + 4),
"blockDeviceMapping" => [],
"productCodes" => [],
"kernelId" => kernel_id,
"ramdiskId" => ramdisk_id,
"imageState" => "available",
"imageId" => image_id,
"architecture" => "i386",
"isPublic" => true,
"imageLocation" => path.join('/'),
"imageType" => "machine",
"rootDeviceType" => ["ebs","instance-store"][rand(2)],
"rootDeviceName" => "/dev/sda1"
}
end
def self.image_id
"ami-#{Fog::Mock.random_hex(8)}"
end
def self.key_fingerprint
fingerprint = []
20.times do
fingerprint << Fog::Mock.random_hex(2)
end
fingerprint.join(':')
end
def self.instance_id
"i-#{Fog::Mock.random_hex(8)}"
end
def self.ip_address
ip = []
4.times do
ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
end
ip.join('.')
end
def self.private_ip_address
ip_address.gsub(/^\d{1,3}\./,"10.")
end
def self.kernel_id
"aki-#{Fog::Mock.random_hex(8)}"
end
def self.key_material
OpenSSL::PKey::RSA.generate(1024).to_s
end
def self.owner_id
Fog::Mock.random_numbers(12)
end
def self.ramdisk_id
"ari-#{Fog::Mock.random_hex(8)}"
end
def self.request_id
request_id = []
request_id << Fog::Mock.random_hex(8)
3.times do
request_id << Fog::Mock.random_hex(4)
end
request_id << Fog::Mock.random_hex(12)
request_id.join('-')
end
class << self
alias :reserved_instances_id :request_id
alias :reserved_instances_offering_id :request_id
alias :sqs_message_id :request_id
alias :sqs_sender_id :request_id
end
def self.reservation_id
"r-#{Fog::Mock.random_hex(8)}"
end
def self.snapshot_id
"snap-#{Fog::Mock.random_hex(8)}"
end
def self.volume_id
"vol-#{Fog::Mock.random_hex(8)}"
end
def self.security_group_id
"sg-#{Fog::Mock.random_hex(8)}"
end
def self.network_interface_id
"eni-#{Fog::Mock.random_hex(8)}"
end
def self.internet_gateway_id
"igw-#{Fog::Mock.random_hex(8)}"
end
def self.dhcp_options_id
"dopt-#{Fog::Mock.random_hex(8)}"
end
def self.vpc_id
"vpc-#{Fog::Mock.random_hex(8)}"
end
def self.subnet_id
"subnet-#{Fog::Mock.random_hex(8)}"
end
def self.zone_id
"zone-#{Fog::Mock.random_hex(8)}"
end
def self.change_id
"change-#{Fog::Mock.random_hex(8)}"
end
def self.nameservers
[
'ns-2048.awsdns-64.com',
'ns-2049.awsdns-65.net',
'ns-2050.awsdns-66.org',
'ns-2051.awsdns-67.co.uk'
]
end
def self.key_id(length=21)
#Probably close enough
Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',length)
end
def self.rds_address(db_name,region)
"#{db_name}.#{Fog::Mock.random_letters(rand(12) + 4)}.#{region}.rds.amazonaws.com"
end
end
def self.parse_security_group_options(group_name, options)
options ||= Hash.new
if group_name.is_a?(Hash)
options = group_name
elsif group_name
if options.key?('GroupName')
raise Fog::Compute::InternetArchive::Error, 'Arguments specified both group_name and GroupName in options'
end
options = options.clone
options['GroupName'] = group_name
end
name_specified = options.key?('GroupName') && !options['GroupName'].nil?
group_id_specified = options.key?('GroupId') && !options['GroupId'].nil?
unless name_specified || group_id_specified
raise Fog::Compute::InternetArchive::Error, 'Neither GroupName nor GroupId specified'
end
if name_specified && group_id_specified
options.delete('GroupName')
end
options
end
end
end

View File

@ -1,4 +1,4 @@
require 'fog/internet_archive'
require 'fog/internet_archive/core'
require 'fog/storage'
module Fog

View File

@ -1,10 +1,2 @@
require 'fog/core'
module Fog
module Joyent
extend Fog::Provider
service(:compute, 'joyent/compute', 'Compute')
end
end
require 'fog/joyent/compute'
require 'fog/joyent/errors'

View File

@ -1,4 +1,4 @@
require 'fog/joyent'
require 'fog/joyent/core'
require 'fog/joyent/errors'
require 'fog/compute'
require 'net/ssh'

10
lib/fog/joyent/core.rb Normal file
View File

@ -0,0 +1,10 @@
require 'fog/core'
module Fog
module Joyent
extend Fog::Provider
service(:compute, 'joyent/compute', 'Compute')
end
end

View File

@ -1,3 +1,4 @@
require 'fog/joyent/core'
module Fog
module Compute
class Joyent < Fog::Service

View File

@ -1,11 +1 @@
require 'fog/core'
module Fog
module Libvirt
extend Fog::Provider
service(:compute, 'libvirt/compute', 'Compute')
end
end
require 'fog/libvirt/compute'

View File

@ -1,4 +1,4 @@
require 'fog/libvirt'
require 'fog/libvirt/core'
require 'fog/compute'
require 'fog/libvirt/models/compute/util/util'
require 'fog/libvirt/models/compute/util/uri'

11
lib/fog/libvirt/core.rb Normal file
View File

@ -0,0 +1,11 @@
require 'fog/core'
module Fog
module Libvirt
extend Fog::Provider
service(:compute, 'libvirt/compute', 'Compute')
end
end

Some files were not shown because too many files have changed in this diff Show More