Class: Fog::Parsers::Compute::VcloudDirector::VmsByMetadata

Inherits:
VcloudDirectorParser show all
Defined in:
lib/fog/vcloud_director/parsers/compute/vms_by_metadata.rb

Instance Attribute Summary

Attributes inherited from Base

#response

Instance Method Summary collapse

Methods inherited from VcloudDirectorParser

#extract_attributes

Methods inherited from Base

#attr_value, #characters, #end_element_namespace, #initialize, #start_element_namespace, #value

Constructor Details

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

Instance Method Details

#resetObject



8
9
10
# File 'lib/fog/vcloud_director/parsers/compute/vms_by_metadata.rb', line 8

def reset
  @response = { :vm_records => [] }
end

#start_element(name, attributes) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/vcloud_director/parsers/compute/vms_by_metadata.rb', line 12

def start_element(name, attributes)
  super
  case name
  when 'QueryResultRecords'
    results = extract_attributes(attributes)
    @response[:type] = results[:type]
    @response[:href] = results[:href]
    @response[:total] = results[:total].to_i
    # href "https://devlab.mdsol.com/api/vms/query?page=1&pageSize=25&format=records&filter=metadata:unoo==STRING:janderr&fields=name,containerName"
    key = @response[:href].scan(/filter=metadata:(.*)==STRING/).flatten.first
    value = @response[:href].scan(/STRING:(.*)&?/).flatten.first
    @response[:id] = "#{key}:#{value}"
  when 'VMRecord'
    results = extract_attributes(attributes)
    results[:id] = results[:href].split('/').last
    results[:vapp_name] = results.delete(:containerName)
    results[:vapp_id] = results.delete(:container).split('/').last
    results[:cpu] = results.delete(:numberOfCpus)
    results[:memory] = results.delete(:memoryMB)
    results[:type] = "application/vnd.vmware.vcloud.vm+xml"
    @response[:vm_records] << results
  end
end