Class: VpsAdminOS::Converter::NetInterface::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vpsadminos-converter/net_interface/base.rb

Direct Known Subclasses

Bridge, Routed

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, hwaddr = nil) ⇒ Base

Returns a new instance of Base.



18
19
20
21
22
23
# File 'lib/vpsadminos-converter/net_interface/base.rb', line 18

def initialize(name, hwaddr = nil)
  @name = name
  @hwaddr = hwaddr
  @type = self.class.type
  @ip_addresses = { 4 => [], 6 => [] }
end

Instance Attribute Details

#hwaddrObject

Returns the value of attribute hwaddr.



15
16
17
# File 'lib/vpsadminos-converter/net_interface/base.rb', line 15

def hwaddr
  @hwaddr
end

#ip_addressesObject (readonly)

Returns the value of attribute ip_addresses.



16
17
18
# File 'lib/vpsadminos-converter/net_interface/base.rb', line 16

def ip_addresses
  @ip_addresses
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/vpsadminos-converter/net_interface/base.rb', line 15

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



16
17
18
# File 'lib/vpsadminos-converter/net_interface/base.rb', line 16

def type
  @type
end

Class Method Details

.type(name = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/vpsadminos-converter/net_interface/base.rb', line 5

def self.type(name = nil)
  if name
    NetInterface.register(name, self)
    @type = name

  else
    @type
  end
end

Instance Method Details

#dumpObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/vpsadminos-converter/net_interface/base.rb', line 25

def dump
  {
    'type' => type.to_s,
    'name' => name,
    'hwaddr' => hwaddr,
    'ip_addresses' => ip_addresses.to_h do |v, ips|
      ["v#{v}", ips.map(&:to_string)]
    end
  }
end