2010-05-24 14:03:52 -04:00
|
|
|
require 'fog/model'
|
|
|
|
|
|
|
|
module Fog
|
2010-09-03 04:11:45 -04:00
|
|
|
class Bluebox
|
2010-05-24 14:03:52 -04:00
|
|
|
|
|
|
|
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
|
2010-06-04 00:32:59 -04:00
|
|
|
# attribute :image_id
|
2010-06-04 01:02:17 -04:00
|
|
|
|
|
|
|
attr_accessor :image_id
|
2010-06-04 00:32:59 -04:00
|
|
|
attribute :template
|
2010-05-24 14:03:52 -04:00
|
|
|
|
|
|
|
# Not reported by the API, but used at create time
|
2010-06-04 01:20:31 -04:00
|
|
|
attr_accessor :password, :ssh_key, :user
|
2010-05-24 14:03:52 -04:00
|
|
|
|
|
|
|
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?
|
|
|
|
@status == 'running'
|
|
|
|
end
|
|
|
|
|
|
|
|
def reboot(type = 'SOFT')
|
|
|
|
requires :id
|
|
|
|
connection.reboot_block(@id, type)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2010-06-08 01:14:15 -04:00
|
|
|
requires :flavor_id, :image_id
|
2010-06-04 01:02:17 -04:00
|
|
|
options = if !@password && !@ssh_key
|
|
|
|
raise(ArgumentError, "password or ssh_key is required for this operation")
|
|
|
|
elsif @ssh_key
|
|
|
|
{'ssh_key' => @ssh_key}
|
|
|
|
elsif @password
|
|
|
|
{'password' => @password}
|
|
|
|
end
|
2010-06-04 01:20:31 -04:00
|
|
|
if @user
|
|
|
|
options['user'] = @user
|
|
|
|
end
|
|
|
|
data = connection.create_block(@flavor_id, @image_id, options)
|
2010-05-24 14:03:52 -04:00
|
|
|
merge_attributes(data.body)
|
|
|
|
true
|
|
|
|
end
|
2010-06-04 00:32:59 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def product=(new_product)
|
|
|
|
@flavor_id = new_product['id']
|
|
|
|
end
|
|
|
|
|
2010-05-24 14:03:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|