Class: IPVSLitmus::CLI::Admin
- Inherits:
-
Object
- Object
- IPVSLitmus::CLI::Admin
- Defined in:
- lib/ipvs_litmus/cli/admin.rb
Instance Method Summary collapse
- #_default_options ⇒ Object
- #_extend_default_parser(options, &block) ⇒ Object
- #_litmus_request(host, port, request) ⇒ Object
- #force(args) ⇒ Object
- #run(argv = ARGV) ⇒ Object
- #status(args) ⇒ Object
Instance Method Details
#_default_options ⇒ Object
50 51 52 |
# File 'lib/ipvs_litmus/cli/admin.rb', line 50 def = { :port => 9292, :host => 'localhost' } end |
#_extend_default_parser(options, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ipvs_litmus/cli/admin.rb', line 54 def _extend_default_parser(, &block) OptionParser.new do |opts| block.call(opts) opts.on("-p", "--port=port", Integer, "Port litmus is running on", "Default: 9292") do |port| [:port] = port end opts.on("-h", "--host=ip", String, ":Host litmus is running on", "Default: localhost") do |host| [:host] = host end opts.on("--help", "Show this help message.") { puts opts; exit } end end |
#_litmus_request(host, port, request) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ipvs_litmus/cli/admin.rb', line 68 def _litmus_request(host, port, request) begin http = Net::HTTP.start(host, port) response = http.request(request) puts response.body case response when Net::HTTPSuccess then exit 0 when Net::HTTPClientError then exit 2 else exit 1 end rescue Errno::ECONNREFUSED => e puts "Unable to connect to litmus on #{host}:#{port}: #{e.}" exit 1 end end |
#force(args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ipvs_litmus/cli/admin.rb', line 9 def force(args) = opt_parser = _extend_default_parser() do |opts| opts. = "Usage: litmusctl force <up|down> [service] [options]" opts.on("-d", "--delete", "Remove status file") do [:delete] = true end opts.on("-r", "--reason=reason", String, "Reason for status file") do |reason| [:reason] = reason end end opt_parser.parse! args direction, service = args if [:delete] request = Net::HTTP::Delete.new("/force/#{direction}/#{service}") else if !.has_key?(:reason) print "Reason? " [:reason] = gets.chomp end request = Net::HTTP::Post.new("/force/#{direction}/#{service}") request.set_form_data('reason' => [:reason]) end _litmus_request([:host], [:port], request) end |
#run(argv = ARGV) ⇒ Object
4 5 6 7 |
# File 'lib/ipvs_litmus/cli/admin.rb', line 4 def run(argv = ARGV) command = argv.shift send(command, argv) end |
#status(args) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ipvs_litmus/cli/admin.rb', line 38 def status(args) = opt_parser = _extend_default_parser() do |opts| opts. = "Usage: litmusctl status <service> [options]" end opt_parser.parse! args service = args.shift _litmus_request([:host], [:port], Net::HTTP::Get.new("/#{service}/status")) end |