cloud66_agent 0.0.1.pre6 → 0.0.1.pre7

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cloud66_agent CHANGED
@@ -8,82 +8,67 @@ require 'cloud66_agent'
8
8
  # global config variable
9
9
  $config = Cloud66::Utils::Config.new
10
10
 
11
+ # deal with global options
11
12
  OptionParser.new do |opts|
12
- opts.banner = "Cloud 66 Agent v#{Cloud66::Utils::Version.current}"
13
+ opts.banner = "Cloud 66 Agent v#{Cloud66::Utils::Version.current} (#{$config.is_agent_configured? ? 'Configured' : 'Not Configured'})"
14
+ 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 }
15
+ opts.on('--log [LOG]', 'Log output') { |v| $config.log = (v == "STDOUT") ? STDOUT : v }
16
+ opts.on('--log-level [LOG_LEVEL]', 'Log level (int)') { |v| $config.log_level = v.to_i }
17
+ end.order!
13
18
 
14
- # following opts only for registration
15
- opts.on('--url URL', 'Server URL') do |v|
16
- $config.url = v
17
- end
18
- opts.on('--sockets SOCKETS', 'Sockets URL') do |v|
19
- $config.faye_url = v
20
- end
21
- opts.on('--api-key APIKEY', 'API key') do |v|
22
- $config.api_key = v
23
- end
24
- opts.on('--secret-key SECRETKEY', 'Secret Key') do |v|
25
- $config.secret_key = v
26
- end
27
- opts.on('--server SERVERUID', 'Server id') do |v|
28
- @server_uid = v
29
- end
30
-
31
- # respond to version requests
32
- opts.on('--version') do |v|
33
- puts "Cloud 66 Agent #{Cloud66::Utils::Version.current}"
34
- exit 0
35
- end
36
-
37
- # logging configuration
38
- opts.on('--log LOG', 'Log file path') do |v|
39
- v == "STDOUT" ? $config.log_path = STDOUT : $config.log_path = v
40
- end
41
- opts.on('--log_level LOGLEVEL', 'Log level (int)') do |v|
42
- $config.log_level = v.to_i
43
- end
44
- end.parse!
45
-
46
- #pick up the command used
47
- command = ARGV[0].downcase unless ARGV[0].nil?
19
+ command = ARGV.shift
20
+ # ensure we have a command
21
+ if command.nil?
22
+ puts "Cloud 66 Agent v#{Cloud66::Utils::Version.current} (#{$config.is_agent_configured? ? 'Configured' : 'Not Configured'})"
23
+ exit 0
24
+ else
25
+ command = command.downcase
26
+ end
48
27
 
49
28
  # prepare the global logger (can't have stdout logging for job_start command - as the stdout result is used)
50
- $config.log_path = "/var/log/cloud66/cloud66_agent.log" if command == 'job_start' && $config.log_path == STDOUT
51
- $logger = Logger.new($config.log_path)
29
+ $config.log = "/var/log/cloud66_agent.log" if command == 'job_start' && $config.log == STDOUT
30
+ $logger = Logger.new($config.log)
52
31
  $logger.level = $config.log_level
53
32
 
33
+ # nothing allowed while disabled
54
34
  if $config.disabled
55
- # no other commands allowed while disabled
56
35
  $logger.error "This agent had been disabled. Please contact Cloud 66 if you think this is in error"
57
- exit -1
58
- end
59
-
60
- if command.nil? || command.empty?
61
- $logger.debug("Cloud 66 Agent v#{Cloud66::Utils::Version.current} (#{$config.is_agent_configured? ? 'Configured' : 'Not Configured'})")
62
- exit 0
63
- end
64
-
65
- if !$config.is_agent_configured? && command != 'configure'
36
+ exit 86
37
+ elsif !$config.is_agent_configured? && command != 'configure'
66
38
  # no other commands allowed while not configured
67
39
  $logger.error "Can only do command \"configure\" (until its been configured!)"
68
40
  exit -1
