Sha256: 9baf2192744599bfc2d689bc528969126d6207da34a1d71d5c5a77daa6469b9d

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 KB

Contents

module Fog
  module Compute
    class Google
      class Addresses < Fog::Collection
        model Fog::Compute::Google::Address

        def all(filters = {})
          if filters[:region]
            data = service.list_addresses(filters[:region]).body["items"] || []
          else
            data = []
            service.list_aggregated_addresses.body["items"].each_value do |region|
              data.concat(region["addresses"]) if region["addresses"]
            end
          end
          load(data)
        end

        def get(identity, region)
          if address = service.get_address(identity, region).body
            new(address)
          end
        rescue Fog::Errors::NotFound
          nil
        end

        def get_by_ip_address(ip_address)
          addresses = service.list_aggregated_addresses(:filter => "address eq .*#{ip_address}").body["items"]
          address = addresses.each_value.select { |region| region.key?("addresses") }

          return nil if address.empty?
          new(address.first["addresses"].first)
        end

        def get_by_name(ip_name)
          names = service.list_aggregated_addresses(:filter => "name eq .*#{ip_name}").body["items"]
          name = names.each_value.select { |region| region.key?("addresses") }

          return nil if name.empty?
          new(name.first["addresses"].first)
        end

        def get_by_ip_address_or_name(ip_address_or_name)
          get_by_ip_address(ip_address_or_name) || get_by_name(ip_address_or_name)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fog-google-0.6.0 lib/fog/compute/google/models/addresses.rb
fog-google-0.5.5 lib/fog/compute/google/models/addresses.rb
fog-google-0.5.4 lib/fog/compute/google/models/addresses.rb
fog-google-0.5.3 lib/fog/compute/google/models/addresses.rb
fog-google-0.5.2 lib/fog/compute/google/models/addresses.rb
fog-google-0.5.1 lib/fog/compute/google/models/addresses.rb
fog-google-0.5.0 lib/fog/compute/google/models/addresses.rb
fog-google-0.4.2 lib/fog/compute/google/models/addresses.rb
fog-google-0.4.1 lib/fog/compute/google/models/addresses.rb
fog-google-0.4.0 lib/fog/compute/google/models/addresses.rb
fog-google-0.3.2 lib/fog/compute/google/models/addresses.rb
fog-google-0.3.1 lib/fog/compute/google/models/addresses.rb
fog-google-0.3.0 lib/fog/compute/google/models/addresses.rb
fog-google-0.2.0 lib/fog/compute/google/models/addresses.rb