Class: Fog::Parsers::Terremark::GetVdc

Inherits:
Base
  • Object
show all
Defined in:
lib/fog/terremark/parsers/get_vdc.rb

Instance Attribute Summary

Attributes inherited from Base

#response

Instance Method Summary collapse

Methods inherited from Base

#characters, #initialize

Constructor Details

This class inherits a constructor from Fog::Parsers::Base

Instance Method Details

#end_element(name) ⇒ Object


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fog/terremark/parsers/get_vdc.rb', line 73

def end_element(name)
  case name
  when 'Allocated', 'Limit', 'Units', 'Used'
    if @in_cpu
      @response['Compute Capacity']['Cpu'][name] = @value
    elsif @in_deployed_vms_quota
      @response['Compute Capacity']['DeployedVmsQuota'][name] = @value
    elsif @in_instantiated_vms_quota
      @response['Compute Capacity']['InstantiatedVmsQuota'][name] = @value
    elsif @in_memory
      @response['Compute Capacity']['Memory'][name] = @value
    elsif @in_storage_capacity
      @response['StorageCapacity'][name] = @value
    end
  when 'Cpu'
    @in_cpu = false
  when 'DeployedVmsQuota'
    @in_deployed_vms_quota = false
  when 'InstantiatedVmsQuota'
    @in_instantiated_vms_quota = false
  when 'Memory'
    @in_memory = false
  when 'StorageCapacity'
    @in_storage_capacity = false
  when 'Type'
    @response[name] = @value
  end
end

#resetObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/terremark/parsers/get_vdc.rb', line 7

def reset
  @in_storage_capacity = false
  @in_cpu = false
  @in_memory = false
  @in_instantiated_vms_quota = false
  @in_deployed_vms_quota = false
  @response = { 
    'links' => [],
    'AvailableNetworks' => [],
    'ComputeCapacity'   => {
      'Cpu' => {},
      'DeployedVmsQuota' => {},
      'InstantiatedVmsQuota' => {},
      'Memory' => {}
    },
    'StorageCapacity'  => {},
    'ResourceEntities' => []
  }
end

#start_element(name, attributes) ⇒ Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fog/terremark/parsers/get_vdc.rb', line 27

def start_element(name, attributes)
  @value = ''
  case name
  when 'Cpu'
    @in_cpu = true
  when 'DeployedVmsQuota'
    @in_deployed_vms_quota = true
  when 'InstantiatedVmsQuota'
    @in_instantiated_vms_quota = true
  when 'Link'
    link = {}
    until attributes.empty?
      link[attributes.shift] = attributes.shift
    end            
    @response['links'] << link
  when 'Memory'
    @in_memory = true
  when 'Network'
    network = {}
    until attributes.empty?
      network[attributes.shift] = attributes.shift
    end
    @response['AvailableNetworks'] << network
  when 'ResourceEntity'
    resource_entity = {}
    until attributes.empty?
      resource_entity[attributes.shift] = attributes.shift
    end
    @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
    @response['href'] = vdc['href']
    @response['name'] = vdc['name']
  end
end