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