Class: HP::Cloud::NetworkHelper
- Inherits:
-
BaseHelper
- Object
- BaseHelper
- HP::Cloud::NetworkHelper
- Defined in:
- lib/hpcloud/network_helper.rb
Instance Attribute Summary collapse
-
#admin_state ⇒ Object
Returns the value of attribute admin_state.
-
#admin_state_up ⇒ Object
Returns the value of attribute admin_state_up.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#router_external ⇒ Object
Returns the value of attribute router_external.
-
#shared ⇒ Object
Returns the value of attribute shared.
-
#status ⇒ Object
Returns the value of attribute status.
-
#subnets ⇒ Object
Returns the value of attribute subnets.
-
#subnets_array ⇒ Object
Returns the value of attribute subnets_array.
-
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
Attributes inherited from BaseHelper
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(connection, foggy = nil) ⇒ NetworkHelper
constructor
A new instance of NetworkHelper.
- #save ⇒ Object
Methods inherited from BaseHelper
#is_valid?, #set_error, #to_hash
Constructor Details
#initialize(connection, foggy = nil) ⇒ NetworkHelper
Returns a new instance of NetworkHelper.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hpcloud/network_helper.rb', line 33 def initialize(connection, foggy = nil) super(connection, foggy) @shared = false @admin_state_up = true if foggy.nil? return end @id = foggy.id @name = foggy.name @tenant_id = foggy.tenant_id @status = foggy.status @shared = foggy.shared @admin_state_up = foggy.admin_state_up @admin_state = foggy.admin_state_up ? "up" : "down" @subnets_array = foggy.subnets @subnets = '' unless foggy.subnets.nil? foggy.subnets.each{ |x| @subnets = ',' unless @subnets.empty? @subnets = x.id.to_s } end @router_external = foggy.router_external end |
Instance Attribute Details
#admin_state ⇒ Object
Returns the value of attribute admin_state.
27 28 29 |
# File 'lib/hpcloud/network_helper.rb', line 27 def admin_state @admin_state end |
#admin_state_up ⇒ Object
Returns the value of attribute admin_state_up.
26 27 28 |
# File 'lib/hpcloud/network_helper.rb', line 26 def admin_state_up @admin_state_up end |
#id ⇒ Object
Returns the value of attribute id.
25 26 27 |
# File 'lib/hpcloud/network_helper.rb', line 25 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'lib/hpcloud/network_helper.rb', line 25 def name @name end |
#router_external ⇒ Object
Returns the value of attribute router_external.
26 27 28 |
# File 'lib/hpcloud/network_helper.rb', line 26 def router_external @router_external end |
#shared ⇒ Object
Returns the value of attribute shared.
26 27 28 |
# File 'lib/hpcloud/network_helper.rb', line 26 def shared @shared end |
#status ⇒ Object
Returns the value of attribute status.
25 26 27 |
# File 'lib/hpcloud/network_helper.rb', line 25 def status @status end |
#subnets ⇒ Object
Returns the value of attribute subnets.
25 26 27 |
# File 'lib/hpcloud/network_helper.rb', line 25 def subnets @subnets end |
#subnets_array ⇒ Object
Returns the value of attribute subnets_array.
25 26 27 |
# File 'lib/hpcloud/network_helper.rb', line 25 def subnets_array @subnets_array end |
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
25 26 27 |
# File 'lib/hpcloud/network_helper.rb', line 25 def tenant_id @tenant_id end |
Class Method Details
.get_keys ⇒ Object
29 30 31 |
# File 'lib/hpcloud/network_helper.rb', line 29 def self.get_keys() return [ "id", "name", "status", "shared", "admin_state", "subnets" ] end |
Instance Method Details
#destroy ⇒ Object
83 84 85 |
# File 'lib/hpcloud/network_helper.rb', line 83 def destroy @connection.network.delete_network(@id) end |
#save ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hpcloud/network_helper.rb', line 58 def save return false if is_valid? == false hsh = {:name => @name, :tenant_id => @tenant_id, :shared => @shared.to_s, :admin_state_up => @admin_state_up.to_s} if @fog.nil? response = @connection.network.create_network(hsh) if response.nil? set_error("Error creating network '#{@name}'") return false end @id = response.body["network"]["id"] @status = response.body["network"]["status"] @foggy = response.body["network"] else response = @connection.network.update_network(@id, hsh) if response.nil? set_error("Error updating network '#{@name}'") return false end end return true end |