Class: HP::Cloud::FloatingIpHelper

Inherits:
BaseHelper show all
Defined in:
lib/hpcloud/floating_ip_helper.rb

Instance Attribute Summary collapse

Attributes inherited from BaseHelper

#connection, #cstatus, #fog

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHelper

#is_valid?, #set_error, #to_hash

Constructor Details

#initialize(connection, foggy = nil) ⇒ FloatingIpHelper

Returns a new instance of FloatingIpHelper.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hpcloud/floating_ip_helper.rb', line 33

def initialize(connection, foggy = nil)
  super(connection, foggy)
  if foggy.nil?
    return
  end
  @id = foggy.id
  @tenant_id = foggy.tenant_id
  @network_id = foggy.floating_network_id
  @port = foggy.port_id
  @router = foggy.router_id
  @fixed_ip = foggy.fixed_ip_address
  @floating_ip = foggy.floating_ip_address
end

Instance Attribute Details

#fixed_ipObject

Returns the value of attribute fixed_ip.



27
28
29
# File 'lib/hpcloud/floating_ip_helper.rb', line 27

def fixed_ip
  @fixed_ip
end

#floating_ipObject

Returns the value of attribute floating_ip.



27
28
29
# File 'lib/hpcloud/floating_ip_helper.rb', line 27

def floating_ip
  @floating_ip
end

#idObject

Returns the value of attribute id.



25
26
27
# File 'lib/hpcloud/floating_ip_helper.rb', line 25

def id
  @id
end

#network_idObject

Returns the value of attribute network_id.



26
27
28
# File 'lib/hpcloud/floating_ip_helper.rb', line 26

def network_id
  @network_id
end

#portObject

Returns the value of attribute port.



26
27
28
# File 'lib/hpcloud/floating_ip_helper.rb', line 26

def port
  @port
end

#routerObject

Returns the value of attribute router.



26
27
28
# File 'lib/hpcloud/floating_ip_helper.rb', line 26

def router
  @router
end

#tenant_idObject

Returns the value of attribute tenant_id.



25
26
27
# File 'lib/hpcloud/floating_ip_helper.rb', line 25

def tenant_id
  @tenant_id
end

Class Method Details

.get_keysObject



29
30
31
# File 'lib/hpcloud/floating_ip_helper.rb', line 29

def self.get_keys()
  return [ "id", "network_id", "port", "router", "fixed_ip", "floating_ip" ]
end

Instance Method Details

#associateObject



75
76
77
# File 'lib/hpcloud/floating_ip_helper.rb', line 75

def associate
  @connection.network.associate_floating_ip(@id, @port)
end

#destroyObject



109
110
111
# File 'lib/hpcloud/floating_ip_helper.rb', line 109

def destroy
  @connection.network.delete_floating_ip(@id)
end

#disassociateObject



79
80
81
82
# File 'lib/hpcloud/floating_ip_helper.rb', line 79

def disassociate
  return if @port.nil?
  @connection.network.disassociate_floating_ip(@id)
end

#ipObject



71
72
73
# File 'lib/hpcloud/floating_ip_helper.rb', line 71

def ip
  @floating_ip
end

#saveObject



84
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/hpcloud/floating_ip_helper.rb', line 84

def save
  return false if is_valid? == false
  hsh = {
      :tenant_id => @tenant_id,
      :floating_network_id => @network_id,
      :port_id => @port,
      :fixed_ip_address => @fixed_ip,
      :floating_ip_address => @floating_ip
    }
  if @fog.nil?
    response = @connection.network.create_floating_ip(@network_id, hsh)
    if response.nil?
      set_error("Error creating floating IP")
      return false
    end
    @id = response.body["floatingip"]["id"]
    @floating_ip = response.body["floatingip"]["floating_ip_address"]
    @foggy = response.body["floating_ip"]
  else
    set_error("Floating IP update is not supported")
    return false
  end
  return true
end

#set_network(value) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/hpcloud/floating_ip_helper.rb', line 47

def set_network(value)
  if value.nil?
    netty = Networks.new.external
    if netty.nil?
      set_error("Cannot find an external network")
      return false
    end
  else
    netty = Networks.new.get(value)
  end
  unless netty.is_valid?
    set_error netty.cstatus
  end
  @network_id = netty.id
end

#set_port(value) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/hpcloud/floating_ip_helper.rb', line 63

def set_port(value)
  porty = Ports.new.get(value)
  unless porty.is_valid?
    set_error porty.cstatus
  end
  @port = porty.id
end