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

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

Instance Method Summary collapse

Instance Method Details

#allObject


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

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


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

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


25
26
27
# File 'lib/fog/glesys/models/compute/ips.rb', line 25

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

#availableObject


29
30
31
# File 'lib/fog/glesys/models/compute/ips.rb', line 29

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

#free(options = {}) ⇒ Object


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

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.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


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

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

#release(ip) ⇒ Object


76
77
78
79
80
# File 'lib/fog/glesys/models/compute/ips.rb', line 76

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

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


105
106
107
# File 'lib/fog/glesys/models/compute/ips.rb', line 105

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

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


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

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