mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[GoGrid] auth and listings
This commit is contained in:
parent
81a09847cb
commit
f377cfd7b5
9 changed files with 308 additions and 1 deletions
|
@ -29,6 +29,7 @@ require 'fog/ssh'
|
|||
|
||||
require 'fog/aws'
|
||||
require 'fog/bluebox'
|
||||
require 'fog/go_grid'
|
||||
require 'fog/linode'
|
||||
require 'fog/local'
|
||||
require 'fog/new_servers'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'fog/credentials'
|
||||
|
||||
require 'fog/aws/bin'
|
||||
require 'fog/go_grid/bin'
|
||||
require 'fog/linode/bin'
|
||||
require 'fog/local/bin'
|
||||
require 'fog/new_servers/bin'
|
||||
|
@ -15,7 +16,7 @@ module Fog
|
|||
|
||||
def services
|
||||
services = []
|
||||
[::AWS, ::Linode, ::Local, ::NewServers, ::Rackspace, ::Slicehost, ::Terremark, ::Vcloud, ::Bluebox].each do |service|
|
||||
[::AWS, ::GoGrid, ::Linode, ::Local, ::NewServers, ::Rackspace, ::Slicehost, ::Terremark, ::Vcloud, ::Bluebox].each do |service|
|
||||
if service.initialized?
|
||||
services << service
|
||||
end
|
||||
|
|
88
lib/fog/go_grid.rb
Normal file
88
lib/fog/go_grid.rb
Normal file
|
@ -0,0 +1,88 @@
|
|||
module Fog
|
||||
module GoGrid
|
||||
extend Fog::Service
|
||||
|
||||
requires :go_grid_api_key
|
||||
requires :go_grid_shared_secret
|
||||
|
||||
model_path 'fog/go_grid/models'
|
||||
|
||||
request_path 'fog/go_grid/requests'
|
||||
request 'common_lookup_list'
|
||||
request 'grid_image_list'
|
||||
request 'grid_ip_list'
|
||||
request 'grid_loadbalancer_list'
|
||||
request 'grid_server_list'
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {}
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@go_grid_api_key = options[:go_grid_api_key]
|
||||
@go_grid_shared_secret = options[:go_grid_shared_secret]
|
||||
@data = self.class.data[@go_grid_api_key]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
include Collections
|
||||
|
||||
def initialize(options={})
|
||||
@go_grid_api_key = options[:go_grid_api_key]
|
||||
@go_grid_shared_secret = options[:go_grid_shared_secret]
|
||||
@host = options[:host] || "api.gogrid.com"
|
||||
@path = options[:path] || "/api"
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
def request(params)
|
||||
params[:query] ||= {}
|
||||
params[:query].merge!({
|
||||
'api_key' => @go_grid_api_key,
|
||||
'format' => 'json',
|
||||
'sig' => Digest::MD5.hexdigest("#{@go_grid_api_key}#{@go_grid_shared_secret}#{Time.now.to_i}"),
|
||||
'v' => '1.4'
|
||||
})
|
||||
|
||||
begin
|
||||
response = @connection.request(
|
||||
params.merge!(:path => "#{@path}/#{params[:path]}")
|
||||
)
|
||||
rescue Excon::Errors::Error => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::Go_Grid::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
unless response.body.empty?
|
||||
response.body = JSON.parse(response.body)
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/go_grid/bin.rb
Normal file
30
lib/fog/go_grid/bin.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module GoGrid
|
||||
class << self
|
||||
if Fog.credentials[:go_grid_api_key] && Fog.credentials[:go_grid_shared_secret]
|
||||
|
||||
def initialized?
|
||||
true
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
credentials = Fog.credentials.reject do |k,v|
|
||||
![:go_grid_api_key, :go_grid_shared_secret].include?(k)
|
||||
end
|
||||
hash[key] = case key
|
||||
when :go_grid
|
||||
Fog::GoGrid.new(credentials)
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
def initialized?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
36
lib/fog/go_grid/requests/common_lookup_list.rb
Normal file
36
lib/fog/go_grid/requests/common_lookup_list.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module GoGrid
|
||||
class Real
|
||||
|
||||
# List options and lookups
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'lookup'<~String> - the lookup to be listed
|
||||
# * options<~Hash>:
|
||||
# * 'sort'<~String> - column to sort result by in ['description', 'id', 'name']
|
||||
# * 'asc'<~String> - order to sort in ['true','false']
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# TODO: docs
|
||||
def common_lookup_list(lookup, options={})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'common/lookup/list',
|
||||
:query => {'lookup' => lookup}.merge!(options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def common_lookup_list(lookup, options={})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
39
lib/fog/go_grid/requests/grid_image_list.rb
Normal file
39
lib/fog/go_grid/requests/grid_image_list.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
module Fog
|
||||
module GoGrid
|
||||
class Real
|
||||
|
||||
# List images
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
# * 'datacenter'<~String> - datacenter to limit results to
|
||||
# * 'isPublic'<~String> - If true only returns public images, in ['false', 'true']
|
||||
# * 'num_items'<~Integer> - Number of items to return
|
||||
# * 'page'<~Integer> - Page index for paginated results
|
||||
# * 'state'<~String> - state to limit results to, in ['Saving', 'Available']
|
||||
# * 'type'<~String> - image type to limit results to
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# TODO: docs
|
||||
def grid_image_list(options={})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'grid/image/list',
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def grid_image_list(options={})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/go_grid/requests/grid_ip_list.rb
Normal file
38
lib/fog/go_grid/requests/grid_ip_list.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module GoGrid
|
||||
class Real
|
||||
|
||||
# List ips
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
# * 'datacenter'<~String> - datacenter to limit results to
|
||||
# * 'ip.state'<~String> - state to limit results to in ip.state
|
||||
# * 'ip.type'<~String> - type to limit results to in ip.type
|
||||
# * 'num_items'<~Integer> - Number of items to return
|
||||
# * 'page'<~Integer> - Page index for paginated results
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# TODO: docs
|
||||
def grid_ip_list(options={})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'grid/ip/list',
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def grid_ip_list(options={})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
36
lib/fog/go_grid/requests/grid_loadbalancer_list.rb
Normal file
36
lib/fog/go_grid/requests/grid_loadbalancer_list.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module GoGrid
|
||||
class Real
|
||||
|
||||
# List load balancers
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
# * 'datacenter'<~String> - datacenter to limit results to
|
||||
# * 'num_items'<~Integer> - Number of items to return
|
||||
# * 'page'<~Integer> - Page index for paginated results
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# TODO: docs
|
||||
def grid_loadbalancer_list(options={})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'grid/loadbalancer/list',
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def grid_loadbalancer_list(options={})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/go_grid/requests/grid_server_list.rb
Normal file
38
lib/fog/go_grid/requests/grid_server_list.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module GoGrid
|
||||
class Real
|
||||
|
||||
# List servers
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
# * 'datacenter'<~String> - datacenter to limit results to
|
||||
# * 'isSandbox'<~String> - If true only returns Image Sandbox servers, in ['false', 'true']
|
||||
# * 'num_items'<~Integer> - Number of items to return
|
||||
# * 'page'<~Integer> - Page index for paginated results
|
||||
# * 'server.type'<~String> - server type to limit results to
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# TODO: docs
|
||||
def grid_server_list(options={})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'grid/server/list',
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def grid_server_list(options={})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue