Class: HP::Cloud::FloatingIpHelper
- Inherits:
-
BaseHelper
- Object
- BaseHelper
- HP::Cloud::FloatingIpHelper
- Defined in:
- lib/hpcloud/floating_ip_helper.rb
Instance Attribute Summary collapse
-
#fixed_ip ⇒ Object
Returns the value of attribute fixed_ip.
-
#floating_ip ⇒ Object
Returns the value of attribute floating_ip.
-
#id ⇒ Object
Returns the value of attribute id.
-
#network_id ⇒ Object
Returns the value of attribute network_id.
-
#port ⇒ Object
Returns the value of attribute port.
-
#router ⇒ Object
Returns the value of attribute router.
-
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
Attributes inherited from BaseHelper
Class Method Summary collapse
Instance Method Summary collapse
- #associate ⇒ Object
- #destroy ⇒ Object
- #disassociate ⇒ Object
-
#initialize(connection, foggy = nil) ⇒ FloatingIpHelper
constructor
A new instance of FloatingIpHelper.
- #ip ⇒ Object
- #save ⇒ Object
- #set_network(value) ⇒ Object
- #set_port(value) ⇒ Object
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_ip ⇒ Object
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_ip ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id.
25 26 27 |
# File 'lib/hpcloud/floating_ip_helper.rb', line 25 def id @id end |
#network_id ⇒ Object
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 |
#port ⇒ Object
Returns the value of attribute port.
26 27 28 |
# File 'lib/hpcloud/floating_ip_helper.rb', line 26 def port @port end |
#router ⇒ Object
Returns the value of attribute router.
26 27 28 |
# File 'lib/hpcloud/floating_ip_helper.rb', line 26 def router @router end |
#tenant_id ⇒ Object
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_keys ⇒ Object
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
#associate ⇒ Object
75 76 77 |
# File 'lib/hpcloud/floating_ip_helper.rb', line 75 def associate @connection.network.associate_floating_ip(@id, @port) end |
#destroy ⇒ Object
109 110 111 |
# File 'lib/hpcloud/floating_ip_helper.rb', line 109 def destroy @connection.network.delete_floating_ip(@id) end |
#disassociate ⇒ Object
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 |
#ip ⇒ Object
71 72 73 |
# File 'lib/hpcloud/floating_ip_helper.rb', line 71 def ip @floating_ip end |
#save ⇒ Object
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 |