Class: Cloud66::Commands::Configure

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud66_agent/commands/configure.rb

Class Method Summary collapse

Class Method Details

.perform(server_uid, cloud) ⇒ Object



8
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cloud66_agent/commands/configure.rb', line 8

def self.perform(server_uid, cloud)
  begin
    if cloud.nil? || cloud.empty?
      # try figure it out
      $config.is_aws = Utils::VitalSigns.is_aws?

      if $config.is_aws
        $config.is_gc = false
      else
        # try figure it out
        $config.is_gc = Utils::VitalSigns.is_gc?
      end
    else
      # use the passed in value
      $config.is_aws = (cloud == 'aws')

      # use the passed in value
      $config.is_gc = (cloud == 'googlecloud')
    end
    data = {
        :timezone => Time.new.zone,
        :server_uid => server_uid,
        :version => Utils::Version.current,
        :system => Utils::VitalSigns.system_info}

    address_info = Utils::VitalSigns.address_info
    data = data.merge(address_info)
  rescue => exc
    data = {error: exc.message}
  end
  result = Utils::Server.send_configure data
  $config.agent_uid = result['agent_uid']

  disk_warning_percent = result['disk_warning_percent']
  $config.disk_warning_percent = disk_warning_percent.to_i unless disk_warning_percent.nil?
  disk_critical_percent = result['disk_critical_percent']
  $config.disk_critical_percent = disk_critical_percent.to_i unless disk_critical_percent.nil?

  $config.disabled = false
  $config.save
  exit 0
rescue => exc
  $logger.error "Command \"configure\" failed: #{exc.message}"
  exit -1
end