Class: Pec::Network::PortState

Inherits:
Object
  • Object
show all
Defined in:
lib/pec/network/port_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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 ⇒ Object



35
36
37
# File 'lib/pec/network/port_state.rb', line 35

def netmask
  IP.new(@port["fixed_ips"][0]["ip_address"]).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

Returns:

  • (Boolean)


15
16
17
# File 'lib/pec/network/port_state.rb', line 15

def used?
  @port && !@port["device_owner"].empty?
end