Class: Fog::Compute::Google::ResourceViews

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

Instance Method Summary collapse

Instance Method Details

#all(filters = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/google/models/compute/resource_views.rb', line 10

def all(filters={})
  if fliters['region'].nil? && filters['zone'].nil?
    data = []
    service.list_regions.body['items'].each do |region|
      data += service.list_region_views(region['name']).body['items'] || []
    end
    service.list_zones.body['items'].each do |zone|
      data += service.list_zone_views(zone['name']).body['items'] || []
    end
  elsif filters['zone'] 
    data = service.list_zone_views(fliters['zone']).body['items'] || []
  else 
    data = service.list_region_views(filters['region']).body['items'] || []
  end
  load(data)
end

#get(identity, region = nil, zone = nil) ⇒ 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
# File 'lib/fog/google/models/compute/resource_views.rb', line 27

def get(identity, region=nil, zone=nil)
  response = nil
  
  if region.nil? & zone.nil?
    service.list_regions.body['items'].each do |region|
      begin
        response = service.get_region_view(identity, region['name'])
        break if response.status == 200
      rescue Fog::Errors::Error
      end
    end
    service.list_zones.body['items'].each do |zone|
      begin
        response = service.get_zone_view(identity, zone['name'])
        break if response.status == 200
      rescue Fog::Errors::Error
      end
    end
  elsif region
    response = service.get_region_view(identity, region)
  else 
    response = service.get_zone_view(identity, zone)
  end

  return nil if response.nil?
  new(response.body)
end