Class: Cloud66::Utils::Config
- Inherits:
-
Object
- Object
- Cloud66::Utils::Config
- 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
-
#agent_uid ⇒ Object
Returns the value of attribute agent_uid.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#disk_critical_percent ⇒ Object
Returns the value of attribute disk_critical_percent.
-
#disk_warning_percent ⇒ Object
Returns the value of attribute disk_warning_percent.
-
#is_aws ⇒ Object
Returns the value of attribute is_aws.
-
#is_gc ⇒ Object
Returns the value of attribute is_gc.
-
#log ⇒ Object
Returns the value of attribute log.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize ⇒ Config
constructor
load up the config at startup.
- #is_agent_configured? ⇒ Boolean
- #save ⇒ Object
Constructor Details
#initialize ⇒ Config
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_uid ⇒ Object
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_key ⇒ Object
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_url ⇒ Object
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 |
#disabled ⇒ Object
Returns the value of attribute disabled.
10 11 12 |
# File 'lib/cloud66_agent/utils/config.rb', line 10 def disabled @disabled end |
#disk_critical_percent ⇒ Object
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_percent ⇒ Object
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_aws ⇒ Object
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_gc ⇒ Object
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 |
#log ⇒ Object
Returns the value of attribute log.
10 11 12 |
# File 'lib/cloud66_agent/utils/config.rb', line 10 def log @log end |
#log_level ⇒ Object
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_key ⇒ Object
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
#delete ⇒ Object
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
39 40 41 |
# File 'lib/cloud66_agent/utils/config.rb', line 39 def is_agent_configured? return !@agent_uid.nil? && !@agent_uid.empty? end |
#save ⇒ Object
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 |