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

Merge pull request #1557 from chirag-jog/terremark_xml_parser_fixes

Terremark xml parser fixes - issue #1549
This commit is contained in:
Wesley Beary 2013-02-12 08:22:33 -08:00
commit 9f2a25bdbf
20 changed files with 67 additions and 202 deletions

View file

@ -1,19 +1,20 @@
module Fog
module Terremark
module Shared
module Parser
remove_method :parse
def parse(data)
case data['type']
when 'application/vnd.vmware.vcloud.vApp+xml'
servers.new(data.merge!(:service => self))
else
data
end
class TerremarkParser < Fog::Parsers::Base
def extract_attributes(attributes_xml)
attributes = {}
until attributes_xml.empty?
if attributes_xml.first.is_a?(Array)
until attributes_xml.first.empty?
attribute = attributes_xml.first.shift
attributes[attribute.localname] = attribute.value
end
else
attribute = attributes_xml.shift
attributes[attribute.localname] = attribute.value
end
end
attributes
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetCatalog < Fog::Parsers::Base
class GetCatalog < TerremarkParser
def reset
@response = { 'CatalogItems' => [] }
@ -13,26 +13,12 @@ module Fog
super
case name
when 'CatalogItem'
catalog_item = {}
attributes.each do |attrib|
i = 0
while i < attrib.size
catalog_item[attrib[i]] = attrib[i+1]
i += 2
end
catalog_item["id"] = catalog_item["href"].split('/').last
end
catalog_item = extract_attributes(attributes)
catalog_item["id"] = catalog_item["href"].split('/').last
@response['CatalogItems'] << catalog_item
when 'Catalog'
catalog = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
catalog[attribute.first] = attribute.last
else
catalog[attributes.shift] = attributes.shift
end
end
catalog = extract_attributes(attributes)
@response['name'] = catalog['name']
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetCatalogItem < Fog::Parsers::Base
class GetCatalogItem < TerremarkParser
def reset
@response = { 'Entity' => {}, 'Properties' => {} }
@ -13,22 +13,12 @@ module Fog
super
case name
when 'Entity'
until attributes.empty?
@response['Entity'][attributes.shift] = attributes.shift
end
@response['Entity'] = extract_attributes(attributes)
when 'CatalogItem'
catalog_item = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
catalog_item[attribute.first] = attribute.last
else
catalog_item[attributes.shift] = attributes.shift
end
end
catalog_item = extract_attributes(attributes)
@response['name'] = catalog_item['name']
when 'Property'
@property_key = attributes.last
@property_key = attributes.value
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetInternetServices < Fog::Parsers::Base
class GetInternetServices < TerremarkParser
def reset
@in_public_ip_address = false

View file

@ -4,8 +4,7 @@ module Fog
module Terremark
module Shared
class GetKeysList < Fog::Parsers::Base
class GetKeysList < TerremarkParser
def reset
@response = { 'Keys' => [] }
@key = {}
@ -15,25 +14,12 @@ module Fog
super
case name
when 'Id', 'Href', 'Name', 'IsDefault','FingerPrint'
data = {}
until attributes.empty?
data[attributes.shift] = attributes.shift
end
data = extract_attributes(attributes)
@key[name] = data
when 'Key'
until attributes.empty?
@key[attributes.shift] = attributes.shift
end
@key = extract_attributes(attributes)
when 'Keys'
keys_list = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
keys_list[attribute.first] = attribute.last
else
keys_list[attributes.shift] = attributes.shift
end
end
keys_list = extract_attributes(attributes)
@response['href'] = keys_list['href']
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetNetworkIps< Fog::Parsers::Base
class GetNetworkIps< TerremarkParser
def reset
@ip_address = {}

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetNodeServices < Fog::Parsers::Base
class GetNodeServices < TerremarkParser
def reset
@node_service = {}

View file

@ -3,7 +3,8 @@ module Fog
module Terremark
module Shared
class GetOrganization < Fog::Parsers::Base
class GetOrganization < TerremarkParser
# include Fog::Terremark::Shared::Parser
def reset
@response = { 'Links' => [] }
@ -13,7 +14,7 @@ module Fog
super
case name
when 'Link'
link = {}
link = extract_attributes(attributes)
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
@ -24,7 +25,7 @@ module Fog
end
@response['Links'] << link
when 'Org'
org = {}
org = extract_attributes(attributes)
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift

View file

