class Tinet::Node
Constants
- TYPES
Attributes
build[R]
cmds[R]
image[R]
interfaces[R]
name[R]
type[R]
Public Class Methods
new(name, type, image, build, interfaces, cmds)
click to toggle source
@param name [String] @param type [Symbol] @param image [String, nil] @param build [String, nil] @param interfaces [Array<Tinet::Node::Interfase>] @param cmds [Array<String>]
# 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
parse(node_hash)
click to toggle source
@param node_hash [Hash] @return [Tinet::Node]
# 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