Class: Pec::Network::PortState
Instance Attribute Summary collapse
-
#device_name ⇒ Object
readonly
Returns the value of attribute device_name.
Instance Method Summary collapse
- #exists? ⇒ Boolean
- #id ⇒ Object
-
#initialize(device_name, port) ⇒ PortState
constructor
A new instance of PortState.
- #ip_address ⇒ Object
- #mac_address ⇒ Object
- #netmask(cidr) ⇒ Object
- #network_id ⇒ Object
- #used? ⇒ Boolean
Constructor Details
#initialize(device_name, port) ⇒ PortState
Returns a new instance of PortState.
6 7 8 9 |
# File 'lib/pec/network/port_state.rb', line 6 def initialize(device_name, port) @device_name = device_name @port = port end |
Instance Attribute Details
#device_name ⇒ Object (readonly)
Returns the value of attribute device_name.
5 6 7 |
# File 'lib/pec/network/port_state.rb', line 5 def device_name @device_name end |
Instance Method Details
#exists? ⇒ Boolean
11 12 13 |
# File 'lib/pec/network/port_state.rb', line 11 def exists? !@port.nil? end |
#id ⇒ Object
19 20 21 |
# File 'lib/pec/network/port_state.rb', line 19 def id @port["id"] end |
#ip_address ⇒ Object
27 28 29 |
# File 'lib/pec/network/port_state.rb', line 27 def ip_address @port["fixed_ips"][0]["ip_address"] end |
#mac_address ⇒ Object
23 24 25 |
# File 'lib/pec/network/port_state.rb', line 23 def mac_address @port["mac_address"] end |
#netmask(cidr) ⇒ Object
35 36 37 |
# File 'lib/pec/network/port_state.rb', line 35 def netmask(cidr) IP.new("#{@port["fixed_ips"][0]["ip_address"]}/#{cidr}").netmask.to_s end |
#network_id ⇒ Object
31 32 33 |
# File 'lib/pec/network/port_state.rb', line 31 def network_id @port["network_id"] end |
#used? ⇒ Boolean
15 16 17 |
# File 'lib/pec/network/port_state.rb', line 15 def used? @port && !@port["device_owner"].empty? end |