1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Compute mostly working for server creates

This commit is contained in:
James W. Brinkerhoff 2011-01-19 19:17:23 -05:00 committed by geemus
parent f475f14e64
commit 1bbb919dff
6 changed files with 83 additions and 6 deletions

View file

@ -12,10 +12,11 @@ module Fog
attribute :name
attribute :processing_cores
#attribute :image_id # id or name
attribute :image_id
#attribute :ip
attribute :status
attribute :facility
attribute :disk_size
def initialize(attributes={})
super
@ -38,13 +39,13 @@ module Fog
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :name, :image_id, :processing_cores, :facility
requires :name, :image_id, :processing_cores, :facility, :disk_size
options = { :hostname => name, :image_id => 16, :processing_cores => processing_cores, :facility => facility }
options = { :hostname => name, :image_id => image_id, :processing_cores => processing_cores, :facility => facility, :disk_size => disk_size }
data = connection.voxcloud_create(options)
merge_attributes(data)
merge_attributes(data.first)
true
end

View file

@ -10,6 +10,11 @@ module Fog
def all
data = connection.devices_list
statuses = connection.voxcloud_status
data.each_index do |i|
data[i][:status] = statuses.select { |s| s[:id] == data[i][:id] }.first[:status]
end
load(data)
end
@ -21,7 +26,10 @@ module Fog
def get(device_id)
if device_id && server = connection.devices_list(device_id)
new(server)
status = connection.voxcloud_status(device_id)
server.first[:status] = status.first[:status]
new(server.first)
end
rescue Fog::Voxel::Compute::NotFound
nil

View file

@ -16,8 +16,14 @@ module Fog
data = request("voxel.devices.list", options)
if data['devices']['device'].is_a?(Hash)
devices = [ data['devices']['device'] ]
else
devices = data['devices']['device']
end
## TODO find both voxserver and voxcloud devices
data['devices']['device'].select { |d| d['type']['id'] == '3' }.map do |device|
devices.select { |d| d['type']['id'] == '3' }.map do |device|
{ :id => device['id'],
:name => device['label'],
:processing_cores => device['processor']['cores'],

View file

@ -0,0 +1,26 @@
module Fog
module Voxel
class Compute
class Real
def voxcloud_create( options )
## TODO Remove this
options.merge! :customer_id => 1470
data = request("voxel.voxcloud.create", options)
unless data['stat'] == 'ok'
raise "Error from hAPI: #{data['err']['msg']}"
end
devices_list(data['device']['id'])
end
end
class Mock
def images_list
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,34 @@
module Fog
module Voxel
class Compute
class Real
def voxcloud_status( device_id = nil )
options = { :verbosity => 'compact' }
## TODO remove this
options[:customer_id] = 1470
unless device_id.nil?
options[:device_id] = device_id
end
data = request("voxel.voxcloud.status", options)
if data['devices']['device'].is_a?(Hash)
devices = [ data['devices']['device'] ]
else
devices = data['devices']['device']
end
devices.map { |d| { :id => d['id'], :status => d['status'] } }
end
end
class Mock
def images_list
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -13,6 +13,8 @@ module Fog
request_path 'fog/compute/requests/voxel'
request :images_list
request :devices_list
request :voxcloud_create
request :voxcloud_status
class Mock
include Collections