Class: Fog::Compute::Glesys::Ip

Inherits:
Model
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/fog/glesys/models/compute/ip.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods included from Deprecation

deprecate, self_deprecate

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#attach(server) ⇒ Object

Add an ip-adress to the server.

Raises:



40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/glesys/models/compute/ip.rb', line 40

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
end

#attached?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/fog/glesys/models/compute/ip.rb', line 26

def attached?
  !serverid.nil?
end

#destroyObject

Remove the ip from a server and release it



60
61
62
63
# File 'lib/fog/glesys/models/compute/ip.rb', line 60

def destroy
  requires :ip
  remove(:release => true)
end

#releaseObject

Return an unused ip-address to the pool of free ips.

Raises:



31
32
33
34
35
36
37
# File 'lib/fog/glesys/models/compute/ip.rb', line 31

def release
  requires :ip
  raise Fog::Errors::Error.new('You can\'t release a ip that is attached to a server') if attached?
  service.ip_release(
    :ipaddress => identity
  )
end

#remove(options = {}) ⇒ Object

Remove an ip from the server

Raises:



52
53
54
55
56
57
# File 'lib/fog/glesys/models/compute/ip.rb', line 52

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

#takeObject



65
66
67
68
69
70
71
# File 'lib/fog/glesys/models/compute/ip.rb', line 65

def take
  requires :ip
  data = service.ip_take(
    :ipaddress => ip
  ).body["response"]["details"]
  merge_attributes data
end