Class: Fog::Compute::Glesys::Ips

Inherits:
Fog::Collection show all
Defined in:
lib/fog/glesys/models/compute/ips.rb

Instance Attribute Summary

Attributes inherited from Fog::Collection

#service

Instance Method Summary collapse

Methods inherited from Fog::Collection

#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

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::Collection

Instance Method Details

#allObject



15
16
17
18
19
20
# File 'lib/fog/glesys/models/compute/ips.rb', line 15

def all
  attributes = {}
  attributes[:serverid] = serverid unless serverid.nil?
  ips  = service.ip_list_own(attributes).body['response']['iplist']
  load(ips)
end

#attach(ip, server_id = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/fog/glesys/models/compute/ips.rb', line 85

def attach(ip, server_id=nil)

  if server_id.nil?
    server_id = serverid
  end

  if server_id.nil?
    raise Fog::Errors::Error.new("You need to specify a server id")
  end

  server_id = server_id.serverid if server_id.is_a?(Fog::Compute::Glesys::Server)

  service.ip_add(
    :ipaddress => ip_from_object(ip),
    :serverid  => server_id
  )

  if server.nil?
    true
  else
    server.reload
  end
end

#attachedObject



27
28
29
# File 'lib/fog/glesys/models/compute/ips.rb', line 27

def attached
  all.select { |ip| !ip.serverid.nil? }
end

#availableObject



31
32
33
# File 'lib/fog/glesys/models/compute/ips.rb', line 31

def available
  all.select { |ip| ip.serverid.nil? }
end

#free(options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/glesys/models/compute/ips.rb', line 35

def free(options = {})
  default_options = {
    :version => 4
  }

  if !server.nil?
    default_options[:datacenter] = server.datacenter
    default_options[:platform] = server.platform
  end

  options = default_options.merge!(options)

  %w{platform datacenter version}.each do |attr|
    raise Fog::Errors::Error.new("You need to specify ':#{attr}'") if !options.has_key?(attr.to_sym)
  end

  options[:ipversion] = options[:version]
  options.delete(:version)

  service.ip_list_free(options).body["response"]["iplist"]["ipaddresses"]
end

#get(ip) ⇒ Object



22
23
24
25
# File 'lib/fog/glesys/models/compute/ips.rb', line 22

def get(ip)
  data = service.ip_details( :ipaddress => ip).body['response']['details']
  new data
end

#release(ip) ⇒ Object



79
80
81
82
83
# File 'lib/fog/glesys/models/compute/ips.rb', line 79

def release(ip)
  service.ip_release(
    :ipaddress => ip_from_object(ip)
  )
end

#remove(ip, options = {}) ⇒ Object



109
110
111
# File 'lib/fog/glesys/models/compute/ips.rb', line 109

def remove(ip, options = {})
  new service.ip_remove({:ipaddress => ip_from_object(ip)}.merge!(options)).data.body["response"]["details"]
end

#take(ip, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/glesys/models/compute/ips.rb', line 57

def take(ip, options = {})

  default_options = {
    :attach => false
  }

  options = default_options.merge!(options)

  data = service.ip_take(
    :ipaddress => ip_from_object(ip)
  ).body["response"]["details"]

  ip = new data

  if options[:attach] && serverid
    server.ips.attach ip, serverid
    ip.serverid = serverid
  end

  ip
end