Ravn::Tactical::

Operation class

A Command-pattern class for the Ravn-Tactical change (task) queue

Attributes

config R

The configuration of the Operation to be run, as a Symbol Hash.

Public Class Methods

from_change( change )

Create an Operation for the specified change.

   # File lib/ravn/tactical/operation.rb
76 def self::from_change( change )
77     return self.create( change.type, **change.config )
78 end
inherited( subclass )

Inheritance hook – enable the constructor for subclasses.

   # File lib/ravn/tactical/operation.rb
31 def self::inherited( subclass )
32     super
33 
34     subclass.public_class_method( :new )
35 end
new( **config )

Create a new Operation targeting the specified node and using the given config.

   # File lib/ravn/tactical/operation.rb
83 def initialize( **config )
84     @config = config
85 end
param_validator()

Return a block for Roda::RodaPlugins::TypecastParams validation for this operation. Defaults to an empty block (no valid config parameters)

   # File lib/ravn/tactical/operation.rb
70 def self::param_validator
71     return Proc.new {|*| }
72 end
valid_type?( name )

Returns true if there is an Operation with the given name.

   # File lib/ravn/tactical/operation.rb
39 def self::valid_type?( name )
40     return self.valid_types.include?( name )
41 end
valid_type_pattern()

Return a Regexp made up of a union of all valid operation types.

   # File lib/ravn/tactical/operation.rb
61 def self::valid_type_pattern
62     pattern = Regexp.union( self.valid_types )
63     self.log.info "Valid type pattern is: %p" % [ pattern ]
64     return pattern.freeze
65 end
valid_types()

Return an Array of all valid operation types.

   # File lib/ravn/tactical/operation.rb
45 def self::valid_types
46     return @valid_types ||= begin
47         self.load_all.map do |op_class|
48             if op_class.name && (op_name = op_class.name[ /::(\w+)\z/, 1 ])
49                 self.log.debug "adding valid operation type %p (%s)" % [ op_class, op_name ]
50                 op_name.un_camelcase
51             else
52                 self.log.warn "can't derive operation name for %p" % [ op_class ]
53                 nil
54             end
55         end.compact
56     end
57 end

Public Instance Methods

after_run( node, response )

Do any teardown on the Control after the Operation is run. It is passed the node (the Ravn::Tactical::Node it was run on), and a response (a HTTPX::Response) of the service call. If this method returns a falsey value, the Change’s transaction is aborted.

    # File lib/ravn/tactical/operation.rb
123 def after_run( node, response )
124     return response
125 end
before_run( node )

Do any preparation on the Control before the Operation is run on the specified node. If this method returns a falsey value, abort the Change. Returns true by default.

    # File lib/ravn/tactical/operation.rb
107 def before_run( node )
108     return true
109 end
inspect_details()

Ravn::Inspection API – Return the details portion of the inspect output.

    # File lib/ravn/tactical/operation.rb
129 def inspect_details
130     return "type: %s, config: %s" % [ self.type, self.config.keys.join(', ') ]
131 end
run( * )

Run the operation, returning a truthy value if successful.

    # File lib/ravn/tactical/operation.rb
113 def run( * )
114     raise NotImplementedError, "%p does not implement required method %s" %
115         [ self.class, __method__ ]
116 end
type()

Return the type of the Operation.

    # File lib/ravn/tactical/operation.rb
 98 def type
 99     classname = self.class.name or return nil
100     return classname[ /.*::(\w+)\b/, 1 ].un_camelcase.to_sym
101 end