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

Use the TerremarkParser to extract relevant attributes

This commit is contained in:
Chirag Jog 2013-02-12 18:22:46 +05:30
parent 6a0cb4fca8
commit 8cb8049390
19 changed files with 53 additions and 189 deletions

View file

@ -3,7 +3,7 @@ module Fog
module Terremark module Terremark
module Shared module Shared
class GetCatalog < Fog::Parsers::Base class GetCatalog < TerremarkParser
def reset def reset
@response = { 'CatalogItems' => [] } @response = { 'CatalogItems' => [] }
@ -13,26 +13,12 @@ module Fog
super super
case name case name
when 'CatalogItem' when 'CatalogItem'
catalog_item = {} catalog_item = extract_attributes(attributes)
attributes.each do |attrib| catalog_item["id"] = catalog_item["href"].split('/').last
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
@response['CatalogItems'] << catalog_item @response['CatalogItems'] << catalog_item
when 'Catalog' when 'Catalog'
catalog = {} catalog = extract_attributes(attributes)
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
@response['name'] = catalog['name'] @response['name'] = catalog['name']
end end
end end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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