2011-03-01 16:37:27 -05:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 20:24:45 -05:00
|
|
|
require 'fog/linode/models/compute/ip'
|
2011-03-01 16:37:27 -05:00
|
|
|
|
|
|
|
module Fog
|
2011-06-16 16:28:54 -07:00
|
|
|
module Compute
|
|
|
|
class Linode
|
2011-03-01 16:37:27 -05:00
|
|
|
class Ips < Fog::Collection
|
2011-06-16 16:28:54 -07:00
|
|
|
model Fog::Compute::Linode::Ip
|
2011-03-07 16:05:20 -05:00
|
|
|
attribute :server
|
2011-03-01 16:37:27 -05:00
|
|
|
|
2011-03-07 16:05:20 -05:00
|
|
|
def all
|
|
|
|
requires :server
|
|
|
|
load ips(server.id)
|
2011-03-01 16:37:27 -05:00
|
|
|
end
|
|
|
|
|
2011-03-07 16:05:20 -05:00
|
|
|
def get(id)
|
|
|
|
requires :server
|
|
|
|
new ips(server.id, id).first
|
2011-06-16 16:28:54 -07:00
|
|
|
rescue Fog::Compute::Linode::NotFound
|
2011-03-01 16:37:27 -05:00
|
|
|
nil
|
2011-03-07 16:05:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def new(attributes = {})
|
|
|
|
requires :server
|
|
|
|
super({ :server => server }.merge!(attributes))
|
|
|
|
end
|
2011-03-01 16:37:27 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
def ips(linode_id, id=nil)
|
|
|
|
connection.linode_ip_list(linode_id, id).body['DATA'].map { |ip| map_ip ip }
|
|
|
|
end
|
|
|
|
|
|
|
|
def map_ip(ip)
|
|
|
|
ip = ip.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
|
|
|
|
ip.merge! :id => ip[:ipaddressid], :ip => ip[:ipaddress], :public => ip[:ispublic]==1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|