@ -3,7 +3,8 @@ module Fog
module Terremark
module Shared
class GetOrganizations < Fog::Parsers::Base
class GetOrganizations < TerremarkParser
# include Fog::Terremark::Shared::Parser
def reset
@response = { 'OrgList' => [] }
@ -12,7 +13,7 @@ module Fog
def start_element(name, attributes)
super
if name == 'Org'
organization = {}
organization = extract_attributes(attributes)
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetPublicIps< Fog::Parsers::Base
class GetPublicIps< TerremarkParser
def reset
@ip_address = {}

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetTasksList < Fog::Parsers::Base
class GetTasksList < TerremarkParser
def reset
@response = { 'Tasks' => [] }
@ -14,25 +14,12 @@ module Fog
super
case name
when 'Owner', 'Result'
data = {}
until attributes.empty?
data[attributes.shift] = attributes.shift
end
data = extract_templates(attributes)
@task[name] = data
when 'Task'
until attributes.empty?
@task[attributes.shift] = attributes.shift
end
@task = extract_templates(attributes)
when 'TasksList'
tasks_list = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
tasks_list[attribute.first] = attribute.last
else
tasks_list[attributes.shift] = attributes.shift
end
end
tasks_list = extract_templates(attributes)
@response['href'] = tasks_list['href']
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetVappTemplate < Fog::Parsers::Base
class GetVappTemplate < TerremarkParser
def reset
@response = { 'Links' => [] }
@ -13,21 +13,10 @@ module Fog
super
case name
when 'Link'
link = {}
until attributes.empty?
link[attributes.shift] = attributes.shift
end
link = extract_attributes(attributes)
@response['Links'] << link
when 'VAppTemplate'
vapp_template = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
vapp_template[attribute.first] = attribute.last
else
vapp_template[attributes.shift] = attributes.shift
end
end
vapp_template = extract_attributes(attributes)
@response['name'] = vapp_template['name']
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class GetVdc < Fog::Parsers::Base
class GetVdc < TerremarkParser
def reset
@in_storage_capacity = false
@ -11,7 +11,7 @@ module Fog
@in_memory = false
@in_instantiated_vms_quota = false
@in_deployed_vms_quota = false
@response = {
@response = {
'links' => [],
'AvailableNetworks' => [],
'ComputeCapacity' => {
@ -35,52 +35,20 @@ module Fog
when 'InstantiatedVmsQuota'
@in_instantiated_vms_quota = true
when 'Link'
link = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
link[attribute.first] = attribute.last
else
link[attributes.shift] = attributes.shift
end
end
link = extract_attributes(attributes)
@response['links'] << link
when 'Memory'
@in_memory = true
when 'Network'
network = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
network[attribute.first] = attribute.last
else
network[attributes.shift] = attributes.shift
end
end
network = extract_attributes(attributes)
@response['AvailableNetworks'] << network
when 'ResourceEntity'
resource_entity = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
resource_entity[attribute.first] = attribute.last
else
resource_entity[attributes.shift] = attributes.shift
end
end
resource_entity = extract_attributes(attributes)
@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
vdc = extract_attributes(attributes)
@response['href'] = vdc['href']
@response['name'] = vdc['name']
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class InstantiateVappTemplate < Fog::Parsers::Base
class InstantiateVappTemplate < TerremarkParser
def reset
@property_key
@ -14,21 +14,10 @@ module Fog
super
case name
when 'Link'
link = {}
until attributes.empty?
link[attributes.shift] = attributes.shift
end
link = extract_attributes(attributes)
@response['Links'] << link
when 'VApp'
vapp_template = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
vapp_template[attribute.first] = attribute.last
else
vapp_template[attributes.shift] = attributes.shift
end
end
vapp_template = extract_attributes(attributes)
@response.merge!(vapp_template.reject {|key, value| !['href', 'name', 'size', 'status', 'type'].include?(key)})
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class InternetService < Fog::Parsers::Base
class InternetService < TerremarkParser
def reset
@in_public_ip_address = false
@ -14,10 +14,7 @@ module Fog
super
case name
when 'Href'
data = {}
until attributes.empty?
data[attributes.shift] = attributes.shift
end
data = extract_attributes(attributes)
if @in_public_ip_address
@response['PublicIpAddress'][name] = data
else

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class Network < Fog::Parsers::Base
class Network < TerremarkParser
def reset
@response = {
@ -15,12 +15,7 @@ module Fog
super
case name
when "Network"
until attributes.empty?
val = attributes.shift
if val.is_a?(String)
@response[val] = attributes.shift
end
end
@response = extract_attributes(attributes)
if @response.has_key?("name")
@response["subnet"] = @response["name"]
end
@ -28,10 +23,7 @@ module Fog
@response["id"] = @response["href"].split("/").last
end
when "Link"
link = {}
until attributes.empty?
link[attributes.shift] = attributes.shift
end
link = extract_attributes(attributes)
@response["links"] << link
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class NodeService < Fog::Parsers::Base
class NodeService < TerremarkParser
def reset
@response = {}

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class PublicIp < Fog::Parsers::Base
class PublicIp < TerremarkParser
def reset
@response = {}

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class Task < Fog::Parsers::Base
class Task < TerremarkParser
def reset
@response = {}
@ -13,21 +13,10 @@ module Fog
super
case name
when 'Owner', 'Result', 'Link', 'Error'
data = {}
until attributes.empty?
data[attributes.shift] = attributes.shift
end
data = extract_attributes(attributes)
@response[name] = data
when 'Task'
task = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
task[attribute.first] = attribute.last
else
task[attributes.shift] = attributes.shift
end
end
task = extract_attributes(attributes)
@response.merge!(task.reject {|key,value| !['endTime', 'href', 'startTime', 'status', 'type'].include?(key)})
end
end

View file

@ -3,7 +3,7 @@ module Fog
module Terremark
module Shared
class Vapp < Fog::Parsers::Base
class Vapp < TerremarkParser
def reset
@response = { 'Links' => [], 'VirtualHardware' => {}, 'OperatingSystem' => {} }
@ -15,23 +15,12 @@ module Fog
super
case name
when 'Link'
link = {}
until attributes.empty?
link[attributes.shift] = attributes.shift
end
link = extract_attributes(attributes)
@response['Links'] << link
when 'OperatingSystemSection'
@in_operating_system = true
when 'VApp'
vapp = {}
until attributes.empty?
if attributes.first.is_a?(Array)
attribute = attributes.shift
vapp[attribute.first] = attribute.last
else
vapp[attributes.shift] = attributes.shift
end
end
vapp = extract_attributes(attributes)
@response.merge!(vapp.reject {|key,value| !['href', 'name', 'size', 'status', 'type'].include?(key)})
end
end