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/compute/models/voxel/server.rb

79 lines
1.8 KiB
Ruby
Raw Normal View History

2011-01-19 17:07:04 -05:00
require 'fog/core/model'
module Fog
module Voxel
class Compute
class Server < Fog::Model
identity :id
attribute :name
attribute :processing_cores
attribute :image_id
2011-01-19 17:07:04 -05:00
attribute :facility
attribute :disk_size
2011-02-23 18:00:56 -05:00
attribute :ip_assignments, :aliases => 'ipassignments'
2011-01-19 17:07:04 -05:00
def initialize(attributes={})
self.image_id ||= '55' # Ubuntu 10.04 LTS 64bit
2011-01-19 17:07:04 -05:00
super
end
def destroy
requires :id
connection.voxcloud_delete(id)
true
end
def image
requires :image_id
2011-02-23 18:00:56 -05:00
connection.images.get(image_id)
2011-01-19 17:07:04 -05:00
end
def ready?
self.state == 'SUCCEEDED'
2011-02-20 14:39:37 -05:00
end
2011-02-23 18:00:56 -05:00
def private_ip_address
ip_assignments.select {|ip_assignment| ip_assignment['type'] == 'internal'}.first
end
def public_ip_address
ip_assignments.select {|ip_assignment| ip_assignment['type'] == 'external'}.first
end
def reboot
requires :id
connection.devices_power(id, :reboot)
true
end
def state
@state ||= connection.voxcloud_status(id).body['devices'].first['status']
2011-01-19 17:07:04 -05:00
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :name, :image_id, :processing_cores, :facility, :disk_size
2011-01-19 17:07:04 -05:00
2011-02-23 18:00:56 -05:00
data = connection.voxcloud_create({
:disk_size => disk_size,
:facility => facility,
:hostname => name,
:image_id => image_id,
:processing_cores => processing_cores
}).body
2011-01-19 17:07:04 -05:00
2011-02-23 18:00:56 -05:00
merge_attributes(data['device'])
2011-01-19 17:07:04 -05:00
true
end
end
end
end
end