Class: HP::Cloud::PortHelper
- Inherits:
-
BaseHelper
- Object
- BaseHelper
- HP::Cloud::PortHelper
- Defined in:
- lib/hpcloud/port_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.
-
#device_id ⇒ Object
Returns the value of attribute device_id.
-
#device_owner ⇒ Object
Returns the value of attribute device_owner.
-
#fixed_ips ⇒ Object
Returns the value of attribute fixed_ips.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#id ⇒ Object
Returns the value of attribute id.
-
#mac_address ⇒ Object
Returns the value of attribute mac_address.
-
#name ⇒ Object
Returns the value of attribute name.
-
#network_id ⇒ Object
Returns the value of attribute network_id.
-
#security_groups ⇒ Object
Returns the value of attribute security_groups.
-
#status ⇒ Object
Returns the value of attribute status.
-
#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) ⇒ PortHelper
constructor
A new instance of PortHelper.
- #save ⇒ Object
- #set_admin_state(value) ⇒ Object
- #set_device_id(value) ⇒ Object
- #set_device_owner(value) ⇒ Object
- #set_fixed_ips(value) ⇒ Object
- #set_mac_address(value) ⇒ Object
- #set_security_groups(value) ⇒ Object
Methods inherited from BaseHelper
#is_valid?, #set_error, #to_hash
Constructor Details
#initialize(connection, foggy = nil) ⇒ PortHelper
Returns a new instance of PortHelper.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/hpcloud/port_helper.rb', line 34 def initialize(connection, foggy = nil) super(connection, foggy) if foggy.nil? return end @id = foggy.id @name = foggy.name @tenant_id = foggy.tenant_id @network_id = foggy.network_id @fixed = foggy.fixed_ips @fixed_ips = "" if foggy.fixed_ips.kind_of? Array foggy.fixed_ips.each{ |pair| @fixed_ips += ";" unless @fixed_ips.empty? @fixed_ips += "#{pair['subnet_id']},#{pair['ip_address']}" } end @mac_address = foggy.mac_address @status = foggy.status @admin_state_up = foggy.admin_state_up @admin_state = foggy.admin_state_up ? "up" : "down" @device_id = foggy.device_id @device_owner = foggy.device_owner @groups = foggy.security_groups @security_groups = "" if foggy.security_groups.kind_of? Array @security_groups = foggy.security_groups.join(",") end end |
Instance Attribute Details
#admin_state ⇒ Object
Returns the value of attribute admin_state.
28 29 30 |
# File 'lib/hpcloud/port_helper.rb', line 28 def admin_state @admin_state end |
#admin_state_up ⇒ Object
Returns the value of attribute admin_state_up.
27 28 29 |
# File 'lib/hpcloud/port_helper.rb', line 27 def admin_state_up @admin_state_up end |
#device_id ⇒ Object
Returns the value of attribute device_id.
27 28 29 |
# File 'lib/hpcloud/port_helper.rb', line 27 def device_id @device_id end |
#device_owner ⇒ Object
Returns the value of attribute device_owner.
27 28 29 |
# File 'lib/hpcloud/port_helper.rb', line 27 def device_owner @device_owner end |
#fixed_ips ⇒ Object
Returns the value of attribute fixed_ips.
26 27 28 |
# File 'lib/hpcloud/port_helper.rb', line 26 def fixed_ips @fixed_ips end |
#groups ⇒ Object
Returns the value of attribute groups.
28 29 30 |
# File 'lib/hpcloud/port_helper.rb', line 28 def groups @groups end |
#id ⇒ Object
Returns the value of attribute id.
25 26 27 |
# File 'lib/hpcloud/port_helper.rb', line 25 def id @id end |
#mac_address ⇒ Object
Returns the value of attribute mac_address.
26 27 28 |
# File 'lib/hpcloud/port_helper.rb', line 26 def mac_address @mac_address end |
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'lib/hpcloud/port_helper.rb', line 25 def name @name end |
#network_id ⇒ Object
Returns the value of attribute network_id.
26 27 28 |
# File 'lib/hpcloud/port_helper.rb', line 26 def network_id @network_id end |
#security_groups ⇒ Object
Returns the value of attribute security_groups.
27 28 29 |
# File 'lib/hpcloud/port_helper.rb', line 27 def security_groups @security_groups end |
#status ⇒ Object
Returns the value of attribute status.
26 27 28 |
# File 'lib/hpcloud/port_helper.rb', line 26 def status @status end |
#tenant_id ⇒ Object
Returns the value of attribute tenant_id.
25 26 27 |
# File 'lib/hpcloud/port_helper.rb', line 25 def tenant_id @tenant_id end |
Class Method Details
.get_keys ⇒ Object
30 31 32 |
# File 'lib/hpcloud/port_helper.rb', line 30 def self.get_keys() return [ "id", "name", "network_id", "fixed_ips", "mac_address", "status", "admin_state", "device_id", "device_owner" ] end |
Instance Method Details
#destroy ⇒ Object
145 146 147 |
# File 'lib/hpcloud/port_helper.rb', line 145 def destroy @connection.network.delete_port(@id) end |
#save ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/hpcloud/port_helper.rb', line 114 def save return false if is_valid? == false hsh = { :name => @name, :tenant_id => @tenant_id, :network_id => @network_id, :fixed_ips => @fixed, :mac_address => @mac_address, :admin_state_up => @admin_state_up, :device_id => @device_id, :device_owner => @device_owner, :security_groups => @groups } if @fog.nil? response = @connection.network.create_port(@network_id, hsh) if response.nil? set_error("Error creating port '#{@name}'") return false end @id = response.body["port"]["id"] @foggy = response.body["port"] else response = @connection.network.update_port(@id, hsh) if response.nil? set_error("Error updating port '#{@name}'") return false end end return true end |
#set_admin_state(value) ⇒ Object
86 87 88 89 90 |
# File 'lib/hpcloud/port_helper.rb', line 86 def set_admin_state(value) return true if value.nil? @admin_state = value ? "up" : "down" @admin_state_up = value end |
#set_device_id(value) ⇒ Object
92 93 94 95 |
# File 'lib/hpcloud/port_helper.rb', line 92 def set_device_id(value) return true if value.nil? @device_id = value end |
#set_device_owner(value) ⇒ Object
97 98 99 100 |
# File 'lib/hpcloud/port_helper.rb', line 97 def set_device_owner(value) return true if value.nil? @device_owner = value end |
#set_fixed_ips(value) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/hpcloud/port_helper.rb', line 64 def set_fixed_ips(value) return true if value.nil? @fixed_ips = value begin @fixed = [] value.split(';').each{ |subnet| ray = subnet.split(',') raise Exception.new("not subnet_id,ip_address") if ray.length != 2 @fixed << { "subnet_id" => ray[0], "ip_address" => ray[1] } } rescue Exception => e set_error("Invalid fixed IPs '#{value}' must be semicolon separated list of subnet_id,ip_address", :incorrect_usage) return false end return true end |
#set_mac_address(value) ⇒ Object
81 82 83 84 |
# File 'lib/hpcloud/port_helper.rb', line 81 def set_mac_address(value) return true if value.nil? @mac_address = value end |
#set_security_groups(value) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/hpcloud/port_helper.rb', line 102 def set_security_groups(value) return true if value.nil? @groups = value begin @security_groups = value.split(',') rescue Exception => e set_error("Invalid security groups '#{value}' must be comma separated list of groups", :incorrect_usage) return false end return true end |