mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
2e0b7e545a
Done with `rubocop --auto-correct --only EmptyLineBetweenDefs,EmptyLines,EmptyLinesAroundBody`
40 lines
1.1 KiB
Ruby
Executable file
40 lines
1.1 KiB
Ruby
Executable file
require 'fog/core/collection'
|
|
require 'fog/google/models/compute/address'
|
|
|
|
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.has_key?('addresses') }
|
|
|
|
return nil if address.empty?
|
|
new(address.first['addresses'].first)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|