first pass at rackspace files support

This commit is contained in:
Wesley Beary 2009-10-11 13:37:25 -07:00
parent 374b36c8dd
commit 77e9013a44
6 changed files with 137 additions and 2 deletions

View File

@ -5,7 +5,7 @@ module Fog
module Rackspace
def self.reload
# TODO: load 'fog/rackspace/files.rb'
load 'fog/rackspace/files.rb'
load 'fog/rackspace/servers.rb'
end

View File

@ -0,0 +1,62 @@
module Fog
module Rackspace
class Files
def self.reload
load "fog/rackspace/requests/files/get_containers.rb"
end
def initialize(options={})
credentials = Fog::Rackspace.authenticate(options)
@auth_token = credentials['X-Auth-Token']
cdn_uri = URI.parse(credentials['X-CDN-Management-Url'])
@cdn_host = cdn_uri.host
@cdn_path = cdn_uri.path
@cdn_port = cdn_uri.port
@cdn_scheme = cdn_uri.scheme
storage_uri = URI.parse(credentials['X-Storage-Url'])
@storage_host = storage_uri.host
@storage_path = storage_uri.path
@storage_port = storage_uri.port
@storage_scheme = storage_uri.scheme
@connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}")
end
def cdn_request(params)
response = @connection.request({
:body => params[:body],
:expects => params[:expects],
:headers => {
'X-Auth-Token' => @auth_token
},
:host => @cdn_host,
:method => params[:method],
:path => "#{@cdn_path}/#{params[:path]}"
})
unless response.status == 204
response.body = JSON.parse(response.body)
end
response
end
def storage_request(params)
response = @connection.request({
:body => params[:body],
:expects => params[:expects],
:headers => {
'X-Auth-Token' => @auth_token
},
:host => @storage_host,
:method => params[:method],
:path => "#{@storage_path}/#{params[:path]}"
})
unless response.status == 204
response.body = JSON.parse(response.body)
end
response
end
end
end
end
Fog::Rackspace::Files.reload

View File

@ -0,0 +1,53 @@
unless Fog.mocking?
module Fog
module Rackspace
class Files
# List existing storage containers
#
# ==== Parameters
# * options<~Hash>:
# * 'limit'<~Integer> - Upper limit to number of results returned
# * 'marker'<~String> - Only return objects with name greater than this value
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * 'publicIp'<~String> - The acquired address
# * 'requestId'<~String> - Id of the request
def get_containers(options = {})
options = { 'format' => 'json' }.merge!(options)
query = []
for key, value in options
query << "#{key}=#{CGI.escape(value)}"
end
response = storage_request(
:expects => [200, 204],
:method => 'GET',
:path => '',
:query => query.join('&')
)
if response.status == 204
response.body = []
end
response
end
end
end
end
else
module Fog
module Rackspace
class Servers
def get_flavors
end
end
end
end
end

View File

@ -30,7 +30,9 @@ module Fog
:method => params[:method],
:path => "#{@path}/#{params[:path]}"
})
response.body = JSON.parse(response.body)
unless response.status == 204
response.body = JSON.parse(response.body)
end
response
end

View File

@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Rackspace::Files.get_containers' do
describe 'success' do
it "should return proper attributes" do
p files.get_containers
end
end
end

View File

@ -28,6 +28,13 @@ def eu_s3
)
end
def files
Fog::Rackspace::Files.new(
:rackspace_api_key => credentials[:rackspace_api_key],
:rackspace_username => credentials[:rackspace_username]
)
end
def sdb
Fog::AWS::SimpleDB.new(
:aws_access_key_id => credentials[:aws_access_key_id],