2010-04-16 03:20:02 -04:00
|
|
|
module Fog
|
|
|
|
module Parsers
|
|
|
|
module Terremark
|
|
|
|
module Shared
|
|
|
|
|
|
|
|
class GetVdc < Fog::Parsers::Base
|
|
|
|
|
|
|
|
def reset
|
|
|
|
@in_storage_capacity = false
|
|
|
|
@in_cpu = false
|
|
|
|
@in_memory = false
|
|
|
|
@in_instantiated_vms_quota = false
|
|
|
|
@in_deployed_vms_quota = false
|
|
|
|
@response = {
|
|
|
|
'links' => [],
|
|
|
|
'AvailableNetworks' => [],
|
|
|
|
'ComputeCapacity' => {
|
|
|
|
'Cpu' => {},
|
|
|
|
'DeployedVmsQuota' => {},
|
|
|
|
'InstantiatedVmsQuota' => {},
|
|
|
|
'Memory' => {}
|
|
|
|
},
|
|
|
|
'StorageCapacity' => {},
|
|
|
|
'ResourceEntities' => []
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_element(name, attributes)
|
2010-05-05 16:39:41 -04:00
|
|
|
super
|
2010-04-16 03:20:02 -04:00
|
|
|
case name
|
|
|
|
when 'Cpu'
|
|
|
|
@in_cpu = true
|
|
|
|
when 'DeployedVmsQuota'
|
|
|
|
@in_deployed_vms_quota = true
|
|
|
|
when 'InstantiatedVmsQuota'
|
|
|
|
@in_instantiated_vms_quota = true
|
|
|
|
when 'Link'
|
|
|
|
link = {}
|
|
|
|
until attributes.empty?
|
2010-12-07 19:37:43 -05:00
|
|
|
if attributes.first.is_a?(Array)
|
|
|
|
attribute = attributes.shift
|
|
|
|
link[attribute.first] = attribute.last
|
|
|
|
else
|
|
|
|
link[attributes.shift] = attributes.shift
|
|
|
|
end
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
@response['links'] << link
|
|
|
|
when 'Memory'
|
|
|
|
@in_memory = true
|
|
|
|
when 'Network'
|
|
|
|
network = {}
|
|
|
|
until attributes.empty?
|
2010-12-07 19:37:43 -05:00
|
|
|
if attributes.first.is_a?(Array)
|
|
|
|
attribute = attributes.shift
|
|
|
|
network[attribute.first] = attribute.last
|
|
|
|
else
|
|
|
|
network[attributes.shift] = attributes.shift
|
|
|
|
end
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
@response['AvailableNetworks'] << network
|
|
|
|
when 'ResourceEntity'
|
|
|
|
resource_entity = {}
|
|
|
|
until attributes.empty?
|
2010-12-07 19:37:43 -05:00
|
|
|
if attributes.first.is_a?(Array)
|
|
|
|
attribute = attributes.shift
|
|
|
|
resource_entity[attribute.first] = attribute.last
|
|
|
|
else
|
|
|
|
resource_entity[attributes.shift] = attributes.shift
|
|
|
|
end
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
@response['ResourceEntities'] << resource_entity
|
|
|
|
when 'StorageCapacity'
|
|
|
|
@in_storage_capacity = true
|
|
|
|
when 'Vdc'
|
|
|
|
vdc = {}
|
|
|
|
until attributes.empty?
|
|
|
|
if attributes.first.is_a?(Array)
|
|
|
|
attribute = attributes.shift
|
|
|
|
vdc[attribute.first] = attribute.last
|
|
|
|
else
|
|
|
|
vdc[attributes.shift] = attributes.shift
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@response['href'] = vdc['href']
|
|
|
|
@response['name'] = vdc['name']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_element(name)
|
|
|
|
case name
|
|
|
|
when 'Allocated', 'Limit', 'Units', 'Used'
|
|
|
|
if @in_cpu
|
2011-05-12 16:15:13 -04:00
|
|
|
@response['ComputeCapacity']['Cpu'][name] = value
|
2010-04-16 03:20:02 -04:00
|
|
|
elsif @in_deployed_vms_quota
|
2011-05-12 16:15:13 -04:00
|
|
|
@response['ComputeCapacity']['DeployedVmsQuota'][name] = value
|
2010-04-16 03:20:02 -04:00
|
|
|
elsif @in_instantiated_vms_quota
|
2011-05-12 16:15:13 -04:00
|
|
|
@response['ComputeCapacity']['InstantiatedVmsQuota'][name] = value
|
2010-04-16 03:20:02 -04:00
|
|
|
elsif @in_memory
|
2011-05-12 16:15:13 -04:00
|
|
|
@response['ComputeCapacity']['Memory'][name] = value
|
2010-04-16 03:20:02 -04:00
|
|
|
elsif @in_storage_capacity
|
2011-05-12 16:15:13 -04:00
|
|
|
@response['StorageCapacity'][name] = value
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
when 'Cpu'
|
|
|
|
@in_cpu = false
|
|
|
|
when 'DeployedVmsQuota'
|
|
|
|
@in_deployed_vms_quota = false
|
|
|
|
when 'InstantiatedVmsQuota'
|
|
|
|
@in_instantiated_vms_quota = false
|
|
|
|
when 'Memory'
|
|
|
|
@in_memory = false
|
|
|
|
when 'StorageCapacity'
|
|
|
|
@in_storage_capacity = false
|
|
|
|
when 'Type'
|
2011-05-12 16:15:13 -04:00
|
|
|
@response[name] = value
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|