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/bluebox/models/server.rb
ggoodale 2a9224cfa7 [bbg] flesh out bbg support
Added basic spec framework; changed class names to match the template fog seems to prefer

Servers tests pass; create and delete implemented.

Added an example script

Properly handle a 409 response from the API

Fixed BBG code to work with the new api endpoint changes; tweaks to the (currently nonexistent) reboot api call

Implement the reboot command for blocks
2010-06-03 14:48:53 -07:00

60 lines
1.3 KiB
Ruby

require 'fog/model'
module Fog
module Bluebox
class BlockInstantiationError < StandardError; end
class Server < Fog::Model
identity :id
attribute :memory
attribute :storage
attribute :hostname
attribute :cpu
attribute :ips
attribute :status
attribute :flavor_id
attribute :image_id
# Not reported by the API, but used at create time
attr_accessor :name, :password, :hash, :text, :error
def destroy
requires :id
connection.destroy_block(@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 ready?
raise Fog::Bluebox::BlockInstantiationError, "Error creating block #{self.id}" if @status == 'error'
@status == 'running'
end
def reboot(type = 'SOFT')
requires :id
connection.reboot_block(@id, type)
true
end
def save
requires :flavor_id, :image_id, :name, :password
data = connection.create_block(@flavor_id, @image_id, @name, @password)
merge_attributes(data.body)
true
end
end
end
end