Sha256: cb8f8103288db4df5a4759b0ef8028e628d0787cc68312c843dd1d508a52a438

Contents?: true

Size: 1.76 KB

Versions: 12

Compression:

Stored size: 1.76 KB

Contents

require 'puppet/application'

class Puppet::Application::Filebucket < Puppet::Application

  should_not_parse_config

  option("--bucket BUCKET","-b")
  option("--debug","-d")
  option("--local","-l")
  option("--remote","-r")
  option("--verbose","-v")

  attr :args

  def run_command
    @args = command_line.args
    command = args.shift
    return send(command) if %w{get backup restore}.include? command
    help
  end

  def get
    md5 = args.shift
    out = @client.getfile(md5)
    print out
  end

  def backup
    args.each do |file|
      unless FileTest.exists?(file)
        $stderr.puts "#{file}: no such file"
        next
      end
      unless FileTest.readable?(file)
        $stderr.puts "#{file}: cannot read file"
        next
      end
      md5 = @client.backup(file)
      puts "#{file}: #{md5}"
    end
  end

  def restore
    file = args.shift
    md5 = args.shift
    @client.restore(file, md5)
  end

  def setup
    Puppet::Log.newdestination(:console)

    @client = nil
    @server = nil

    Signal.trap(:INT) do
      $stderr.puts "Cancelling"
      exit(1)
    end

    if options[:debug]
      Puppet::Log.level = :debug
    elsif options[:verbose]
      Puppet::Log.level = :info
    end

    # Now parse the config
    Puppet.parse_config

      exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?

    require 'puppet/file_bucket/dipper'
    begin
      if options[:local] or options[:bucket]
        path = options[:bucket] || Puppet[:bucketdir]
        @client = Puppet::FileBucket::Dipper.new(:Path => path)
      else
        @client = Puppet::FileBucket::Dipper.new(:Server => Puppet[:server])
      end
    rescue => detail
      $stderr.puts detail
      puts detail.backtrace if Puppet[:trace]
      exit(1)
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
puppet-2.6.18 lib/puppet/application/filebucket.rb
puppet-2.6.17 lib/puppet/application/filebucket.rb
puppet-2.6.16 lib/puppet/application/filebucket.rb
puppet-2.6.15 lib/puppet/application/filebucket.rb
puppet-2.6.14 lib/puppet/application/filebucket.rb
puppet-2.6.13 lib/puppet/application/filebucket.rb
puppet-2.6.12 lib/puppet/application/filebucket.rb
puppet-2.6.11 lib/puppet/application/filebucket.rb
puppet-2.6.10 lib/puppet/application/filebucket.rb
puppet-2.6.9 lib/puppet/application/filebucket.rb
puppet-2.6.8 lib/puppet/application/filebucket.rb
puppet-2.6.7 lib/puppet/application/filebucket.rb