2011-08-10 09:03:51 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
2013-02-01 08:36:57 -05:00
|
|
|
module Compute
|
|
|
|
class Glesys
|
2011-08-10 09:03:51 -04:00
|
|
|
|
|
|
|
class Ip < Fog::Model
|
2013-02-01 08:36:57 -05:00
|
|
|
|
2011-08-10 09:03:51 -04:00
|
|
|
extend Fog::Deprecation
|
|
|
|
|
2013-02-01 08:41:45 -05:00
|
|
|
identity :ip
|
2011-08-10 09:03:51 -04:00
|
|
|
|
2013-02-01 08:41:45 -05:00
|
|
|
attribute :ip, :aliases => "ipaddress"
|
2011-08-10 09:03:51 -04:00
|
|
|
attribute :datacenter
|
2013-02-01 08:41:45 -05:00
|
|
|
attribute :version, :aliases => "ipversion"
|
2011-08-10 09:03:51 -04:00
|
|
|
attribute :platform
|
2013-02-01 08:41:45 -05:00
|
|
|
attribute :netmask
|
|
|
|
attribute :broadcast
|
|
|
|
attribute :gateway
|
|
|
|
attribute :nameservers
|
|
|
|
attribute :serverid
|
|
|
|
attribute :reserved
|
|
|
|
attribute :ptr
|
|
|
|
attribute :cost
|
2011-08-10 09:03:51 -04:00
|
|
|
|
2013-02-01 14:36:44 -05:00
|
|
|
def attached?
|
|
|
|
!serverid.nil?
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
|
2013-02-01 14:36:44 -05:00
|
|
|
# Return an unused ip-address to the pool of free ips.
|
2011-08-10 09:03:51 -04:00
|
|
|
def release
|
2013-02-01 14:36:44 -05:00
|
|
|
requires :ip
|
|
|
|
raise Fog::Errors::Error.new('You can\'t release a ip that is attached to a server') if attached?
|
2012-12-22 18:27:08 -05:00
|
|
|
service.ip_release(
|
2013-02-01 14:36:44 -05:00
|
|
|
:ipaddress => identity
|
2011-08-10 09:03:51 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2013-02-01 14:36:44 -05:00
|
|
|
# Add an ip-adress to the server.
|
|
|
|
def attach(server)
|
|
|
|
requires :ip
|
|
|
|
server = server.serverid if server.is_a?(Fog::Compute::Glesys::Server)
|
|
|
|
raise Fog::Errors::Error.new("Ip is already attached to a server, #{serverid}") unless serverid.nil?
|
|
|
|
data = service.ip_add(
|
|
|
|
:ipaddress => identity,
|
|
|
|
:serverid => server
|
|
|
|
).body["response"]["details"]
|
|
|
|
merge_attributes data
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
|
2013-02-01 14:36:44 -05:00
|
|
|
# Remove an ip from the server
|
|
|
|
def remove(options = {})
|
|
|
|
requires :ip
|
|
|
|
raise Fog::Errors::Error.new('Ip is not attached to a server.') if serverid.nil?
|
|
|
|
data = service.ip_remove({:ipaddress => ip}.merge!(options)).body["response"]["details"]
|
|
|
|
merge_attributes data
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove the ip from a server and release it
|
|
|
|
def destroy
|
|
|
|
requires :ip
|
|
|
|
remove(:release => true)
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:44:45 -05:00
|
|
|
def take
|
|
|
|
requires :ip
|
|
|
|
data = service.ip_take(
|
|
|
|
:ipaddress => ip
|
|
|
|
).body["response"]["details"]
|
|
|
|
merge_attributes data
|
|
|
|
end
|
|
|
|
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|