Ravn::Tactical::ServiceInfra::

Kit module

:nocov:

Public Class Methods

included( app )

Add nodes-related routes to the given app.

   # File lib/ravn/tactical/service_infra/kit.rb
20 def self::included( app )
21     super
22 
23     self.log.info "Mounting kit endpoints."
24     self.mount( app )
25 end
mount( app )

Mount kit endpoints in the given app.

   # File lib/ravn/tactical/service_infra/kit.rb
29 def self::mount( app )
30     app.hash_branch( :infra, 'kit' ) do |r|
31 
32         # GET /api/infra/kit/control
33         # PUT /api/infra/kit/control
34         r.on( 'control' ) do
35             r.get { self.get_control_node }
36             r.put { self.set_control_node }
37         end
38 
39     end
40 end

Public Instance Methods

get_control_node()

Fetch this node’s current Control.

   # File lib/ravn/tactical/service_infra/kit.rb
48 def get_control_node
49     node = Ravn::Tactical.control_node or return nil
50     return present( node )
51 end
set_control_node()

Make this node a control node.

   # File lib/ravn/tactical/service_infra/kit.rb
55 def set_control_node
56     self.log.debug "Request is: %p" % [ request ]
57 
58     if (node = Ravn::Tactical.control_node)
59         request.halt( 409, "This node is already controlled by %s" % [ node.device_id ] )
60     end
61 
62     device_id = typecast_params.device_id!( 'device_id' )
63     node = Ravn::Tactical::Discovery.nodes[ device_id ] or
64         return bad_request( request, "Unknown device %p." % [device_id] )
65 
66     self.log.info "Attempting to set this node's control to: %s" % [ device_id ]
67     Ravn::Tactical.set_control_node( node )
68 
69     return present( node )
70 end