1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[go_grid] consistency between providers/services

This commit is contained in:
geemus 2010-09-07 16:58:14 -07:00
parent 75ea140b79
commit 8d7b30e187
21 changed files with 442 additions and 404 deletions

View file

@ -1,96 +1,18 @@
module Fog
class GoGrid < Fog::Service
module GoGrid
requires :go_grid_api_key
requires :go_grid_shared_secret
extend Fog::Provider
model_path 'fog/go_grid/models'
service_path 'fog/go_grid'
service 'servers'
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_add
request :grid_server_delete
request :grid_server_get
request :grid_server_list
request :grid_server_power
class Mock
include Collections
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {}
end
def self.new(attributes = {})
location = caller.first
warning = "[yellow][WARN] Fog::GoGrid#new is deprecated, use Fog::GoGrid::Servers#new instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
Fog::Bluebox::Blocks.new(attributes)
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 = {
:expects => 200,
:method => 'GET'
}.merge!(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

View file

@ -9,15 +9,15 @@ module GoGrid
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :go_grid
Fog::GoGrid.new
when :servers
Fog::GoGrid::Servers.new
end
end
@@connections[service]
end
def services
[:go_grid]
[:servers]
end
else

View file

@ -1,34 +0,0 @@
module Fog
class 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(
: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

View file

@ -1,37 +0,0 @@
module Fog
class 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(
:path => 'grid/image/list',
:query => options
)
end
end
class Mock
def grid_image_list(options={})
Fog::Mock.not_implemented
end
end
end
end

View file

@ -1,36 +0,0 @@
module Fog
class 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(
:path => 'grid/ip/list',
:query => options
)
end
end
class Mock
def grid_ip_list(options={})
Fog::Mock.not_implemented
end
end
end
end

View file

@ -1,34 +0,0 @@
module Fog
class 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(
:path => 'grid/loadbalancer/list',
:query => options
)
end
end
class Mock
def grid_loadbalancer_list(options={})
Fog::Mock.not_implemented
end
end
end
end

View file

@ -1,42 +0,0 @@
module Fog
class GoGrid
class Real
# Create a new server
#
# ==== Parameters
# * 'image'<~String> - image to use, in grid_image_list
# * 'ip'<~String> - initial public ip for this server
# * 'name'<~String> - name of the server, 20 or fewer characters
# * 'server_ram'<~String> - flavor to use, in common_lookup_list('server.ram')
# * 'options'<~Hash>:
# * 'description'<~String> - description of this server
# * 'isSandbox'<~String> - treat this server as image sandbox? in ['true', 'false']
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def grid_server_add(image, ip, name, server_ram, options={})
request(
:path => 'grid/server/add',
:query => {
'image' => image,
'ip' => ip,
'name' => name,
'server.ram' => server_ram
}.merge!(options)
)
end
end
class Mock
def grid_server_add(image, ip, name, server_ram, options={})
Fog::Mock.not_implemented
end
end
end
end

View file

@ -1,31 +0,0 @@
module Fog
class GoGrid
class Real
# Delete a server
#
# ==== Parameters
# * 'server'<~String> - id or name of server to delete
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def grid_server_delete(server)
request(
:path => 'grid/server/delete',
:query => {'server' => server}
)
end
end
class Mock
def grid_server_delete(server)
Fog::Mock.not_implemented
end
end
end
end

View file

@ -1,31 +0,0 @@
module Fog
class GoGrid
class Real
# Get one or more servers by name
#
# ==== Parameters
# * 'server'<~String> - id or name of server(s) to lookup
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def grid_server_get(servers)
request(
:path => 'grid/server/get',
:query => {'server' => [*servers]}
)
end
end
class Mock
def grid_server_get(servers)
Fog::Mock.not_implemented
end
end
end
end

View file

@ -1,36 +0,0 @@
module Fog
class 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(
:path => 'grid/server/list',
:query => options
)
end
end
class Mock
def grid_server_list(options={})
Fog::Mock.not_implemented
end
end
end
end

View file

@ -1,32 +0,0 @@
module Fog
class GoGrid
class Real
# Start, Stop or Restart a server
#
# ==== Parameters
# * 'server'<~String> - id or name of server to power
# * 'power'<~String> - power operation, in ['restart', 'start', 'stop']
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def grid_server_delete(server, power)
request(
:path => 'grid/server/power',
:query => {'server' => server}
)
end
end
class Mock
def grid_server_delete(server)
Fog::Mock.not_implemented
end
end
end
end

View file

@ -0,0 +1,36 @@
module Fog
module GoGrid
class Servers
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(
: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
end

View file

@ -0,0 +1,39 @@
module Fog
module GoGrid
class Servers
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(
:path => 'grid/image/list',
:query => options
)
end
end
class Mock
def grid_image_list(options={})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,38 @@
module Fog
module GoGrid
class Servers
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(
:path => 'grid/ip/list',
:query => options
)
end
end
class Mock
def grid_ip_list(options={})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,36 @@
module Fog
module GoGrid
class Servers
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(
:path => 'grid/loadbalancer/list',
:query => options
)
end
end
class Mock
def grid_loadbalancer_list(options={})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,44 @@
module Fog
module GoGrid
class Servers
class Real
# Create a new server
#
# ==== Parameters
# * 'image'<~String> - image to use, in grid_image_list
# * 'ip'<~String> - initial public ip for this server
# * 'name'<~String> - name of the server, 20 or fewer characters
# * 'server_ram'<~String> - flavor to use, in common_lookup_list('server.ram')
# * 'options'<~Hash>:
# * 'description'<~String> - description of this server
# * 'isSandbox'<~String> - treat this server as image sandbox? in ['true', 'false']
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def grid_server_add(image, ip, name, server_ram, options={})
request(
:path => 'grid/server/add',
:query => {
'image' => image,
'ip' => ip,
'name' => name,
'server.ram' => server_ram
}.merge!(options)
)
end
end
class Mock
def grid_server_add(image, ip, name, server_ram, options={})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,33 @@
module Fog
module GoGrid
class Servers
class Real
# Delete a server
#
# ==== Parameters
# * 'server'<~String> - id or name of server to delete
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def grid_server_delete(server)
request(
:path => 'grid/server/delete',
:query => {'server' => server}
)
end
end
class Mock
def grid_server_delete(server)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,33 @@
module Fog
module GoGrid
class Servers
class Real
# Get one or more servers by name
#
# ==== Parameters
# * 'server'<~String> - id or name of server(s) to lookup
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def grid_server_get(servers)
request(
:path => 'grid/server/get',
:query => {'server' => [*servers]}
)
end
end
class Mock
def grid_server_get(servers)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,38 @@
module Fog
module GoGrid
class Servers
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(
:path => 'grid/server/list',
:query => options
)
end
end
class Mock
def grid_server_list(options={})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,34 @@
module Fog
module GoGrid
class Servers
class Real
# Start, Stop or Restart a server
#
# ==== Parameters
# * 'server'<~String> - id or name of server to power
# * 'power'<~String> - power operation, in ['restart', 'start', 'stop']
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Array>:
# TODO: docs
def grid_server_delete(server, power)
request(
:path => 'grid/server/power',
:query => {'server' => server}
)
end
end
class Mock
def grid_server_delete(server)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,98 @@
module Fog
module GoGrid
class Servers < 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_add
request :grid_server_delete
request :grid_server_get
request :grid_server_list
request :grid_server_power
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 = {
:expects => 200,
:method => 'GET'
}.merge!(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
end