Class: Tinet::Switch::Interfase

Inherits:
Object
  • Object
show all
Defined in:
lib/tinet/switch.rb

Constant Summary collapse

TYPES =
%w(docker netns phys).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, args) ⇒ Interfase

Returns a new instance of Interfase.

Parameters:

  • name (String)
  • type (Symbol)
  • args (String, nil)


41
42
43
44
45
46
# File 'lib/tinet/switch.rb', line 41

def initialize(name, type, args)
  @name = name
  @type = type.to_sym
  @args = args
  @switch = nil
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



36
37
38
# File 'lib/tinet/switch.rb', line 36

def args
  @args
end

#nameObject (readonly)

Returns the value of attribute name.



36
37
38
# File 'lib/tinet/switch.rb', line 36

def name
  @name
end

#switchObject

Returns the value of attribute switch.



36
37
38
# File 'lib/tinet/switch.rb', line 36

def switch
  @switch
end

#typeObject (readonly)

Returns the value of attribute type.



36
37
38
# File 'lib/tinet/switch.rb', line 36

def type
  @type
end

Class Method Details

.parse(interface_hash) ⇒ Tinet::Switch::Interfase

Parameters:

  • interface_hash (Hash)

Returns:

Raises:



29
30
31
32
33
34
# File 'lib/tinet/switch.rb', line 29

def self.parse(interface_hash)
  name, type, args = interface_hash['name'], interface_hash['type'], interface_hash['args']
  raise InvalidYAMLError, "Interfase name is missing" if name.nil? || name.empty?
  raise InvalidTypeError, "Unknown interface type: #{type}" unless TYPES.include?(type)
  self.new(name, type.to_sym, args)
end