From 822b8f7110bf9d5d889ab3d45e0abc752f60b1e3 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Herrero Date: Thu, 26 May 2022 19:35:38 +0200 Subject: [PATCH] F #5844: add get-vm/service to onelog (#2091) --- src/cli/onelog | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/cli/onelog b/src/cli/onelog index 470b8cb7f2..0efae66c7b 100755 --- a/src/cli/onelog +++ b/src/cli/onelog @@ -98,4 +98,55 @@ CommandParser::CmdParser.new(ARGV) do system("#{pager} #{options[:pager_opts]} /var/log/one/#{file}") end + + vm_desc = <<-EOT.unindent + Gets VM log + EOT + + command :'get-vm', vm_desc, :id, :options => [PAGER, PAGER_OPTS] do + pager = options[:pager] || DEFAULT_PAGER + + begin + Integer(args[0]) + + file = "/var/log/one/#{args[0]}.log" + + unless File.exist?(file) + STDERR.puts "No LOG file found for '#{args[0]}' VM" + exit 1 + end + + system("#{pager} #{options[:pager_opts]} #{file}") + rescue StandardError + STDERR.puts 'Only ID is supported' + exit 1 + end + end + + service_desc = <<-EOT.unindent + Gets Service log + EOT + + command :'get-service', + service_desc, + :id, + :options => [PAGER, PAGER_OPTS] do + pager = options[:pager] || DEFAULT_PAGER + + begin + Integer(args[0]) + + file = "/var/log/one/oneflow/#{args[0]}.log" + + unless File.exist?(file) + STDERR.puts "No LOG file found for '#{args[0]}' service" + exit 1 + end + + system("#{pager} #{options[:pager_opts]} #{file}") + rescue StandardError + STDERR.puts 'Only ID is supported' + exit 1 + end + end end