69
41
  end
70
42
 
71
43
  # handle commands
72
- $logger.info "Performing: \"#{command}\""
73
- if command == "configure"
74
- Cloud66Agent.configure @server_uid
44
+ $logger.info "Attempting: \"#{command}\""
45
+ if command == 'configure'
46
+ OptionParser.new do |opts|
47
+ opts.on('--api-url [URL]', 'API URL') { |v| $config.api_url = v }
48
+ opts.on('--api-key API_KEY', 'API key') { |v| $config.api_key = v }
49
+ opts.on('--secret-key SECRET_KEY', 'Secret key') { |v| $config.secret_key = v }
50
+ opts.on('--server-uid SERVER_UID', 'Server UID') { |v| @server_uid = v }
51
+ end.order!
52
+ Cloud66Agent.configure(@server_uid)
53
+ elsif command == 'job_start'
54
+ OptionParser.new do |opts|
55
+ opts.on('--job-uid JOB_UID', 'Job UID') { |v| @job_uid = v }
56
+ end.order!
57
+ Cloud66Agent.job_start(@job_uid)
58
+ elsif command == 'job_end'
59
+ OptionParser.new do |opts|
60
+ opts.on('--job-uid JOB_UID', 'Job UID') { |v| @job_uid = v }
61
+ opts.on('--run-uid RUN_UID', 'Run UID') { |v| @run_uid = v }
62
+ opts.on('--run-status RUN_STATUS', 'Status') { |v| @run_status = v }
63
+ opts.on('--run-time RUN_TIME', 'Execution time') { |v| @run_time = v }
64
+ opts.on('--results-file RESULTS_FILE', 'Results file') { |v| @results_file = v }
65
+ end.order!
66
+ Cloud66Agent.job_end(@job_uid, @run_uid, @run_status, @run_time, @results_file)
75
67
  else
76
68
  begin
77
- arguments = ARGV[1..-1]
78
- if arguments.empty?
79
- Cloud66Agent.send command
80
- else
81
- Cloud66Agent.send(command, arguments)
82
- end
83
- rescue ArgumentError
84
- $logger.error "Invalid command/arguments: #{command} #{arguments}"
69
+ Cloud66Agent.send command
70
+ rescue
71
+ $logger.error "Invalid command: #{command}"
85
72
  exit -1
86
73
  end
87
- end
88
- exit 0
89
-
74
+ end
@@ -13,7 +13,7 @@ module Cloud66
13
13
  Utils::Server.send_address data
14
14
  exit 0
15
15
  rescue => exc
16
- $logger.error "'address' failed: #{exc.message}"
16
+ $logger.error "Command \"address\" failed: #{exc.message}"
17
17
  exit -1
18
18
  end
19
19
  end
@@ -11,21 +11,21 @@ module Cloud66
11
11
  data = {
12
12
  :timezone => Time.new.zone,
13
13
  :server_uid => server_uid,
14
- :ext_ip4 => address_info[:ext_ip4],
15
- :int_ip4 => address_info[:int_ip4],
16
- :ext_ip6 => address_info[:ext_ip6],
17
- :int_ip6 => address_info[:int_ip6],
14
+ :ext_ipv4 => address_info[:ext_ipv4],
15
+ :int_ipv4 => address_info[:int_ipv4],
16
+ :ext_ipv6 => address_info[:ext_ipv6],
17
+ :int_ipv6 => address_info[:int_ipv6],
18
18
  :version => Utils::Version.current,
19
19
  :system => Utils::VitalSigns.system_info }
20
20
  rescue => exc
21
21
  data = { error: exc.message }
22
22
  end
23
23
  result = Utils::Server.send_configure data
24
- $config.agent_uid = result['uid']
24
+ $config.agent_uid = result['agent_uid']
25
25
  $config.save
26
26
  exit 0
27
27
  rescue => exc
28
- $logger.error "'configure' failed: #{exc.message}"
28
+ $logger.error "Command \"configure\" failed: #{exc.message}"
29
29
  exit -1
