Skip to content

add active support providing String#constantize #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.gem
*.rbc
.idea
.idea/*
.bundle
.config
.yardoc
Expand Down
1 change: 1 addition & 0 deletions fleetctl.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
spec.add_dependency 'hashie', '~> 2'
spec.add_dependency 'net-ssh', '= 2.9.1'
spec.add_dependency 'net-scp', '= 1.2.1'
spec.add_dependency 'activesupport'
end
38 changes: 32 additions & 6 deletions lib/fleet/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def units
@units.to_a
end

def units_once
fetch_units_once
end

# refreshes local state to match the fleet cluster
def sync
build_fleet
Expand All @@ -35,7 +39,8 @@ def [](unit_name)
# accepts one or more File objects, or an array of File objects
def start(*unit_file_or_files)
unitfiles = [*unit_file_or_files].flatten
out = unitfile_operation(:start, unitfiles)
start_command = 'start -no-block'
out = unitfile_operation(start_command, unitfiles)
clear_units
out
end
Expand All @@ -62,18 +67,18 @@ def destroy(*unit_names)
runner.exit_code == 0
end

def clear_units
@units = nil
end

private

def build_fleet
cluster.discover!
end

def fleet_host
cluster.fleet_host
end

def clear_units
@units = nil
Fleetctl.options.fleet_host || cluster.fleet_host
end

def unitfile_operation(command, files)
Expand All @@ -99,6 +104,27 @@ def fetch_units(host: fleet_host)
@units.to_a
end

#This was specific for getting the info back as a hash rather than as objects
def fetch_units_once(host: fleet_host)
Fleetctl.logger.info 'Fetching units from host: '+host.inspect
command = Fleetctl::Command.new('list-units', '-l') do |runner|
runner.run(host: host)
end
output_data = Fleetctl::TableParser.parse(command.runner.stdout_data)
parse_units_once(output_data)
end

def parse_units_once(units)
units.map do |unit|
new_unit = {}
new_unit[:name] = unit[:unit]
new_unit[:ip] = unit[:machine].split('/').last
new_unit[:active] = unit[:active]
new_unit[:sub] = unit[:sub]
new_unit
end
end

def parse_units(raw_table)
unit_hashes = Fleetctl::TableParser.parse(raw_table)
unit_hashes.each do |unit_attrs|
Expand Down
2 changes: 1 addition & 1 deletion lib/fleet/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Unit
# SUB = The low-level unit activation state, values depend on unit type.
attr_reader :controller, :name, :state, :load, :active, :sub, :desc, :machine

def initialize(controller:, name:, state:, load:, active:, sub:, desc:, machine:)
def initialize(controller: nil, name: nil, state: nil, load: nil, active: nil, sub: nil, desc: nil, machine: nil)
@controller = controller
@name = name
@state = state
Expand Down
3 changes: 2 additions & 1 deletion lib/fleetctl.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'net/ssh'
require 'net/scp'
require 'hashie'
require 'active_support/all'

require 'fleetctl/version'
require 'fleetctl/command'
Expand All @@ -21,7 +22,7 @@
module Fleetctl
class << self
extend Forwardable
def_delegators :instance, :machines, :units, :[], :sync, :start, :submit, :load, :destroy
def_delegators :instance, :machines, :units, :[], :sync, :start, :submit, :load, :destroy, :clear_units

attr_reader :options

Expand Down
2 changes: 1 addition & 1 deletion lib/fleetctl/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def defaults
end

def ssh_options
self[:ssh_options].symbolize_keys
self[:ssh_options].to_hash.symbolize_keys
end
end
end
15 changes: 10 additions & 5 deletions lib/fleetctl/remote_tempfile.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module Fleetctl
class RemoteTempfile
class << self
def open(local_file)
remote_path = File.join(Fleetctl.options.remote_temp_dir, File.basename(local_file.path))
Net::SCP.upload!(Fleetctl.options.fleet_host, Fleetctl.options.fleet_user, local_file.path, remote_path, :ssh => Fleetctl.options.ssh_options)
yield(remote_path)
Net::SSH.start(Fleetctl.options.fleet_host, Fleetctl.options.fleet_user, Fleetctl.options.ssh_options) { |ssh| ssh.exec!("rm #{remote_path}") }
def open(*local_files)
remote_paths = local_files.map do |local_file|
remote_path = File.join(Fleetctl.options.remote_temp_dir, File.basename(local_file.path))
Net::SCP.upload!(Fleetctl.options.fleet_host, Fleetctl.options.fleet_user, local_file.path, remote_path, :ssh => Fleetctl.options.ssh_options)
remote_path
end

yield(remote_paths)

Net::SSH.start(Fleetctl.options.fleet_host, Fleetctl.options.fleet_user, Fleetctl.options.ssh_options) { |ssh| ssh.exec!("rm #{remote_paths.join(' ')}") }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fleetctl/runner/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def run(*)

@exit_signal = @status.termsig
@exit_code = @status.exitstatus
Fleetctl.logger.info "EXIT CODE!: #{@exit_code.inspect}"
Fleetctl.logger.info "EXIT CODE: #{@exit_code.inspect}"
Fleetctl.logger.info "STDOUT: #{@output.inspect}"
@output = @stdout_data
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fleetctl/runner/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run(host: Fleetctl.options.fleet_host, user: Fleetctl.options.fleet_user, ss
ssh.loop
@output = @stdout_data
end
Fleetctl.logger.info "EXIT CODE!: #{exit_code.inspect}"
Fleetctl.logger.info "EXIT CODE: #{exit_code.inspect}"
Fleetctl.logger.info "STDOUT: #{@output.inspect}"
@output
rescue => e
Expand Down
2 changes: 1 addition & 1 deletion lib/fleetctl/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Fleetctl
VERSION = '0.1.4'
VERSION = '0.1.4.4'
end