class TritonOps::Snapshot::Collector
Constants
- COMMANDS
- TARGETS
Attributes
headnode[R]
namespace[RW]
Public Class Methods
new(headnode, **options)
click to toggle source
# File lib/triton-ops/snapshot/collector.rb, line 16 def initialize(headnode, **options) @headnode = headnode @namespace = options.fetch(:namespace) { '' } self end
Public Instance Methods
array_from_json_output_of_remote_command()
click to toggle source
Most of the commands we need to execute output a JSON array.
# File lib/triton-ops/snapshot/collector.rb, line 53 def array_from_json_output_of_remote_command if instance_variable_defined? "@#{__callee__}" instance_variable_get "@#{__callee__}" else instance_variable_set( "@#{__callee__}", JSON.parse(execute_remote!(command(__callee__)))) end end
record(key, value)
click to toggle source
# File lib/triton-ops/snapshot/collector.rb, line 37 def record(key, value) snapshot = timestamp.iso8601 redis.multi do redis.set "#{namespace}/headnode/#{headnode}/snapshot/#{snapshot}/#{key}", value redis.sadd "#{namespace}/headnode/#{headnode}/snapshot/#{snapshot}", key redis.sadd "#{namespace}/headnode/#{headnode}/snapshots", snapshot redis.sadd "#{namespace}/headnodes", headnode end end
timestamp()
click to toggle source
# File lib/triton-ops/snapshot/collector.rb, line 76 def timestamp @timestamp ||= Time.at( execute_remote!(command(:timestamp)).to_i).utc end
Private Instance Methods
command(target)
click to toggle source
# File lib/triton-ops/snapshot/collector.rb, line 83 def command(target) COMMANDS.fetch target end
execute_remote!(command)
click to toggle source
# File lib/triton-ops/snapshot/collector.rb, line 87 def execute_remote!(command) %x(ssh #{headnode} -- #{command}) end
redis()
click to toggle source
# File lib/triton-ops/snapshot/collector.rb, line 91 def redis @redis ||= Redis.new end