Class: Rprov::Config
- Inherits:
-
Object
- Object
- Rprov::Config
- Defined in:
- lib/rprov/config.rb
Constant Summary collapse
- STARTING_PORT =
10_000
- DEFAULTS =
{ :appendfsync => "everysec", :host => "127.0.0.1", :vm_enabled => "no", :vm_max_memory => 0, :paranoid => false }
Instance Attribute Summary collapse
-
#appendfsync ⇒ Object
Returns the value of attribute appendfsync.
-
#host ⇒ Object
Returns the value of attribute host.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#paranoid ⇒ Object
Returns the value of attribute paranoid.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#path ⇒ Object
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#vm_enabled ⇒ Object
Returns the value of attribute vm_enabled.
-
#vm_max_memory ⇒ Object
Returns the value of attribute vm_max_memory.
Class Method Summary collapse
Instance Method Summary collapse
- #config_cmd ⇒ Object
-
#initialize(key) ⇒ Config
constructor
A new instance of Config.
- #memory=(memory) ⇒ Object
- #redis_conf ⇒ Object
- #shutdown_cmd ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(key) ⇒ Config
Returns a new instance of Config.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rprov/config.rb', line 24 def initialize(key) @key = key @password, @port = redis.hmget(:password, :port) DEFAULTS.each do |key, value| send("%s=" % key, redis.hget(key) || value) end rescue Errno::ECONNREFUSED raise Errno::ECONNREFUSED, "You need to setup a master redis server." end |
Instance Attribute Details
#appendfsync ⇒ Object
Returns the value of attribute appendfsync.
20 21 22 |
# File 'lib/rprov/config.rb', line 20 def appendfsync @appendfsync end |
#host ⇒ Object
Returns the value of attribute host.
19 20 21 |
# File 'lib/rprov/config.rb', line 19 def host @host end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
13 14 15 |
# File 'lib/rprov/config.rb', line 13 def key @key end |
#paranoid ⇒ Object
Returns the value of attribute paranoid.
16 17 18 |
# File 'lib/rprov/config.rb', line 16 def paranoid @paranoid end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
14 15 16 |
# File 'lib/rprov/config.rb', line 14 def password @password end |
#path ⇒ Object
Returns the value of attribute path.
17 18 19 |
# File 'lib/rprov/config.rb', line 17 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/rprov/config.rb', line 15 def port @port end |
#vm_enabled ⇒ Object
Returns the value of attribute vm_enabled.
21 22 23 |
# File 'lib/rprov/config.rb', line 21 def vm_enabled @vm_enabled end |
#vm_max_memory ⇒ Object
Returns the value of attribute vm_max_memory.
22 23 24 |
# File 'lib/rprov/config.rb', line 22 def vm_max_memory @vm_max_memory end |
Class Method Details
.generate(key = gen_key) ⇒ Object
65 66 67 68 69 |
# File 'lib/rprov/config.rb', line 65 def self.generate(key = gen_key) redis[key].hmset(:port, gen_port, :password, random_string) return new(key) end |
.random_string ⇒ Object
71 72 73 |
# File 'lib/rprov/config.rb', line 71 def self.random_string Digest::SHA1.hexdigest(uuid + Time.now.to_f.to_s) end |
.redis ⇒ Object
75 76 77 |
# File 'lib/rprov/config.rb', line 75 def self.redis @redis ||= Nest.new(:rprov)[:config] end |
Instance Method Details
#config_cmd ⇒ Object
58 |
# File 'lib/rprov/config.rb', line 58 def config_cmd() redis.hget(:config_cmd) || :config end |
#memory=(memory) ⇒ Object
36 37 38 39 |
# File 'lib/rprov/config.rb', line 36 def memory=(memory) self.vm_max_memory = memory self.vm_enabled = "yes" end |
#redis_conf ⇒ Object
61 62 63 |
# File 'lib/rprov/config.rb', line 61 def redis_conf redis_conf_erb.result(binding) end |
#shutdown_cmd ⇒ Object
59 |
# File 'lib/rprov/config.rb', line 59 def shutdown_cmd() redis.hget(:shutdown_cmd) || :shutdown end |
#url ⇒ Object
45 46 47 |
# File 'lib/rprov/config.rb', line 45 def url "redis://:#{password}@#{host}:#{port}" end |