30
30
  end
31
31
 
@@ -3,17 +3,17 @@ require 'cloud66_agent/utils/server'
3
3
  module Cloud66
4
4
  module Commands
5
5
  class JobEnd
6
- def self.perform(status, job_uid, session_uid, run_time, results_file)
7
- job_results = File.exists?(results_file) ? IO.readlines(results_file) : []
6
+ def self.perform(job_uid, run_uid, run_status, run_time, results_file)
7
+ run_data = File.exists?(results_file) ? IO.readlines(results_file) : []
8
8
  data = {
9
- status: status,
10
- session_uid: session_uid,
9
+ run_uid: run_uid,
10
+ run_status: run_status,
11
11
  run_time: run_time,
12
- job_results: job_results
12
+ run_data: run_data
13
13
  }
14
14
  Utils::Server.send_job_end(job_uid, data)
15
15
  rescue => exc
16
- $logger.error "'job_end' failed: #{exc.message}"
16
+ $logger.error "Command \"job_end\" failed: #{exc.message}"
17
17
  exit -1
18
18
  ensure
19
19
  # get rid of the old results
@@ -6,10 +6,10 @@ module Cloud66
6
6
  def self.perform(job_uid)
7
7
  result = Utils::Server.send_job_start job_uid
8
8
  # this is the only time we need a response value from the client
9
- puts result['session_uid']
9
+ puts result['run_uid']
10
10
  exit 0
11
11
  rescue => exc
12
- $logger.error "'job_start' failed: #{exc.message}"
12
+ $logger.error "Command \"job_start\" failed: #{exc.message}"
13
13
  exit -1
14
14
  end
15
15
  end
@@ -7,7 +7,7 @@ module Cloud66
7
7
  Utils::Server.send_pulse
8
8
  exit 0
9
9
  rescue => exc
10
- $logger.error "'pulse' failed: #{exc.message}"
10
+ $logger.error "Command \"pulse\" failed: #{exc.message}"
11
11
  exit -1
12
12
  end
13
13
  end
@@ -13,7 +13,7 @@ module Cloud66
13
13
  Utils::Server.send_vitals data
14
14
  exit 0
15
15
  rescue => exc
16
- $logger.error "'vitals' failed: #{exc.message}"
16
+ $logger.error "Command \"vitals\" failed: #{exc.message}"
17
17
  exit -1
18
18
  end
19
19
  end
@@ -5,24 +5,22 @@ module Cloud66
5
5
  # default conf dir
6
6
  CONFIG_PATH = "/etc/cloud66/cloud66_agent.yml"
7
7
 
8
- attr_accessor :api_key,
9
- :agent_uid,
8
+ attr_accessor :api_url,
9
+ :api_key,
10
10
  :secret_key,
11
- :log_path,
12
- :log_level,
13
- :url,
14
- :faye_url,
15
- :disabled
11
+ :agent_uid,
12
+ :disabled,
13
+ :log,
14
+ :log_level
16
15
 
17
16
  # load up the config at startup
18
17
  def initialize
19
18
  load if File.exists?(CONFIG_PATH)
20
19
 
21
20
  # set defaults
22
- @log_path = @log_path.nil? || @log_path.to_s.strip.empty? || @log_path == "STDOUT" ? STDOUT : @log_path
21
+ @log = @log.nil? || @log.to_s.strip.empty? || @log == "STDOUT" ? STDOUT : @log
23
22
  @log_level ||= 2
24
- @url ||= 'https://api.cloud66.com'
25
- @faye_url ||= 'https://sockets.cloud66.com/push'
23
+ @api_url ||= 'https://api.cloud66.com'
26
24
  @disabled ||= false
27
25
  end
28
26
 
@@ -35,18 +33,14 @@ module Cloud66
35
33
 
36
34
  File.open(CONFIG_PATH, 'w+') do |out|
