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

112 lines
3.8 KiB
Ruby
Raw Normal View History

2011-02-20 22:01:28 -05:00
module Fog
module Parsers
module Compute
module Voxel
2011-02-20 22:01:28 -05:00
class DevicesList < Fog::Parsers::Base
def reset
@device = {}
2011-02-23 18:00:56 -05:00
@response = { 'devices' => [] }
2011-02-20 22:01:28 -05:00
@in_storage = false
end
def start_element(name, attrs = [])
super
case name
2011-02-23 18:00:56 -05:00
when 'accessmethod'
@access_method = { 'type' => attr_value('type', attrs) }
when 'accessmethods'
@device['access_methods'] = []
2011-02-20 22:01:28 -05:00
when 'device'
@device = {
2011-02-23 18:00:56 -05:00
'id' => attr_value('id', attrs),
'label' => attr_value('label', attrs),
'status' => attr_value('status', attrs)
2011-02-20 22:01:28 -05:00
}
2011-02-23 18:00:56 -05:00
when 'err'
@response['err'] = {
'code' => attr_value('code', attrs),
'msg' => attr_value('msg', attrs)
}
when 'cage', 'facility', 'rack', 'row', 'zone'
@device['location'][name] = { 'id' => attr_value('id', attrs) }
if code = attr_value('code', attrs)
@device['location'][name]['code'] = code
2011-02-20 22:01:28 -05:00
end
2011-02-23 18:00:56 -05:00
when 'drive'
@drive = { 'position' => attr_value('position', attrs) }
when 'ipassignment'
type = attr_value('type', attrs)
@device['ipassignments'] = []
@device['ipassignments'] << {
'id' => attr_value('id', attrs),
'type' => attr_value('type', attrs),
'description' => attr_value('description', attrs),
}
when 'ipassignments'
@device['ipassignments'] = {}
when 'location'
@device['location'] = {}
when 'memory'
@device['memory'] = { 'size' => attr_value('size', attrs).to_i }
when 'model', 'type'
@device[name] = { 'id' => attr_value('id', attrs) }
when 'operating_system'
@device['operating_system'] = {}
when 'power_consumption'
@device[name] = attr_value('unit', attrs)
when 'processor'
@device['processor'] = {}
when 'rsp'
@response['stat'] = attr_value('stat', attrs)
when 'storage'
@device['drives'] = []
2011-02-20 22:01:28 -05:00
end
end
def end_element(name)
case name
2011-02-23 18:00:56 -05:00
when 'access_method'
@device['access_methods'] << @access_method
when 'architecture'
@device['operating_system'][name] = value.to_i
2011-02-23 18:00:56 -05:00
when 'cage', 'facility', 'rack', 'row', 'zone'
@device['location'][name]['value'] = value
2011-02-23 18:00:56 -05:00
when 'cores'
@device['processor'][name] = value.to_i
2011-02-23 18:00:56 -05:00
when 'description'
@device[name] = value
2011-02-20 22:01:28 -05:00
when 'device'
2011-02-23 18:00:56 -05:00
@response['devices'] << @device
2011-02-20 22:01:28 -05:00
@device = {}
2011-02-23 18:00:56 -05:00
when 'drive'
@device['drives'] << @drive
@drive = {}
2011-02-20 22:01:28 -05:00
when 'cores'
@device['processing_cores'] = value.to_i
2011-02-20 22:01:28 -05:00
when 'ipassignment'
@device['ipassignments'].last['value'] = value
2011-02-23 18:00:56 -05:00
when 'model', 'type'
@device[name]['value'] = value
2011-02-23 18:00:56 -05:00
when 'name'
@device['operating_system'][name] = value
2011-02-23 18:00:56 -05:00
when 'position'
@device['location'][name] = value
2011-02-23 18:00:56 -05:00
when 'power_consumption'
@device[name] = [value, @device[name]].join(' ')
2011-02-23 18:00:56 -05:00
when 'size'
@drive[name] = value.to_i
2011-02-23 18:00:56 -05:00
when 'host', 'password', 'protocol', 'username'
@access_method[name] = value
2011-02-20 22:01:28 -05:00
end
end
end
end
end
end
end