2011-02-20 22:01:28 -05:00
|
|
|
module Fog
|
|
|
|
module Parsers
|
2011-06-16 19:28:54 -04:00
|
|
|
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'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device['operating_system'][name] = value.to_i
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'cage', 'facility', 'rack', 'row', 'zone'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device['location'][name]['value'] = value
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'cores'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device['processor'][name] = value.to_i
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'description'
|
2011-05-12 16:15:13 -04:00
|
|
|
@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'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device['processing_cores'] = value.to_i
|
2011-02-20 22:01:28 -05:00
|
|
|
when 'ipassignment'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device['ipassignments'].last['value'] = value
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'model', 'type'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device[name]['value'] = value
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'name'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device['operating_system'][name] = value
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'position'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device['location'][name] = value
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'power_consumption'
|
2011-05-12 16:15:13 -04:00
|
|
|
@device[name] = [value, @device[name]].join(' ')
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'size'
|
2011-05-12 16:15:13 -04:00
|
|
|
@drive[name] = value.to_i
|
2011-02-23 18:00:56 -05:00
|
|
|
when 'host', 'password', 'protocol', 'username'
|
2011-05-12 16:15:13 -04:00
|
|
|
@access_method[name] = value
|
2011-02-20 22:01:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|