2011-08-11 12:53:52 -04:00
|
|
|
require 'fog/compute/models/server'
|
2010-10-11 02:16:40 -04:00
|
|
|
|
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class GoGrid
|
2010-10-11 02:16:40 -04:00
|
|
|
|
|
|
|
class BlockInstantiationError < StandardError; end
|
|
|
|
|
2011-08-11 12:53:52 -04:00
|
|
|
class Server < Fog::Compute::Server
|
2011-02-23 13:45:50 -05:00
|
|
|
extend Fog::Deprecation
|
2011-02-22 19:36:15 -05:00
|
|
|
deprecate(:ip, :public_ip_address)
|
2010-10-11 02:16:40 -04:00
|
|
|
|
2010-10-13 16:20:18 -04:00
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :name
|
2011-01-26 18:19:48 -05:00
|
|
|
attribute :image_id # id or name
|
2011-06-24 17:27:25 -04:00
|
|
|
attribute :public_ip_address, :aliases => 'ip', :squash => 'ip'
|
2010-10-13 16:20:18 -04:00
|
|
|
attribute :memory # server.ram
|
|
|
|
attribute :state
|
|
|
|
attribute :description # Optional
|
|
|
|
attribute :sandbox # Optional. Default: False
|
|
|
|
|
|
|
|
def initialize(attributes={})
|
2011-04-14 19:31:58 -04:00
|
|
|
image_id ||= 'ubuntu_10_04_LTS_64_base' # Ubuntu 10.04 LTS 64bit
|
2010-10-13 16:20:18 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
2012-12-22 18:26:52 -05:00
|
|
|
service.grid_server_delete(id)
|
2010-10-13 16:20:18 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
|
|
|
requires :image_id
|
2012-12-22 18:26:52 -05:00
|
|
|
service.grid_image_get(:image => image_id)
|
2010-10-13 16:20:18 -04:00
|
|
|
end
|
|
|
|
|
2011-02-22 19:36:15 -05:00
|
|
|
def private_ip_address
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2010-10-13 16:20:18 -04:00
|
|
|
def ready?
|
2011-01-26 05:58:12 -05:00
|
|
|
@state && @state["name"] == 'On'
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
requires :name
|
|
|
|
begin
|
|
|
|
if data = collection.get(name)
|
|
|
|
new_attributes = data.attributes
|
|
|
|
merge_attributes(new_attributes)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
rescue Excon::Errors::BadRequest
|
|
|
|
false
|
|
|
|
end
|
2010-10-13 16:20:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2012-12-22 21:45:05 -05:00
|
|
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
2011-06-24 17:27:25 -04:00
|
|
|
requires :name, :image_id, :memory, :public_ip_address
|
2011-01-26 05:23:00 -05:00
|
|
|
options = {
|
|
|
|
'isSandbox' => sandbox,
|
|
|
|
'image' => image_id
|
|
|
|
}
|
|
|
|
options = options.reject {|key, value| value.nil?}
|
2012-12-22 18:26:52 -05:00
|
|
|
data = service.grid_server_add(image, public_ip_address, name, memory, options)
|
2010-10-13 16:20:18 -04:00
|
|
|
merge_attributes(data.body)
|
|
|
|
true
|
2010-10-11 02:16:40 -04:00
|
|
|
end
|
|
|
|
|
2011-01-26 05:23:00 -05:00
|
|
|
def setup(credentials = {})
|
2011-06-24 17:27:25 -04:00
|
|
|
requires :identity, :public_ip_address, :public_key, :username
|
|
|
|
Fog::SSH.new(public_ip_address, username, credentials).run([
|
2011-01-26 05:23:00 -05:00
|
|
|
%{mkdir .ssh},
|
|
|
|
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
|
|
|
|
%{passwd -l root},
|
2012-04-25 10:31:28 -04:00
|
|
|
%{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
|
|
|
|
%{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
|
2011-01-26 05:23:00 -05:00
|
|
|
])
|
|
|
|
rescue Errno::ECONNREFUSED
|
|
|
|
sleep(1)
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def adminPass=(new_admin_pass)
|
|
|
|
@password = new_admin_pass
|
|
|
|
end
|
|
|
|
|
2010-10-11 02:16:40 -04:00
|
|
|
end
|
|
|
|
|
2010-10-13 16:20:18 -04:00
|
|
|
end
|
|
|
|
|
2010-10-11 22:53:24 -04:00
|
|
|
end
|
|
|
|
end
|