1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/rackspace/models/servers/server.rb

71 lines
1.5 KiB
Ruby
Raw Normal View History

require 'fog/model'
module Fog
module Rackspace
module Servers
class Server < Fog::Model
identity :id
attribute :addresses
attribute :password, 'adminPass'
attribute :flavor_id, 'flavorId'
attribute :host_id, 'hostId'
attribute :image_id, 'imageId'
attribute :metadata
attribute :name
attribute :personality
attribute :progress
attribute :status
def destroy
requires :id
connection.delete_server(@id)
true
end
def flavor
requires :flavor_id
connection.flavors.get(@flavor_id)
end
def image
requires :image_id
connection.images.get(@image_id)
end
def images
requires :id
connection.images(:server => self)
end
def ready?
@status == 'ACTIVE'
end
def reboot(type = 'SOFT')
requires :id
connection.reboot_server(@id, type)
true
end
def save
requires :flavor_id, :image_id
options = {
'metadata' => @metadata,
'name' => @name,
'personality' => @personality
}
2009-10-15 18:06:50 -04:00
options = options.reject {|key, value| value.nil?}
data = connection.create_server(@flavor_id, @image_id, options)
merge_attributes(data.body['server'])
true
end
end
end
end
end