Class: Tinet::Node::Interfase

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

Constant Summary collapse

TYPES =
%w(direct bridge veth 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)


53
54
55
56
57
58
# File 'lib/tinet/node.rb', line 53

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



48
49
50
# File 'lib/tinet/node.rb', line 48

def args
  @args
end

#nameObject (readonly)

Returns the value of attribute name.



48
49
50
# File 'lib/tinet/node.rb', line 48

def name
  @name
end

#nodeObject

Returns the value of attribute node.



48
49
50
# File 'lib/tinet/node.rb', line 48

def node
  @node
end

#typeObject (readonly)

Returns the value of attribute type.



48
49
50
# File 'lib/tinet/node.rb', line 48

def type
  @type
end

Class Method Details

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

Parameters:

  • interface_hash (Hash)

Returns:

Raises:



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

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