Class: Fog::Compute::Google::TargetInstances

Inherits:
Fog::Collection
  • Object
show all
Defined in:
lib/fog/google/models/compute/target_instances.rb

Instance Method Summary collapse

Instance Method Details

#all(filters = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/google/models/compute/target_instances.rb', line 10

def all(filters={})
  if filters['zone']
    data = service.list_target_instances(filters['zone']).body['items'] || []
  else
    data = []
    service.list_aggregated_target_instances.body['items'].each_value do |zone|
      data.concat(zone['targetInstances']) if zone['targetInstances']
    end
  end
  load(data)
end

#get(identity, zone = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/google/models/compute/target_instances.rb', line 22

def get(identity, zone=nil)
  response = nil
  if zone
    response = service.get_target_instance(identity, zone).body
  else
    target_instances = service.list_aggregated_target_instances(:filter => "name eq .*#{identity}").body['items']
    target_instance = target_instances.each_value.select { |zone| zone.key?('targetInstances') }

    # It can only be 1 target_instance with the same name across all regions
    response = target_instance.first['targetInstances'].first unless target_instance.empty?
  end
  return nil if response.nil?
  new(response)
rescue Fog::Errors::NotFound
  nil
end