2010-10-04 14:02:08 -07:00
require 'fog/core/collection'
2011-01-14 18:20:52 +08:00
require 'fog/compute/models/aws//address'
2010-03-16 15:46:21 -07:00
2009-08-12 22:33:35 -07:00
module Fog
module AWS
2010-09-08 14:40:02 -07:00
class Compute
2009-08-12 22:33:35 -07:00
class Addresses < Fog :: Collection
2010-10-04 15:46:12 -07:00
attribute :filters
2010-01-08 11:29:07 -08:00
attribute :server
2009-09-21 11:40:38 -07:00
2010-09-08 14:40:02 -07:00
model Fog :: AWS :: Compute :: Address
2010-11-29 19:10:20 -05:00
2010-11-29 18:44:44 -05:00
# Used to create an IP address
#
# ==== Returns
#
#>> AWS.addresses.create
# <Fog::AWS::Compute::Address
# public_ip="4.88.524.95",
# server_id=nil
# >
#
# The IP address can be retreived by running AWS.addresses.get("test"). See get method below.
#
2009-10-29 23:35:28 -07:00
2009-09-27 21:31:15 -07:00
def initialize ( attributes )
2010-11-19 13:45:45 -08:00
self . filters || = { }
2009-09-27 21:31:15 -07:00
super
end
2010-11-29 18:44:44 -05:00
# AWS.addresses.all
#
# ==== Returns
#
# Returns an array of all IP addresses
#
#>> AWS.addresses.all
# <Fog::AWS::Compute::Addresses
# filters={},
# server=nil
# [
# <Fog::AWS::Compute::Address
# public_ip="76.7.46.54",
# server_id=nil
# >,
# .......
# <Fog::AWS::Compute::Address
# public_ip="4.88.524.95",
# server_id=nil
# >
# ]
# >
#>>
2010-11-19 13:45:45 -08:00
def all ( filters = filters )
2010-10-11 13:45:26 -07:00
unless filters . is_a? ( Hash )
Formatador . display_line ( " [yellow][WARN] all with #{ filters . class } param is deprecated, use all('public-ip' => []) instead[/] [light_black]( #{ caller . first } )[/] " )
filters = { 'public-ip' = > [ * filters ] }
end
2010-11-19 13:45:45 -08:00
self . filters = filters
2010-10-04 15:46:12 -07:00
data = connection . describe_addresses ( filters ) . body
2010-03-06 20:02:10 -08:00
load (
data [ 'addressesSet' ] . map do | address |
address . reject { | key , value | value . nil? || value . empty? }
end
)
2010-01-08 11:29:07 -08:00
if server
2010-03-17 11:56:09 -07:00
self . replace ( self . select { | address | address . server_id == server . id } )
2009-10-06 18:55:39 -07:00
end
2010-03-17 12:26:42 -07:00
self
2009-08-12 22:33:35 -07:00
end
2010-11-29 18:44:44 -05:00
# Used to retreive an IP address
#
# public_ip is required to get the associated IP information.
#
# You can run the following command to get the details:
# AWS.addresses.get("76.7.46.54")
2009-09-21 11:40:38 -07:00
def get ( public_ip )
2009-10-22 20:46:15 -07:00
if public_ip
2010-10-04 15:46:12 -07:00
self . class . new ( :connection = > connection ) . all ( 'public-ip' = > public_ip ) . first
2009-10-22 20:46:15 -07:00
end
2009-09-21 11:40:38 -07:00
end
2009-10-29 23:35:28 -07:00
def new ( attributes = { } )
2010-01-08 11:29:07 -08:00
if server
super ( { :server = > server } . merge! ( attributes ) )
2009-12-05 14:53:42 -08:00
else
super ( attributes )
end
2009-09-21 11:40:38 -07:00
end
2009-08-12 22:33:35 -07:00
end
end
end
end