mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
first pass at rackspace support
This commit is contained in:
parent
8a182e5ce5
commit
374b36c8dd
13 changed files with 232 additions and 4 deletions
|
@ -17,6 +17,7 @@ module Fog
|
|||
|
||||
def self.reload
|
||||
load "fog/aws.rb"
|
||||
load "fog/rackspace.rb"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -172,6 +172,7 @@ module Fog
|
|||
response = @connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:error_parser => Fog::Errors::Parser.new,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:host => @host,
|
||||
:method => 'POST',
|
||||
|
|
|
@ -105,6 +105,7 @@ module Fog
|
|||
response = @connection.request({
|
||||
:block => params[:block],
|
||||
:body => params[:body],
|
||||
:error_parser => Fog::Errors::Parser.new,
|
||||
:expects => params[:expects],
|
||||
:headers => params[:headers],
|
||||
:host => params[:host],
|
||||
|
|
|
@ -36,7 +36,7 @@ unless Fog.mocking?
|
|||
|
||||
def request(params)
|
||||
params[:path] ||= ''
|
||||
unless params[:path][0] == '/'
|
||||
unless params[:path][0..0] == '/'
|
||||
params[:path] = '/' + params[:path].to_s
|
||||
end
|
||||
if params[:query] && !params[:query].empty?
|
||||
|
@ -68,7 +68,7 @@ unless Fog.mocking?
|
|||
response = Fog::Response.new
|
||||
response.request = params
|
||||
response.status = connection.readline[9..11].to_i
|
||||
if params[:expects] && params[:expects] != response.status
|
||||
if params[:expects] && ![*params[:expects]].include?(response.status)
|
||||
error = true
|
||||
end
|
||||
while true
|
||||
|
@ -81,9 +81,9 @@ unless Fog.mocking?
|
|||
end
|
||||
|
||||
unless params[:method] == 'HEAD'
|
||||
if error || params[:parser]
|
||||
if (error && params[:error_parser]) || params[:parser]
|
||||
if error
|
||||
parser = Fog::Errors::Parser.new
|
||||
parser = params[:error_parser]
|
||||
elsif params[:parser]
|
||||
parser = params[:parser]
|
||||
end
|
||||
|
|
31
lib/fog/rackspace.rb
Normal file
31
lib/fog/rackspace.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'rubygems'
|
||||
require 'json'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
|
||||
def self.reload
|
||||
# TODO: load 'fog/rackspace/files.rb'
|
||||
load 'fog/rackspace/servers.rb'
|
||||
end
|
||||
|
||||
def self.authenticate(options)
|
||||
connection = Fog::Connection.new("https://auth.api.rackspacecloud.com")
|
||||
response = connection.request({
|
||||
:expects => 204,
|
||||
:headers => {
|
||||
'X-Auth-Key' => options[:rackspace_api_key],
|
||||
'X-Auth-User' => options[:rackspace_username]
|
||||
},
|
||||
:host => 'auth.api.rackspacecloud.com',
|
||||
:method => 'GET',
|
||||
: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
|
||||
|
||||
end
|
||||
end
|
||||
Fog::Rackspace.reload
|
38
lib/fog/rackspace/requests/servers/get_flavors.rb
Normal file
38
lib/fog/rackspace/requests/servers/get_flavors.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class Servers
|
||||
|
||||
# List all images (IDs and names only)
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'publicIp'<~String> - The acquired address
|
||||
# * 'requestId'<~String> - Id of the request
|
||||
def get_flavors
|
||||
request(
|
||||
:method => 'GET',
|
||||
:path => 'flavors'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class Servers
|
||||
|
||||
def get_flavors
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
38
lib/fog/rackspace/requests/servers/get_images.rb
Normal file
38
lib/fog/rackspace/requests/servers/get_images.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class Servers
|
||||
|
||||
# List all images (IDs and names only)
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'publicIp'<~String> - The acquired address
|
||||
# * 'requestId'<~String> - Id of the request
|
||||
def get_images
|
||||
request(
|
||||
:method => 'GET',
|
||||
:path => 'images'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class Servers
|
||||
|
||||
def get_images
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
38
lib/fog/rackspace/requests/servers/get_servers.rb
Normal file
38
lib/fog/rackspace/requests/servers/get_servers.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
unless Fog.mocking?
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class Servers
|
||||
|
||||
# List all servers (IDs and names only)
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'publicIp'<~String> - The acquired address
|
||||
# * 'requestId'<~String> - Id of the request
|
||||
def get_servers
|
||||
request(
|
||||
:method => 'GET',
|
||||
:path => 'servers'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class Servers
|
||||
|
||||
def get_servers
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
40
lib/fog/rackspace/servers.rb
Normal file
40
lib/fog/rackspace/servers.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class Servers
|
||||
|
||||
def self.reload
|
||||
load "fog/rackspace/requests/servers/get_flavors.rb"
|
||||
load "fog/rackspace/requests/servers/get_images.rb"
|
||||
load "fog/rackspace/requests/servers/get_servers.rb"
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
credentials = Fog::Rackspace.authenticate(options)
|
||||
@auth_token = credentials['X-Auth-Token']
|
||||
uri = URI.parse(credentials['X-Server-Management-Url'])
|
||||
@host = uri.host
|
||||
@path = uri.path
|
||||
@port = uri.port
|
||||
@scheme = uri.scheme
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||
end
|
||||
|
||||
def request(params)
|
||||
response = @connection.request({
|
||||
:body => params[:body],
|
||||
:expects => params[:expects],
|
||||
:headers => {
|
||||
'X-Auth-Token' => @auth_token
|
||||
},
|
||||
:host => @host,
|
||||
:method => params[:method],
|
||||
:path => "#{@path}/#{params[:path]}"
|
||||
})
|
||||
response.body = JSON.parse(response.body)
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Fog::Rackspace::Servers.reload
|
11
spec/rackspace/requests/servers/get_flavors.rb
Normal file
11
spec/rackspace/requests/servers/get_flavors.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'Rackspace::Servers.get_flavors' do
|
||||
describe 'success' do
|
||||
|
||||
it "should return proper attributes" do
|
||||
p servers.get_flavors
|
||||
end
|
||||
|
||||
end
|
||||
end
|
11
spec/rackspace/requests/servers/get_images.rb
Normal file
11
spec/rackspace/requests/servers/get_images.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'Rackspace::Servers.get_images' do
|
||||
describe 'success' do
|
||||
|
||||
it "should return proper attributes" do
|
||||
p servers.get_images
|
||||
end
|
||||
|
||||
end
|
||||
end
|
11
spec/rackspace/requests/servers/get_servers.rb
Normal file
11
spec/rackspace/requests/servers/get_servers.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require File.dirname(__FILE__) + '/../../../spec_helper'
|
||||
|
||||
describe 'Rackspace::Servers.get_servers' do
|
||||
describe 'success' do
|
||||
|
||||
it "should return proper attributes" do
|
||||
p servers.get_servers
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -35,6 +35,13 @@ def sdb
|
|||
)
|
||||
end
|
||||
|
||||
def servers
|
||||
Fog::Rackspace::Servers.new(
|
||||
:rackspace_api_key => credentials[:rackspace_api_key],
|
||||
:rackspace_username => credentials[:rackspace_username]
|
||||
)
|
||||
end
|
||||
|
||||
def s3
|
||||
Fog::AWS::S3.new(
|
||||
:aws_access_key_id => credentials[:aws_access_key_id],
|
||||
|
|
Loading…
Reference in a new issue