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 unless @required
require 'fog/terremark/parsers/get_catalog' require 'fog/terremark/parsers/get_catalog'
require 'fog/terremark/parsers/get_catalog_item' 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_organization'
require 'fog/terremark/parsers/get_organizations' require 'fog/terremark/parsers/get_organizations'
require 'fog/terremark/parsers/get_public_ips' require 'fog/terremark/parsers/get_public_ips'
@ -26,6 +28,8 @@ module Fog
require 'fog/terremark/requests/deploy_vapp' require 'fog/terremark/requests/deploy_vapp'
require 'fog/terremark/requests/get_catalog' require 'fog/terremark/requests/get_catalog'
require 'fog/terremark/requests/get_catalog_item' 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_organization'
require 'fog/terremark/requests/get_organizations' require 'fog/terremark/requests/get_organizations'
require 'fog/terremark/requests/get_public_ips' require 'fog/terremark/requests/get_public_ips'

View file

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

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

View file

@ -2,7 +2,7 @@ module Fog
module Terremark module Terremark
class Real 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 # Get a list of all internet services for a vdc
# #