Permalink
Browse files

cutting out unused stuff from the gem.

  • Loading branch information...
1 parent a1f4a54 commit 294e7672b8c02851462ed37a2a56cdf986a9a971 @jdunphy jdunphy committed Oct 20, 2010
View
21 lib/ruby/lib/beehive_client.rb
@@ -3,25 +3,4 @@
end
module BeehiveClient
-
- class << self
- attr_accessor :verbose, :very_verbose, :debugging, :very_debugging
-
- def lib_dir
- @lib_dir ||= File.join(File.dirname(__FILE__), "..")
- end
-
- def templates_dir
- @templates_dir ||= File.join(File.dirname(__FILE__), "..", "templates")
- end
-
- def prefix(n=nil)
- @prefix ||= n ? n : "/opt/beehive"
- end
- def mount_base; prefix/"mnt"; end
- def repos_base; prefix/"repos"; end
- def squash_base; prefix/"squashed_fs"; end
- def tmp_base; prefix/"tmp"; end
- end
-
end
View
6 lib/ruby/lib/beehive_client/commands/base.rb
@@ -3,7 +3,6 @@ module Command
class Base
- include BeehiveClient::Connection
include BeehiveClient::Rest
attr_accessor :args, :host, :user, :keypair, :prefix
@@ -18,11 +17,6 @@ def run
def parse_args(&block)
options = {}
opts = OptionParser.new {|opts|
- opts.on('-v', '--verbose') {|v| BeehiveClient.verbose = true}
- opts.on('-e', '--very_verbose') {|v| BeehiveClient.very_verbose = true}
- opts.on('-d', '--debugging') {|v| BeehiveClient.debugging = true}
- opts.on('-r', '--very_debugging') {|v| BeehiveClient.very_debugging = true}
-
opts.on("-o host", "--host host", 'The remote host') {|u| @host = u }
opts.on("-u user", "--user user", 'Your user') {|u| @user = u }
opts.on("-p password", "--password password", 'Your password') {|u| @password = u }
View
25 lib/ruby/lib/beehive_client/core/object.rb
@@ -1,25 +0,0 @@
-class Object
- # MESSAGES
- # Debugging output helpers
- def vputs(m="")
- puts "[INFO] -- #{m}" if verbose?
- end
- def dputs(m="")
- puts "[DEBUG] -- #{m.is_a?(String) ? m : m.inspect}" if debugging?
- end
- def ddputs(m="")
- puts "[VERY DEBUG] -- #{m.is_a?(String) ? m : m.inspect}" if very_debugging?
- end
- def verbose?
- BeehiveClient.verbose ||= false
- end
- def very_verbose?
- (BeehiveClient.very_verbose ||= false)
- end
- def debugging?
- (BeehiveClient.debugging ||= false)
- end
- def very_debugging?
- (BeehiveClient.very_debugging ||= false)
- end
-end
View
101 lib/ruby/lib/beehive_client/mixins/connection.rb
@@ -1,101 +0,0 @@
-require "open3"
-
-module BeehiveClient
- module Connection
-
- attr_reader :host, :user
-
- def run(commands, o={})
- ssh(commands)
- end
-
- # Simply shell out and call ssh, simple, reliable and fewest
- # dependencies, but slow
- def ssh( commands=[], extra_ssh_ops={})
- commands = commands.compact.join(' && ') if commands.is_a?(Array)
- if commands.empty?
- #TODO: replace this with a IO.popen call with read_nonblocking to show progress, and accept input
- Kernel.system(ssh_string(extra_ssh_ops))
- else
- system_run(ssh_string(extra_ssh_ops)+"'#{commands}'")
- end
- end
-
- def ssh_string(extra_ssh_ops={})
- "ssh #{user}@#{host} #{ssh_options(extra_ssh_ops)} "
- end
-
- # Take a hash of options and join them into a string, combined
- # with default options. Default options are
- # -o StrictHostKeyChecking=no
- # -i keypair.full_filepath
- # -l user
- # {'-i'=>'keyfile, '-l' => 'fred' } would become
- # "-i keyfile -o StrictHostKeyChecking=no -i keypair.to_s -l fred"
- def ssh_options(opts={})
- o = {"-i" => keypair.full_filepath,
- "-o" =>"StrictHostKeyChecking=no"
- }.merge(opts)
- o.collect{ |k,v| "#{k} #{v}"}.join(' ')
- end
-
- def rsync( opts={} )
- raise StandardError.
- new("You must pass a :source=>uri option to rsync") unless opts[:source]
- destination_path = opts[:destination] || opts[:source]
- rsync_opts = opts[:rsync_opts] || '-va'
- cmd_string = "rsync -L -e 'ssh #{ssh_options}' #{rsync_opts} #{opts[:source]} #{user}@#{host}:#{destination_path}"
- ddputs "Running rsync with: #{cmd_string}"
- out = system_run(cmd_string)
- out
- end
-
- def scp(opts={})
- source = opts[:source]
- destination_path = opts[:destination] || opts[:source]
- raise StandardError.new("You must pass a local_file to scp") unless source
- scp_opts = opts[:scp_opts] || {}
- cmd_string = "scp #{ssh_options(scp_opts)} #{source} #{user}@#{host}:#{destination_path}"
- out = system_run(cmd_string)
- out
- end
-
- # Determine the os
- # Default to ubuntu
- # Send the determine_os.sh script to the node and run it remotely
- def determine_os
- o = ssh("/bin/sh #{@prefix}/determine_os.sh").chomp
- o.empty? ? :ubuntu : o
- end
-
- private
-
- # Execute command locally.
- # This method is mainly broken out to ease testing in the other methods
- # It opens the 3 IO outputs (stdin, stdout, stderr) and print the output out
- # as the command runs, unless the quiet option is passed in
- def system_run(cmd, o={})
- opts = {:quiet => false, :sysread => 1024}.merge(o)
- buf = ""
- ddputs("Running command: #{cmd}")
- Open3.popen3(cmd) do |stdout, stdin, stderr|
- begin
- while (chunk = stdin.readpartial(opts[:sysread]))
- buf << chunk
- unless chunk.nil? || chunk.empty?
- $stdout.write(chunk) if debugging? || verbose?
- end
- end
- err = stderr.readlines
- $stderr.write_nonblock(err)
- rescue SystemCallError => error
- $stderr.write_nonblock(stderr)
- rescue EOFError => error
- # nothing
- end
- end
- buf
- end
-
- end
-end

0 comments on commit 294e767

Please sign in to comment.