Sha256: bcdc5ed52d20339752c0e12bc069dbb0db53e74c85a5594fce34cf8734ba3c7f

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module Oxidized
  require_relative 'fetch'
  require 'slop'
  class Fetch
    class CLI
      class CLIError < ScriptError; end
      class NothingToDo < ScriptError; end

      def run
        connect
      end

      private

      def initialize
        @args, @opts = opts_parse
        CFG.debug = true if @opts[:debug]
        @host = @args.shift
        @oxf  = nil
        raise NothingToDo, 'no host given' if not @host
      end

      def opts_parse
        slop = Slop.new(:help=>true)
        slop.banner 'Usage: oxf [options] hostname'
        slop.on 'm=', '--model',     'host model (ios, junos, etc), otherwise discovered from Oxidized source'
        slop.on 'u=', '--username',  'username to use'
        slop.on 'p=', '--password',  'password to use'
        slop.on 't=', '--timeout',   'timeout value to use'
        slop.on 'e=', '--enable',    'enable password to use'
        slop.on 'c=', '--community', 'snmp community to use for discovery'
        slop.on       '--protocols=','protocols to use, default "ssh, telnet"'
        slop.on 'v',  '--verbose',   'verbose output, e.g. show commands sent'
        slop.on 'd',  '--debug',     'turn on debugging'
        slop.on :terse, 'display clean output'
        slop.parse
        [slop.parse!, slop]
      end

      def connect
        opts = {}
        opts[:host]     = @host
        [:model, :username, :password, :timeout, :enable, :verbose, :community, :protocols].each do |key|
          opts[key] = @opts[key] if @opts[key]
        end
        @oxf = Fetch.new opts
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oxidized-fetch-0.1.0 lib/oxidized/fetch/cli.rb