37
35
  data = {
36
+ 'api_url' => @api_url,
38
37
  'api_key' => @api_key,
39
- 'agent_uid' => @agent_uid,
40
38
  'secret_key' => @secret_key,
41
- 'log_path' => @log_path == STDOUT ? "STDOUT" : @log_path,
42
- 'log_level' => @log_level,
43
- 'disabled' => @disabled
39
+ 'agent_uid' => @agent_uid,
40
+ 'disabled' => @disabled,
41
+ 'log' => @log == STDOUT ? "STDOUT" : @log,
42
+ 'log_level' => @log_level
44
43
  }
45
- # store the url if it is different
46
- data['url'] = @url if @url != 'https://api.cloud66.com'
47
- # store the faye url if it is different
48
- data['faye_url'] = @faye_url if @faye_url != 'https://sockets.cloud66.com/push'
49
-
50
44
  YAML::dump(data, out)
51
45
  end
52
46
  end
@@ -60,29 +54,14 @@ module Cloud66
60
54
  def load
61
55
  raise "config not found" unless File.exists?(CONFIG_PATH)
62
56
  config = YAML::load(File.open(CONFIG_PATH))
63
-
57
+ @api_url = config['api_url']
64
58
  @api_key = config['api_key']
65
- @agent_uid = config['agent_uid']
66
59
  @secret_key = config['secret_key']
67
-
68
- # get if it exists in the config
69
- config_url = config['url']
70
- @url = config_url if !config_url.nil? && !config_url.strip.empty?
71
-
72
- # get if it exists in the config
73
- config_faye_url = config['faye_url']
74
- @faye_url = config_faye_url if !config_faye_url.nil? && !config_faye_url.strip.empty?
75
-
76
- # get if it exists in the config
77
- config_log_path = config['log_path']
78
- @log_path = config_log_path if !config_log_path.nil? && !config_log_path.strip.empty?
79
-
60
+ @agent_uid = config['agent_uid']
61
+ @log = config['log']
80
62
  # get if it exists in the config
81
63
  config_log_level = config['log_level']
82
- @log_level = config_log_level.to_i
83
-
84
- disabled = config['disabled']
85
- @disabled = disabled if !disabled.nil?
64
+ @log_level = config_log_level.to_i if config_log_level
86
65
  rescue
87
66
  # we can't load the file
88
67
  end
@@ -24,11 +24,11 @@ module Cloud66
24
24
  end
25
25
 
26
26
  def self.send_job_start(job_uid)
27
- process(do_get("/server/#{job_uid}/job_start.json", build_content))
27
+ process(do_get("/job/#{job_uid}/start.json", build_content))
28
28
  end
29
29
 
30
30
  def self.send_job_end(job_uid, data)
31
- process(do_post("/server/#{job_uid}/job_end.json", build_content(data)))
31
+ process(do_post("/job/#{job_uid}/end.json", build_content(data)))
32
32
  end
33
33
 
34
34
  private
@@ -61,7 +61,7 @@ module Cloud66
61
61
  $logger.debug "Sending (post) request..."
62
62
  $logger.debug "Request url: #{url}"
63
63
  $logger.debug "Request content: #{content}"
64
- base_uri $config.url
64
+ base_uri $config.api_url
65
65
  post(url, content)
66
66
  end
67
67
 
@@ -69,7 +69,7 @@ module Cloud66
69
69
  $logger.debug "Sending (delete) request..."
70
70
  $logger.debug "Request url: #{url}"
71
71
  $logger.debug "Request content: #{content}"
72
- base_uri $config.url
72
+ base_uri $config.api_url
73
73
  delete(url, content)
74
74
  end
75
75
 
@@ -77,7 +77,7 @@ module Cloud66
77
77
  $logger.debug "Sending (get) request..."
78
78
  $logger.debug "Request url: #{url}"
79
79
  $logger.debug "Request content: #{content}"
80
- base_uri $config.url
80
+ base_uri $config.api_url
81
81
  get(url, content)
82
82
  end
83
83
 
