class Wire::Resource::FigAdapter
Fig Adapter resource, runs fig script to control containers
Attributes
executables[RW]
executables
[Hash] of binaries needed to control the resource
figfile[RW]
executables
[Hash] of binaries needed to control the resource
Public Class Methods
new(name, figfile)
click to toggle source
initialize the object with given name
and path to fig file params:
-
name fig filename name, i.e. “backend.yaml”
Calls superclass method
# File lib/wire/resource/fig_adapter.rb, line 24 def initialize(name, figfile) super(name.tr('_-', '')) @figfile = figfile # TODO: make configurable @executables = { :fig => '/usr/local/bin/fig' } end
Public Instance Methods
down()
click to toggle source
takes containers down
# File lib/wire/resource/fig_adapter.rb, line 105 def down $log.debug 'Taking down fig containers ...' with_fig(['stop']) do |exec_obj| exec_obj.run return false if (exec_obj.exitstatus != 0) end $log.debug 'Removing fig containers ...' with_fig(%w(rm --force)) do |exec_obj| exec_obj.run return false if (exec_obj.exitstatus != 0) end true end
down?()
click to toggle source
checks if the bridge is down
# File lib/wire/resource/fig_adapter.rb, line 100 def down? !(up?) end
exist?()
click to toggle source
checks if containers exist
# File lib/wire/resource/fig_adapter.rb, line 35 def exist? up? end
to_s()
click to toggle source
Returns a string representation
# File lib/wire/resource/fig_adapter.rb, line 122 def to_s "FigAdapter:[#{name},file=#{figfile}]" end
up()
click to toggle source
brings containers up
# File lib/wire/resource/fig_adapter.rb, line 90 def up $log.debug 'Bringing up fig containers ...' with_fig(%w(up -d --no-recreate)) do |exec_obj| exec_obj.run return (exec_obj.exitstatus == 0) end end
up?()
click to toggle source
checks if containers are up (using fig ps)
# File lib/wire/resource/fig_adapter.rb, line 49 def up? with_fig(%w(ps)) do |exec_obj| exec_obj.run # parse stdout.. re = Regexp.new "^#{@name}.*Up.*" num_up = 0 exec_obj.stdout.split("\n").each do |line| next unless line.match(re) $log.debug "Matching fig ps output: #{line}" num_up += 1 end $log.debug 'No containers found in fig ps output' if num_up == 0 return (exec_obj.exitstatus == 0 && num_up > 0) end end
up_ids()
click to toggle source
returns the container ids of currently running containers as [Array] of ids
# File lib/wire/resource/fig_adapter.rb, line 71 def up_ids with_fig(%w(ps -q)) do |exec_obj| exec_obj.run # parse stdout.. re = Regexp.new '^[0-9a-zA-Z]+' res = [] exec_obj.stdout.split("\n").each do |line| next unless line.match(re) res << line.chomp.strip end return res end nil end
with_fig(command_arr) { |exec_obj| ... }
click to toggle source
calls fig with correct -p and -f options and given command_arr
array
# File lib/wire/resource/fig_adapter.rb, line 41 def with_fig(command_arr) LocalExecution.with(@executables[:fig], ['-p', @name, '-f', @figfile, command_arr].flatten) do |exec_obj| yield exec_obj end end