mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
DRYer refactored version.
This commit is contained in:
parent
f828eebdd1
commit
c885b5f896
2 changed files with 6 additions and 82 deletions
|
@ -22,51 +22,13 @@ module Fog
|
|||
@response[:vm].merge!(vm_attrs.reject {|key,value| ![:href, :name, :status, :type, :deployed].include?(key)})
|
||||
@response[:vm][:id] = @response[:vm][:href].split('/').last
|
||||
@response[:vm][:status] = human_status(@response[:vm][:status])
|
||||
when 'HostResource'
|
||||
@current_host_resource = extract_attributes(attributes)
|
||||
when 'Connection'
|
||||
@current_network_connection = extract_attributes(attributes)
|
||||
when 'Link'
|
||||
@links << extract_attributes(attributes)
|
||||
else
|
||||
parse_start_element name, attributes, @response[:vm]
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'IpAddress'
|
||||
@response[:vm][:ip_address] = value
|
||||
when 'Description'
|
||||
if @in_operating_system
|
||||
@response[:vm][:operating_system] = value
|
||||
@in_operating_system = false
|
||||
end
|
||||
when 'ResourceType'
|
||||
@resource_type = value
|
||||
when 'VirtualQuantity'
|
||||
case @resource_type
|
||||
when '3'
|
||||
@response[:vm][:cpu] = value
|
||||
when '4'
|
||||
@response[:vm][:memory] = value
|
||||
end
|
||||
when 'ElementName'
|
||||
@element_name = value
|
||||
when 'Item'
|
||||
case @resource_type
|
||||
when '17' # disk
|
||||
@response[:vm][:disks] ||= []
|
||||
@response[:vm][:disks] << { @element_name => @current_host_resource[:capacity].to_i }
|
||||
when '10' # nic
|
||||
@response[:vm][:network_adapters] ||= []
|
||||
@response[:vm][:network_adapters] << {
|
||||
:ip_address => @current_network_connection[:ipAddress],
|
||||
:primary => (@current_network_connection[:primaryNetworkConnection] == 'true'),
|
||||
:ip_allocation_mode => @current_network_connection[:ipAddressingMode]
|
||||
}
|
||||
end
|
||||
when 'Link'
|
||||
@response[:vm][:links] = @links
|
||||
end
|
||||
parse_end_element name, @response[:vm]
|
||||
end
|
||||
|
||||
def human_status(status)
|
||||
|
|
|
@ -33,52 +33,14 @@ module Fog
|
|||
@response[:id] = @response[:href].split('/').last
|
||||
when 'Children'
|
||||
@in_children = true
|
||||
when 'HostResource'
|
||||
@current_host_resource = extract_attributes(attributes)
|
||||
when 'Connection'
|
||||
@current_network_connection = extract_attributes(attributes)
|
||||
when 'Link'
|
||||
@links << extract_attributes(attributes)
|
||||
else
|
||||
parse_start_element name, attributes, @vm
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
if @in_children
|
||||
case name
|
||||
when 'IpAddress'
|
||||
@vm[:ip_address] = value
|
||||
when 'Description'
|
||||
if @in_operating_system
|
||||
@vm[:operating_system] = value
|
||||
@in_operating_system = false
|
||||
end
|
||||
when 'ResourceType'
|
||||
@resource_type = value
|
||||
when 'VirtualQuantity'
|
||||
case @resource_type
|
||||
when '3'
|
||||
@vm[:cpu] = value
|
||||
when '4'
|
||||
@vm[:memory] = value
|
||||
end
|
||||
when 'ElementName'
|
||||
@element_name = value
|
||||
when 'Item'
|
||||
case @resource_type
|
||||
when '17' # disk
|
||||
@vm[:disks] ||= []
|
||||
@vm[:disks] << { @element_name => @current_host_resource[:capacity].to_i }
|
||||
when '10' # nic
|
||||
@vm[:network_adapters] ||= []
|
||||
@vm[:network_adapters] << {
|
||||
:ip_address => @current_network_connection[:ipAddress],
|
||||
:primary => (@current_network_connection[:primaryNetworkConnection] == 'true'),
|
||||
:ip_allocation_mode => @current_network_connection[:ipAddressingMode]
|
||||
}
|
||||
end
|
||||
when 'Link'
|
||||
@vm[:links] = @links
|
||||
when 'Vm'
|
||||
if name == 'Vm'
|
||||
@response[:vms] << @vm
|
||||
@vm = {}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue