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/requests/voxel/devices_list.rb

49 lines
1.2 KiB
Ruby
Raw Normal View History

2011-01-19 17:07:04 -05:00
module Fog
module Voxel
class Compute
class Real
def devices_list( device_id = nil )
# name, processing_cores, status, facility
options = { :verbosity => 'normal' }
unless device_id.nil?
options[:device_id] = device_id
end
2011-02-20 22:01:28 -05:00
data = request("voxel.devices.list", options, Fog::Parsers::Voxel::Compute::DevicesList.new).body
2011-01-19 17:07:04 -05:00
2011-02-20 22:01:28 -05:00
if data[:stat] == 'fail'
2011-02-20 14:39:37 -05:00
raise Fog::Voxel::Compute::NotFound
2011-02-20 22:01:28 -05:00
elsif data[:devices].empty?
[]
else
2011-02-20 22:01:28 -05:00
devices = data[:devices]
## TODO find both voxserver and voxcloud devices
2011-02-20 22:01:28 -05:00
devices.select { |d| d[:type] == '3' }.map do |device|
device.delete(:type)
device.merge( :image_id => 0 )
end
2011-01-19 17:07:04 -05:00
end
end
end
class Mock
def devices_list( device_id = nil)
if device_id.nil?
2011-02-20 14:39:37 -05:00
@data[:servers]
else
2011-02-20 14:39:37 -05:00
result = @data[:servers].select { |d| d[:id] == device_id }
if result.empty?
raise Fog::Voxel::Compute::NotFound
else
result
end
end
2011-01-19 17:07:04 -05:00
end
end
end
end
end