Class: Cloud66::Utils::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud66_agent/utils/config.rb

Constant Summary collapse

CONFIG_PATH =

default conf dir

"/etc/cloud66/cloud66_agent.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

load up the config at startup



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cloud66_agent/utils/config.rb', line 23

def initialize
  load if File.exists?(CONFIG_PATH)

  # set defaults
  @log = @log.nil? ? "/var/log/cloud66_agent.log" : @log == "STDOUT" ? STDOUT : @log
  @log_level ||= 2
  @api_url ||= 'https://api.cloud66.com'
  @disabled ||= false
  @is_aws ||= false
  @is_gc ||= false

  # defaults
  @disk_warning_percent = 80
  @disk_critical_percent = 90
end

Instance Attribute Details

#agent_uidObject

Returns the value of attribute agent_uid.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def agent_uid
  @agent_uid
end

#api_keyObject

Returns the value of attribute api_key.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def api_key
  @api_key
end

#api_urlObject

Returns the value of attribute api_url.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def api_url
  @api_url
end

#disabledObject

Returns the value of attribute disabled.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def disabled
  @disabled
end

#disk_critical_percentObject

Returns the value of attribute disk_critical_percent.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def disk_critical_percent
  @disk_critical_percent
end

#disk_warning_percentObject

Returns the value of attribute disk_warning_percent.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def disk_warning_percent
  @disk_warning_percent
end

#is_awsObject

Returns the value of attribute is_aws.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def is_aws
  @is_aws
end

#is_gcObject

Returns the value of attribute is_gc.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def is_gc
  @is_gc
end

#logObject

Returns the value of attribute log.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def log
  @log
end

#log_levelObject

Returns the value of attribute log_level.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def log_level
  @log_level
end

#secret_keyObject

Returns the value of attribute secret_key.



10
11
12
# File 'lib/cloud66_agent/utils/config.rb', line 10

def secret_key
  @secret_key
end

Instance Method Details

#deleteObject



64
65
66
# File 'lib/cloud66_agent/utils/config.rb', line 64

def delete
  File.delete(CONFIG_PATH) if File.exists?(CONFIG_PATH)
end

#is_agent_configured?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/cloud66_agent/utils/config.rb', line 39

def is_agent_configured?
  return !@agent_uid.nil? && !@agent_uid.empty?
end

#saveObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cloud66_agent/utils/config.rb', line 43

def save
  Dir.mkdir(CONFIG_PATH) if !FileTest::directory?(File.dirname(CONFIG_PATH))

  File.open(CONFIG_PATH, 'w+') do |out|
    data = {
        'api_url' => @api_url,
        'api_key' => @api_key,
        'secret_key' => @secret_key,
        'agent_uid' => @agent_uid,
        'disabled' => @disabled,
        'is_aws' => @is_aws,
        'is_gc' => @is_gc,
        'log' => @log == STDOUT ? "STDOUT" : @log,
        'log_level' => @log_level,
        'disk_warning_percent' => @disk_warning_percent,
        'disk_critical_percent' => @disk_critical_percent,
    }
    out.puts to_cust_yaml(data)
  end
end