Ravn::CLI::

Nodes module

Command line interface to the HEAK node database

Public Class Methods

preamble()

Common preamble for all subcommands.

   # File lib/ravn/cli/nodes.rb
15 def self::preamble
16     require 'ravn/tactical'
17     require 'ravn/tactical/model'
18     require 'ravn/tactical/node'
19 
20     unless Ravn::Tactical::Node.table_exists?
21         exit_now!( "No Tactical database; use `ravn tactical install_db` to install one." )
22     end
23 end

Public Instance Methods

display_nodes( nodes )

Display the specified nodes in a readable form.

    # File lib/ravn/cli/nodes.rb
130 def display_nodes( nodes )
131     if nodes.empty?
132         prompt.say( "No matching nodes." )
133         return
134     end
135 
136     table = TTY::Table.new( ['ID', 'Device ID', 'Callsign', 'IP', 'Mission ID', ''], [] )
137     local_device_id = Ravn.device_id
138 
139     nodes.each do |node|
140         row = [
141             node.id || '-',
142             node.device_id,
143             node.callsign,
144             node.ip || '-',
145             node.mission_chksum || '-',
146             node_status_description( node )
147         ]
148         self.log.debug "Adding row: %p" % [ row ]
149 
150         row = highlight_row( row ) if node.is_local?
151 
152         table << row
153     end
154 
155     prompt.say( headline_string "Nodes:" )
156     prompt.say( table.render(:unicode, padding: [0, 1]) )
157 end
do_discovery()

Start the Discovery service for a few seconds and return the nodes that were discovered.

    # File lib/ravn/cli/nodes.rb
114 def do_discovery
115     wait_time = Ravn::Tactical::Discovery::DISCOVERY_DATA_TIMEOUT
116 
117     prompt.say( "Starting discovery..." )
118     Ravn::Tactical::Discovery.start
119     prompt.say( "Waiting %0.2fs for discovery data..." % [wait_time] )
120     sleep( wait_time )
121     nodes = Ravn::Tactical::Discovery.nodes.values
122     prompt.say( "Shutting down discovery..." )
123     Ravn::Tactical::Discovery.stop
124 
125     return nodes
126 end
highlight_row( row )

Return a copy of row with all of the items in it highlighted.

    # File lib/ravn/cli/nodes.rb
161 def highlight_row( row )
162     return row.map do |line|
163         highlight_string( line )
164     end
165 end
node_status_description( node )

Return a human-readable status description for the specified node.

    # File lib/ravn/cli/nodes.rb
169 def node_status_description( node )
170     return 'control' if node.is_control?
171     return 'failover' if node.is_failover?
172     return ''
173 end