Class: Tinet::Node
- Inherits:
-
Object
- Object
- Tinet::Node
- Defined in:
- lib/tinet/node.rb
Defined Under Namespace
Classes: Interfase
Constant Summary collapse
- TYPES =
%w(docker netns).freeze
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#cmds ⇒ Object
readonly
Returns the value of attribute cmds.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#interfaces ⇒ Object
readonly
Returns the value of attribute interfaces.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, type, image, build, interfaces, cmds) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(name, type, image, build, interfaces, cmds) ⇒ Node
Returns a new instance of Node.
26 27 28 29 30 31 32 33 34 |
# File 'lib/tinet/node.rb', line 26 def initialize(name, type, image, build, interfaces, cmds) @name = name @type = type @image = image @build = build @interfaces = interfaces @cmds = cmds interfaces.each { |interface| interface.node = self } end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
18 19 20 |
# File 'lib/tinet/node.rb', line 18 def build @build end |
#cmds ⇒ Object (readonly)
Returns the value of attribute cmds.
18 19 20 |
# File 'lib/tinet/node.rb', line 18 def cmds @cmds end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
18 19 20 |
# File 'lib/tinet/node.rb', line 18 def image @image end |
#interfaces ⇒ Object (readonly)
Returns the value of attribute interfaces.
18 19 20 |
# File 'lib/tinet/node.rb', line 18 def interfaces @interfaces end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/tinet/node.rb', line 18 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
18 19 20 |
# File 'lib/tinet/node.rb', line 18 def type @type end |
Class Method Details
.parse(node_hash) ⇒ Tinet::Node
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/tinet/node.rb', line 7 def self.parse(node_hash) name, type, interfaces = node_hash['name'], node_hash['type'], node_hash['interfaces'] raise InvalidYAMLError, "Node name is missing" if name.nil? || name.empty? raise InvalidTypeError, "Unknown node type: #{type}" unless TYPES.include?(type) raise InvalidYAMLError, "Node interfaces must be array" unless interfaces.is_a?(Array) interfaces = interfaces.map { |interface| Interfase.parse(interface) } cmds = node_hash.fetch('cmds', []).map { |cmd| cmd['cmd'] || cmd } self.new(name, type.to_sym, node_hash['image'], node_hash['build'], interfaces, cmds) end |