2010-03-19 18:29:42 -07:00
|
|
|
require 'fog/model'
|
|
|
|
|
2009-10-14 22:03:16 -07:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
2010-03-19 18:29:42 -07:00
|
|
|
module Servers
|
2009-10-14 22:03:16 -07:00
|
|
|
|
|
|
|
class Server < Fog::Model
|
|
|
|
|
2009-10-25 18:24:20 -07:00
|
|
|
identity :id
|
|
|
|
|
2010-01-12 22:00:49 -08:00
|
|
|
attribute :addresses
|
|
|
|
attribute :password, 'adminPass'
|
2009-10-14 22:03:16 -07:00
|
|
|
attribute :flavor_id, 'flavorId'
|
|
|
|
attribute :host_id, 'hostId'
|
2010-01-12 22:00:49 -08:00
|
|
|
attribute :image_id, 'imageId'
|
|
|
|
attribute :metadata
|
|
|
|
attribute :name
|
2009-10-14 22:03:16 -07:00
|
|
|
attribute :personality
|
|
|
|
attribute :progress
|
2010-01-12 22:00:49 -08:00
|
|
|
attribute :status
|
2009-10-14 22:03:16 -07:00
|
|
|
|
|
|
|
def destroy
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :id
|
2009-10-14 22:03:16 -07:00
|
|
|
connection.delete_server(@id)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2010-01-12 22:00:49 -08:00
|
|
|
def flavor
|
|
|
|
requires :flavor_id
|
|
|
|
connection.flavors.get(@flavor_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
|
|
|
requires :image_id
|
|
|
|
connection.images.get(@image_id)
|
|
|
|
end
|
|
|
|
|
2009-11-19 08:19:46 -08:00
|
|
|
def images
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :id
|
2009-11-19 08:19:46 -08:00
|
|
|
connection.images(:server => self)
|
|
|
|
end
|
|
|
|
|
2010-01-12 22:00:49 -08:00
|
|
|
def ready?
|
|
|
|
@status == 'ACTIVE'
|
|
|
|
end
|
|
|
|
|
2009-11-21 10:42:20 -08:00
|
|
|
def reboot(type = 'SOFT')
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :id
|
2009-11-21 10:42:20 -08:00
|
|
|
connection.reboot_server(@id, type)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2009-10-14 22:03:16 -07:00
|
|
|
def save
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :flavor_id, :image_id, :name
|
2009-11-18 18:22:38 -08:00
|
|
|
options = { 'metadata' => @metadata, 'personality' => @personality }
|
2009-10-15 15:06:50 -07:00
|
|
|
options = options.reject {|key, value| value.nil?}
|
2009-11-18 18:22:38 -08:00
|
|
|
data = connection.create_server(@flavor_id, @image_id, @name, options)
|
2009-10-14 22:03:16 -07:00
|
|
|
merge_attributes(data.body['server'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|