bin/cloud66_agent in cloud66_agent-0.0.1.pre6 vs bin/cloud66_agent in cloud66_agent-0.0.1.pre7
- old
+ new
@@ -6,84 +6,69 @@
require 'cloud66_agent'
# global config variable
$config = Cloud66::Utils::Config.new
+# deal with global options
OptionParser.new do |opts|
- opts.banner = "Cloud 66 Agent v#{Cloud66::Utils::Version.current}"
+ opts.banner = "Cloud 66 Agent v#{Cloud66::Utils::Version.current} (#{$config.is_agent_configured? ? 'Configured' : 'Not Configured'})"
+ opts.on('--version', 'Agent version', '-v') { |v| puts "Cloud 66 Agent v#{Cloud66::Utils::Version.current} (#{$config.is_agent_configured? ? 'Configured' : 'Not Configured'})"; exit 0 }
+ opts.on('--log [LOG]', 'Log output') { |v| $config.log = (v == "STDOUT") ? STDOUT : v }
+ opts.on('--log-level [LOG_LEVEL]', 'Log level (int)') { |v| $config.log_level = v.to_i }
+end.order!
- # following opts only for registration
- opts.on('--url URL', 'Server URL') do |v|
- $config.url = v
- end
- opts.on('--sockets SOCKETS', 'Sockets URL') do |v|
- $config.faye_url = v
- end
- opts.on('--api-key APIKEY', 'API key') do |v|
- $config.api_key = v
- end
- opts.on('--secret-key SECRETKEY', 'Secret Key') do |v|
- $config.secret_key = v
- end
- opts.on('--server SERVERUID', 'Server id') do |v|
- @server_uid = v
- end
+command = ARGV.shift
+# ensure we have a command
+if command.nil?
+ puts "Cloud 66 Agent v#{Cloud66::Utils::Version.current} (#{$config.is_agent_configured? ? 'Configured' : 'Not Configured'})"
+ exit 0
+else
+ command = command.downcase
+end
- # respond to version requests
- opts.on('--version') do |v|
- puts "Cloud 66 Agent #{Cloud66::Utils::Version.current}"
- exit 0
- end
-
- # logging configuration
- opts.on('--log LOG', 'Log file path') do |v|
- v == "STDOUT" ? $config.log_path = STDOUT : $config.log_path = v
- end
- opts.on('--log_level LOGLEVEL', 'Log level (int)') do |v|
- $config.log_level = v.to_i
- end
-end.parse!
-
-#pick up the command used
-command = ARGV[0].downcase unless ARGV[0].nil?
-
# prepare the global logger (can't have stdout logging for job_start command - as the stdout result is used)
-$config.log_path = "/var/log/cloud66/cloud66_agent.log" if command == 'job_start' && $config.log_path == STDOUT
-$logger = Logger.new($config.log_path)
+$config.log = "/var/log/cloud66_agent.log" if command == 'job_start' && $config.log == STDOUT
+$logger = Logger.new($config.log)
$logger.level = $config.log_level
+# nothing allowed while disabled
if $config.disabled
- # no other commands allowed while disabled
$logger.error "This agent had been disabled. Please contact Cloud 66 if you think this is in error"
- exit -1
-end
-
-if command.nil? || command.empty?
- $logger.debug("Cloud 66 Agent v#{Cloud66::Utils::Version.current} (#{$config.is_agent_configured? ? 'Configured' : 'Not Configured'})")
- exit 0
-end
-
-if !$config.is_agent_configured? && command != 'configure'
+ exit 86
+elsif !$config.is_agent_configured? && command != 'configure'
# no other commands allowed while not configured
$logger.error "Can only do command \"configure\" (until its been configured!)"
exit -1
end
# handle commands
-$logger.info "Performing: \"#{command}\""
-if command == "configure"
- Cloud66Agent.configure @server_uid
+$logger.info "Attempting: \"#{command}\""
+if command == 'configure'
+ OptionParser.new do |opts|
+ opts.on('--api-url [URL]', 'API URL') { |v| $config.api_url = v }
+ opts.on('--api-key API_KEY', 'API key') { |v| $config.api_key = v }
+ opts.on('--secret-key SECRET_KEY', 'Secret key') { |v| $config.secret_key = v }
+ opts.on('--server-uid SERVER_UID', 'Server UID') { |v| @server_uid = v }
+ end.order!
+ Cloud66Agent.configure(@server_uid)
+elsif command == 'job_start'
+ OptionParser.new do |opts|
+ opts.on('--job-uid JOB_UID', 'Job UID') { |v| @job_uid = v }
+ end.order!
+ Cloud66Agent.job_start(@job_uid)
+elsif command == 'job_end'
+ OptionParser.new do |opts|
+ opts.on('--job-uid JOB_UID', 'Job UID') { |v| @job_uid = v }
+ opts.on('--run-uid RUN_UID', 'Run UID') { |v| @run_uid = v }
+ opts.on('--run-status RUN_STATUS', 'Status') { |v| @run_status = v }
+ opts.on('--run-time RUN_TIME', 'Execution time') { |v| @run_time = v }
+ opts.on('--results-file RESULTS_FILE', 'Results file') { |v| @results_file = v }
+ end.order!
+ Cloud66Agent.job_end(@job_uid, @run_uid, @run_status, @run_time, @results_file)
else
begin
- arguments = ARGV[1..-1]
- if arguments.empty?
- Cloud66Agent.send command
- else
- Cloud66Agent.send(command, arguments)
- end
- rescue ArgumentError
- $logger.error "Invalid command/arguments: #{command} #{arguments}"
+ Cloud66Agent.send command
+ rescue
+ $logger.error "Invalid command: #{command}"
exit -1
end
-end
-exit 0
-
+end
\ No newline at end of file