1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

cleanup/fleshing out parsers

This commit is contained in:
geemus (Wesley Beary) 2010-04-16 18:31:00 -07:00
parent b452b885f9
commit f0527aaa7b
5 changed files with 77 additions and 31 deletions

View file

@ -6,6 +6,8 @@ module Fog
unless @required
require 'fog/terremark/parsers/get_catalog'
require 'fog/terremark/parsers/get_catalog_item'
require 'fog/terremark/parsers/get_internet_services'
require 'fog/terremark/parsers/get_node_services'
require 'fog/terremark/parsers/get_organization'
require 'fog/terremark/parsers/get_organizations'
require 'fog/terremark/parsers/get_public_ips'
@ -26,6 +28,8 @@ module Fog
require 'fog/terremark/requests/deploy_vapp'
require 'fog/terremark/requests/get_catalog'
require 'fog/terremark/requests/get_catalog_item'
require 'fog/terremark/requests/get_internet_services'
require 'fog/terremark/requests/get_node_services'
require 'fog/terremark/requests/get_organization'
require 'fog/terremark/requests/get_organizations'
require 'fog/terremark/requests/get_public_ips'

View file

@ -1,46 +1,58 @@
module Fog
module Parsers
module Terremark
class GetInternetServices < Fog::Parsers::Base
def reset
@in_public_ip_address = false
@in_internet_service = false
@response = { 'InternetServices' => [] } #an array of internet services
@internet_service = {}
@response = { 'InternetServices' => [] }
end
def start_element(name, attributes)
@value = ''
case name
when 'InternetService' #start of a new InternetService:
@in_internet_service = true
when 'PublicIPAddress' #start of new IP Address
when 'PublicIPAddress'
@in_public_ip_address = true
end
end
def end_element(name)
case name
when 'PublicIPAddress'
@in_public_ip_address = false
when 'InternetService'
@in_internet_service = false
when 'Id', 'Name'
when 'Description', 'Protocol'
@internet_service[name] = @value
when 'Enabled'
if @value == 'true'
@internet_service[name] = true
else
@internet_service[name] = false
end
when 'Href', 'Name'
if @in_public_ip_address
@response['InternetServices'].last['PublicIPAddress'][name] = @value
elsif @in_internet_service
@response['InternetServices'].last[name] = @value
@internet_service['PublicIpAddress'] ||= {}
@internet_service['PublicIpAddress'][name] = @value
else
@internet_service[name] = @value
end
when 'Id'
if @in_public_ip_address
@internet_service['PublicIpAddress'] ||= {}
@internet_service['PublicIpAddress'][name] = @value.to_i
else
@internet_service[name] = @value.to_i
end
when 'InternetService'
@response['InternetServices'] << @internet_service
@internet_service = {}
when 'Port', 'Timeout'
@internet_service[name] = @value.to_i
when 'PublicIPAddress'
@in_public_ip_address = false
end
end
end
end #end class
end #end Terremark
end #end Parsers
end #end Fog
end
end
end

View file

@ -0,0 +1,31 @@
module Fog
module Parsers
module Terremark
class GetNodeServices < Fog::Parsers::Base
def reset
@node_service = {}
@response = { 'NodeServices' => [] }
end
def end_element(name)
case name
when 'Description', 'Href', 'Name', 'IpAddress'
@node_service[name] = @value
when 'Enabled'
if @value == 'true'
@node_service[name] = true
else
@node_service[name] = false
end
when 'Id', 'Port'
@node_service[name] = @value.to_i
end
end
end
end
end
end

View file

@ -8,7 +8,7 @@ module Fog
#
# ==== Parameters
# * vdc_id<~Integer> - Id of vDc to get list of internet services for
#
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
@ -18,9 +18,8 @@ module Fog
# * 'PublicIPAddress'<~Hash>
# * 'Id'<~String> => id of the public IP
# * 'name'<~String> => actual ip address
#
#
def get_internet_services(vdc_id)
request(
:expects => 200,
:method => 'GET',

View file

@ -2,7 +2,7 @@ module Fog
module Terremark
class Real
require 'fog/terremark/parsers/node_service'
require 'fog/terremark/parsers/get_node_services'
# Get a list of all internet services for a vdc
#