Class: NetworkManager::Ip4Config
- Inherits:
-
Object
- Object
- NetworkManager::Ip4Config
- Defined in:
- lib/network_manager/ip4_config.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#gateway ⇒ Object
Returns the value of attribute gateway.
Class Method Summary collapse
- .from_dot_notation(address, subnet = '255.255.255.0', gateway = '0.0.0.0') ⇒ Object
- .from_nm_au(address_u32, prefix = 0, gateway_u32 = 0) ⇒ Object
- .revert_octects(ipv4) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
2 3 4 |
# File 'lib/network_manager/ip4_config.rb', line 2 def address @address end |
#gateway ⇒ Object
Returns the value of attribute gateway.
2 3 4 |
# File 'lib/network_manager/ip4_config.rb', line 2 def gateway @gateway end |
Class Method Details
.from_dot_notation(address, subnet = '255.255.255.0', gateway = '0.0.0.0') ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/network_manager/ip4_config.rb', line 4 def self.from_dot_notation(address, subnet = '255.255.255.0', gateway = '0.0.0.0') obj = self.new obj.address = IPAddress::IPv4.new(address) obj.address.netmask = subnet obj.gateway = IPAddress::IPv4.new(gateway) obj.gateway.netmask = subnet obj end |
.from_nm_au(address_u32, prefix = 0, gateway_u32 = 0) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/network_manager/ip4_config.rb', line 13 def self.from_nm_au(address_u32, prefix = 0, gateway_u32 = 0) obj = self.new obj.address = revert_octects(IPAddress::IPv4.parse_u32(address_u32)) obj.address.prefix = prefix obj.gateway = revert_octects(IPAddress::IPv4.parse_u32(gateway_u32)) obj.gateway.prefix = prefix obj end |
.revert_octects(ipv4) ⇒ Object
26 27 28 |
# File 'lib/network_manager/ip4_config.rb', line 26 def self.revert_octects(ipv4) IPAddress::IPv4.new(ipv4.octets.reverse.join('.')) end |
Instance Method Details
#revert_octects(ipv4) ⇒ Object
30 31 32 |
# File 'lib/network_manager/ip4_config.rb', line 30 def revert_octects(ipv4) self.class.revert_octects(ipv4) end |
#to_nm_au ⇒ Object
22 23 24 |
# File 'lib/network_manager/ip4_config.rb', line 22 def to_nm_au [revert_octects(address).to_i, address.prefix.to_i, revert_octects(gateway).to_i] end |