@@ -85,7 +85,7 @@ module Cloud66
85
85
  $logger.debug "Sending (put) request..."
86
86
  $logger.debug "Request url: #{url}"
87
87
  $logger.debug "Request content: #{content}"
88
- base_uri $config.url
88
+ base_uri $config.api_url
89
89
  put(url, content)
90
90
  end
91
91
 
@@ -16,7 +16,7 @@ module Cloud66
16
16
  MAJOR, MINOR, PATCH = 0, 0, 1
17
17
 
18
18
  #ie. PRERELEASE_MODIFIER = 'beta1'
19
- PRERELEASE_MODIFIER = "pre6"
19
+ PRERELEASE_MODIFIER = "pre7"
20
20
 
21
21
  ##
22
22
  # Returns the major version ( big release based off of multiple minor releases )
@@ -6,26 +6,15 @@ module Cloud66
6
6
  class VitalSigns
7
7
 
8
8
  def self.system_info
9
- return { ext_ipv4: "123.123.123.123",
10
- int_ipv4: "123.123.123.123",
11
- ext_ipv6: "123.123.123.123",
12
- int_ipv6: "123.123.123.123" } if RUBY_PLATFORM.include?('darwin')
13
-
14
9
  # system info
15
- return parse_data(`sudo facter`)
10
+ return parse_data(`facter`)
16
11
  end
17
12
 
18
13
  def self.address_info
19
- return { ext_ipv4: "123.123.123.123",
20
- int_ipv4: "123.123.123.123",
21
- ext_ipv6: "123.123.123.123",
22
- int_ipv6: "123.123.123.123" } if RUBY_PLATFORM.include?('darwin')
23
-
24
14
  # address information
25
15
  hash = parse_data(`facter ipaddress ec2_public_ipv4 ipaddress_eth0 ipaddress6 ipaddress6_eth0`)
26
16
 
27
17
  result = {}
28
-
29
18
  if hash.has_key?('ec2_public_ipv4')
30
19
  # return ec2 info first (most specific)
31
20
  result[:ext_ipv4] = hash['ec2_public_ipv4']
data/lib/cloud66_agent.rb CHANGED
@@ -3,7 +3,8 @@ Dir.glob(File.dirname(File.absolute_path(__FILE__)) + '/cloud66_agent/commands/*
3
3
 
4
4
  class Cloud66Agent
5
5
  def self.configure(server_uid)
6
- Cloud66::Commands::Configure.perform server_uid
6
+ raise ArgumentError.new if server_uid.nil?
7
+ Cloud66::Commands::Configure.perform(server_uid)
7
8
  end
8
9
 
9
10
  def self.pulse
@@ -18,19 +19,13 @@ class Cloud66Agent
18
19
  Cloud66::Commands::Address.perform
19
20
  end
20
21
 
21
- def self.job_start(args)
22
- job_uid = args[0]
22
+ def self.job_start(job_uid)
23
23
  raise ArgumentError.new if job_uid.nil?
24
- Cloud66::Commands::JobStart.perform job_uid
24
+ Cloud66::Commands::JobStart.perform(job_uid)
25
25
  end
26
26
 
27
- def self.job_end(args)
28
- status = args[0]
29
- job_uid = args[1]
30
- session_uid = args[2]
31
- run_time = args[3]
32
- results_file = args[4]
33
- raise ArgumentError.new if status.nil? || job_uid.nil? || session_uid.nil? || run_time.nil? || results_file.nil?
34
- Cloud66::Commands::JobEnd.perform(status, job_uid, session_uid, run_time, results_file)
27
+ def self.job_end(job_uid, run_uid, run_status, run_time, results_file)
28
+ raise ArgumentError.new if run_status.nil? || job_uid.nil? || run_uid.nil? || run_time.nil? || results_file.nil?
29
+ Cloud66::Commands::JobEnd.perform(job_uid, run_uid, run_status, run_time, results_file)
35
30
  end
36
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud66_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre6
4
+ version: 0.0.1.pre7
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: