Class: Pvectl::Models::NetworkInterface
- Defined in:
- lib/pvectl/models/network_interface.rb
Overview
Represents a network interface on a Proxmox node.
Immutable domain model containing network interface attributes and helper methods for display. Created by Repositories::Node from API data.
Instance Attribute Summary collapse
-
#active ⇒ Integer
readonly
Active flag (0/1).
-
#address ⇒ String?
readonly
IP address with CIDR (e.g., “192.168.1.10/24”).
-
#autostart ⇒ Integer
readonly
Autostart flag (0/1).
-
#bridge_ports ⇒ String?
readonly
Bridge ports (for bridge type).
-
#comments ⇒ String?
readonly
Comments.
-
#gateway ⇒ String?
readonly
Gateway IP address.
-
#iface ⇒ String
readonly
Interface name (e.g., “vmbr0”, “eth0”).
-
#type ⇒ String
readonly
Interface type (bridge, bond, eth, vlan).
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks if the interface is active.
-
#has_gateway? ⇒ Boolean
Checks if the interface has a gateway configured.
-
#initialize(attrs = {}) ⇒ NetworkInterface
constructor
Creates a new NetworkInterface model from attributes.
-
#ip_without_cidr ⇒ String?
Returns IP address without CIDR suffix.
Constructor Details
#initialize(attrs = {}) ⇒ NetworkInterface
Creates a new NetworkInterface model from attributes.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pvectl/models/network_interface.rb', line 48 def initialize(attrs = {}) super @iface = attributes[:iface] @type = attributes[:type] @address = attributes[:address] @gateway = attributes[:gateway] @active = attributes[:active] @autostart = attributes[:autostart] @bridge_ports = attributes[:bridge_ports] @comments = attributes[:comments] end |
Instance Attribute Details
#active ⇒ Integer (readonly)
Returns active flag (0/1).
34 35 36 |
# File 'lib/pvectl/models/network_interface.rb', line 34 def active @active end |
#address ⇒ String? (readonly)
Returns IP address with CIDR (e.g., “192.168.1.10/24”).
28 29 30 |
# File 'lib/pvectl/models/network_interface.rb', line 28 def address @address end |
#autostart ⇒ Integer (readonly)
Returns autostart flag (0/1).
37 38 39 |
# File 'lib/pvectl/models/network_interface.rb', line 37 def autostart @autostart end |
#bridge_ports ⇒ String? (readonly)
Returns bridge ports (for bridge type).
40 41 42 |
# File 'lib/pvectl/models/network_interface.rb', line 40 def bridge_ports @bridge_ports end |
#comments ⇒ String? (readonly)
Returns comments.
43 44 45 |
# File 'lib/pvectl/models/network_interface.rb', line 43 def comments @comments end |
#gateway ⇒ String? (readonly)
Returns gateway IP address.
31 32 33 |
# File 'lib/pvectl/models/network_interface.rb', line 31 def gateway @gateway end |
#iface ⇒ String (readonly)
Returns interface name (e.g., “vmbr0”, “eth0”).
22 23 24 |
# File 'lib/pvectl/models/network_interface.rb', line 22 def iface @iface end |
#type ⇒ String (readonly)
Returns interface type (bridge, bond, eth, vlan).
25 26 27 |
# File 'lib/pvectl/models/network_interface.rb', line 25 def type @type end |
Instance Method Details
#active? ⇒ Boolean
Checks if the interface is active.
63 64 65 |
# File 'lib/pvectl/models/network_interface.rb', line 63 def active? active == 1 end |
#has_gateway? ⇒ Boolean
Checks if the interface has a gateway configured.
70 71 72 |
# File 'lib/pvectl/models/network_interface.rb', line 70 def has_gateway? !gateway.nil? && !gateway.to_s.empty? end |
#ip_without_cidr ⇒ String?
Returns IP address without CIDR suffix.
80 81 82 |
# File 'lib/pvectl/models/network_interface.rb', line 80 def ip_without_cidr address&.split("/")&.first end |