mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Initial GoGrid work
This commit is contained in:
parent
4b7157abc1
commit
a5b2390188
9 changed files with 212 additions and 2 deletions
|
@ -67,7 +67,7 @@ module Fog
|
|||
'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'
|
||||
'v' => '1.5'
|
||||
})
|
||||
|
||||
begin
|
||||
|
|
47
lib/fog/go_grid/models/compute/image.rb
Normal file
47
lib/fog/go_grid/models/compute/image.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module GoGrid
|
||||
class Compute
|
||||
|
||||
class Image < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :friendly_name, :aliases => 'friendlyName'
|
||||
attribute :created_at, :aliases => 'createdTime'
|
||||
attribute :updated_at, :aliases => 'updatedTime'
|
||||
attribute :server_id, :aliases => 'id'
|
||||
|
||||
def server=(new_server)
|
||||
requires :id
|
||||
|
||||
@server_id = new_server.id
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
|
||||
connection.grid_server_delete(@id)
|
||||
true
|
||||
end
|
||||
|
||||
def ready?
|
||||
status == 'Available'
|
||||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
requires :server_id
|
||||
|
||||
data = connection.grid_server_add(@server_id, 'name' => name)
|
||||
merge_attributes(data.body['image'])
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
29
lib/fog/go_grid/models/compute/images.rb
Normal file
29
lib/fog/go_grid/models/compute/images.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/go_grid/models/compute/image'
|
||||
|
||||
module Fog
|
||||
module GoGrid
|
||||
class Compute
|
||||
|
||||
class Images < Fog::Collection
|
||||
|
||||
model Fog::GoGrid::Compute::Image
|
||||
|
||||
attribute :server
|
||||
|
||||
def all
|
||||
data = connection.grid_image_list.body['list']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(image_id)
|
||||
response = connection.grid_image_get.body['list'][image_id]
|
||||
rescue Fog::GoGrid::Compute::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
53
lib/fog/go_grid/models/compute/server.rb
Normal file
53
lib/fog/go_grid/models/compute/server.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module GoGrid
|
||||
class Compute
|
||||
|
||||
class BlockInstantiationError < StandardError; end
|
||||
|
||||
class Server < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :image_id # id or name
|
||||
attribute :ip
|
||||
attribute :memory # server.ram
|
||||
attribute :state
|
||||
attribute :description # Optional
|
||||
attribute :sandbox # Optional. Default: False
|
||||
|
||||
def initialize(attributes={})
|
||||
super
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.grid_server_destroy(@id)
|
||||
true
|
||||
end
|
||||
|
||||
def image
|
||||
requires :image_id
|
||||
connection.grid_image_get(@image_id)
|
||||
end
|
||||
|
||||
def ready?
|
||||
@state == 'On'
|
||||
end
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
requires :name, :image_id, :ip, :memory
|
||||
options['isSandbox'] = sandbox if sandbox
|
||||
options['server.ram'] = memory
|
||||
options['image'] = image_id
|
||||
data = connection.grid_server_add(name, image, ip, options)
|
||||
merge_attributes(data.body)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
35
lib/fog/go_grid/models/compute/servers.rb
Normal file
35
lib/fog/go_grid/models/compute/servers.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/go_grid/models/compute/server'
|
||||
|
||||
module Fog
|
||||
module GoGrid
|
||||
class Compute
|
||||
|
||||
class Servers < Fog::Collection
|
||||
|
||||
model Fog::GoGrid::Compute::Server
|
||||
|
||||
def all
|
||||
data = connection.grid_server_list.body['list']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def bootstrap(new_attributes = {})
|
||||
server = create(new_attributes)
|
||||
server.wait_for { ready? }
|
||||
server
|
||||
end
|
||||
|
||||
def get(server_id)
|
||||
if server_id && server = connection.grid_server_get(server_id).body['list']
|
||||
new(server)
|
||||
end
|
||||
rescue Fog::GoGrid::Compute::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
41
lib/fog/go_grid/requests/compute/grid_image_get.rb
Normal file
41
lib/fog/go_grid/requests/compute/grid_image_get.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
module Fog
|
||||
module GoGrid
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
# List images
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
# * 'id'<~String> - ID of the image
|
||||
# * 'name'<~String> - Name of the image
|
||||
# * 'image'<~String> - ID(s) or Name(s) of the images to retrive. Can be speicifed multiple times
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Array>:
|
||||
# TODO: docs
|
||||
def grid_image_get(options={})
|
||||
request(
|
||||
:path => 'grid/image/get',
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def grid_image_get(options={})
|
||||
#response = Excon::Response.new
|
||||
|
||||
#images = @data[:list].values
|
||||
#for image in images
|
||||
# case image['state']
|
||||
# when 'Available'
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,7 +30,12 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def grid_image_list(options={})
|
||||
Fog::Mock.not_implemented
|
||||
#response = Excon::Response.new
|
||||
|
||||
#images = @data[:list].values
|
||||
#for image in images
|
||||
# case image['state']
|
||||
# when 'Available'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
0
tests/go_grid/helper.rb
Normal file
0
tests/go_grid/helper.rb
Normal file
0
tests/go_grid/requests/compute/image_tests.rb
Normal file
0
tests/go_grid/requests/compute/image_tests.rb
Normal file
Loading…
Reference in a new issue